What's the error? SV_Position is a DX10 and above thing, maybe that's the problem? My guess is that something in your layout is not supported in the feature level you're using.
Hi, could u please help me to rewrite my Vertex Shader and Pixel Shader, so that they do not use SV_Position and SV_Target? It seems to be like you said. SV_Position and SV_Target are not supported in Shader Model 2.
Here is the snippet from my hlsl code:
// Vertex Shader input structure (from Application)
struct VertexShaderInput
{
float4 Position : SV_Position;// Position - xyzw
float3 Normal : NORMAL; // Normal - for lighting and mapping operations
float4 Color : COLOR0; // Color - vertex color, used to generate a diffuse color
float2 TextureUV: TEXCOORD0; // UV - texture coordinate
uint4 SkinIndices : BLENDINDICES0; // blend indices
float4 SkinWeights : BLENDWEIGHT0; // blend weights
};
// Pixel Shader input structure (from Vertex Shader)
struct PixelShaderInput
{
float4 Position : SV_Position;
// Interpolation of combined vertex and material diffuse
float4 Diffuse : COLOR;
// Interpolation of vertex UV texture coordinate
float2 TextureUV: TEXCOORD0;
// We need the World Position and normal for light calculations
float3 WorldNormal : NORMAL;
float3 WorldPosition : WORLDPOS;
};
PixelShaderInput VSMain(VertexShaderInput vertex)
{
PixelShaderInput result = (PixelShaderInput)0;
// Apply vertex skinning if any
SkinVertex(vertex.SkinWeights, vertex.SkinIndices, vertex.Position, vertex.Normal);
result.Position = mul(vertex.Position, WorldViewProjection);
result.Diffuse = vertex.Color * MaterialDiffuse;
// Apply material UV transformation
result.TextureUV = mul(float4(vertex.TextureUV.x, vertex.TextureUV.y, 0, 1), (float4x2)UVTransform).xy;
// We use the inverse transpose of the world so that if there is non uniform
// scaling the normal is transformed correctly. We also use a 3x3 so that
// the normal is not affected by translation (i.e. a vector has the same direction
// and magnitude regardless of translation)
result.WorldNormal = mul(vertex.Normal, (float3x3)WorldInverseTranspose);
result.WorldPosition = mul(vertex.Position, World).xyz;
return result;
}
float4 PSMain(PixelShaderInput pixel) : SV_Target
{
// Normalize our vectors as they are not
// guaranteed to be unit vectors after interpolation
float3 normal = normalize(pixel.WorldNormal);
float3 toEye = normalize(CameraPosition - pixel.WorldPosition);
float3 toLight = normalize(-Light.Direction);
// Texture sample here (use white if no texture)
float4 sample = (float4)1.0f;
if (HasTexture)
sample = Texture0.Sample(Sampler, pixel.TextureUV);
float3 ambient = MaterialAmbient.rgb;
float3 emissive = MaterialEmissive.rgb;
float3 diffuse = Lambert(pixel.Diffuse, normal, toLight);
float3 specular = SpecularBlinnPhong(normal, toLight, toEye);
// Calculate final color component
float3 color = (saturate(ambient+diffuse) * sample.rgb + specular) * Light.Color.rgb + emissive;
// We saturate ambient+diffuse to ensure there is no over-
// brightness on the texture sample if the sum is greater than 1
// Calculate final alpha value
float alpha = pixel.Diffuse.a * sample.a;
// Return result
return float4(color, alpha);
}
I am not sure if it's ok just to replace SV_position with POSITION or POSITION0 or if I need to make any other adjusments...