Original Post
I was trying to convert a GLSL shader from gametutorials.com over to a HLSL shader, but I have run into an error that I cannot seem to figure out. The error is: (21)error X4502: invalid input semantic 'POSITION0' And here is the shader code: Any help with this error would be great appreciated. Thanks, Chris
float4x4 ModelViewProjectionMatrix;
float4 lightPos;
float4 cameraPos;
texture reflectionTex;
texture refractionTex;
texture normalMapTex;
texture dudvMapTex;
texture depthMapTex;
float4 waterColor;
struct VS_INPUT
{
float4 position : POSITION0;
float4 refrCoords : TEXCOORD0;
float4 normCoords : TEXCOORD1;
};
struct VS_OUTPUT
{
float4 position : POSITION0;
float4 refrCoords : TEXCOORD0;
float4 normCoords : TEXCOORD1;
float4 viewTangetSpace : TEXCOORD2;
float4 lightTangetSpace : TEXCOORD3;
};
sampler2D reflection = sampler_state
{
Texture = (reflectionTex);
MIPFILTER = LINEAR;
MAGFILTER = LINEAR;
MINFILTER = LINEAR;
};
sampler2D refraction = sampler_state
{
Texture = (refractionTex);
MIPFILTER = LINEAR;
MAGFILTER = LINEAR;
MINFILTER = LINEAR;
};
sampler2D normalMap = sampler_state
{
Texture = (normalMapTex);
MIPFILTER = LINEAR;
MAGFILTER = LINEAR;
MINFILTER = LINEAR;
};
sampler2D dudvMap = sampler_state
{
Texture = (dudvMapTex);
MIPFILTER = LINEAR;
MAGFILTER = LINEAR;
MINFILTER = LINEAR;
};
sampler2D depthMap = sampler_state
{
Texture = (depthMapTex);
MIPFILTER = LINEAR;
MAGFILTER = LINEAR;
MINFILTER = LINEAR;
};
void mainVS( in VS_INPUT IN, out VS_OUTPUT OUT )
{
// Because we have a flat plane for water we already know the vectors for tangent space
float4 tangent = float4(1.0f, 0.0f, 0.0f, 0.0f);
float4 normal = float4(0.0f, 1.0f, 0.0f, 0.0f);
float4 biTangent = float4(0.0f, 0.0f, 1.0f, 0.0f);
// Calculate the vector coming from the vertex to the camera
float4 viewDir = cameraPos - IN.position;
// Compute tangent space for the view direction
float4 v = float4(0.0f, 0.0f, 0.0f, 0.0f);
v.x = dot(viewDir, tangent);
v.y = dot(viewDir, biTangent);
v.z = dot(viewDir, normal);
v.w = 1.0;
OUT.viewTangetSpace = v;
// Calculate the vector that the light hits the vertex
float4 lightDir = lightPos - IN.position;
// Compute tangent space for the light direction
float4 l = float4(0.0f, 0.0f, 0.0f, 0.0f);
l.x = dot(lightDir, tangent);
l.y = dot(lightDir, biTangent);
l.z = dot(lightDir, normal);
l.w = 1.0;
OUT.lightTangetSpace = l;
OUT.refrCoords = IN.refrCoords;
OUT.normCoords = IN.normCoords;
// This calculates our current projection coordinates
OUT.position = mul(IN.position, ModelViewProjectionMatrix);
}
float4 mainPS( in VS_OUTPUT IN ) : COLOR
{
float kShine = 128.0f;
float kDistortion = 0.015f;
float kRefraction = 0.009f;
float4 distOffset = tex2D(dudvMap, IN.normCoords.xy) * kDistortion;
float4 dudvColor = tex2D(dudvMap, IN.refrCoords + distOffset);
dudvColor = normalize(dudvColor * 2.0f - 1.0f) * kRefraction;
float4 normalVector = tex2D(normalMap, IN.refrCoords + distOffset);
normalVector = normalVector * 2.0f - 1.0f;
normalVector.w = 0.0f;
float4 lightReflection = normalize( reflect(-IN.lightTangetSpace, normalVector) );
float4 invertedFresnel = dot(normalVector, lightReflection);
float4 fresnelTerm = 1.0f - invertedFresnel;
float4 projCoord = IN.position / IN.position.x;
projCoord = (projCoord + 1.0f) * 0.5f;
projCoord += dudvColor;
projCoord = clamp(projCoord, 0.001f, 0.999f);
float4 reflectionColor = tex2D(reflection, projCoord.xy);
float4 refractionColor = tex2D(refraction, projCoord.xy);
float4 depthValue = tex2D(depthMap, projCoord.xy);
float4 invDepth = 1.0f - depthValue;
refractionColor *= invertedFresnel * invDepth;
refractionColor += waterColor * depthValue * invertedFresnel;
reflectionColor *= fresnelTerm;
float4 localView = normalize(IN.viewTangetSpace);
float intensity = max(0.0f, dot(lightReflection, localView) );
float4 specular = pow(intensity, kShine);
float4 FinalColor = refractionColor + reflectionColor + specular;
FinalColor.w = 1.0f;
return FinalColor;
}
technique Normal_Mapped_Water
{
pass p0
{
vertexshader = compile vs_2_0 mainVS();
pixelshader = compile ps_2_0 mainPS();
}
}