Original Post
Hello
I'm trying to develop a simple shader that implements Phong light model (in HLSL , for DX10.0)
The interpolated normal given in the PS seems to be good, but the specular term 'seems' to be calculated per vertex only instead of per pixel.
I'm not sure the vPosViewer member in PS_INPUT1 is interpolated.
Here's my main shader code :
Thank you very much
NB : if you know a site with DX10 HLSL examples, I'm interested !
I'm trying to develop a simple shader that implements Phong light model (in HLSL , for DX10.0)
The interpolated normal given in the PS seems to be good, but the specular term 'seems' to be calculated per vertex only instead of per pixel.
I'm not sure the vPosViewer member in PS_INPUT1 is interpolated.
Here's my main shader code :
struct VS_INPUT1
{
float3 vPosObject : POSITION;
float3 vNormalObject : NORMAL;
float2 vTexUV : TEXCOORD0;
};
struct PS_INPUT1
{
float4 vPosProj : SV_POSITION;
float3 vPosViewer : POSWORLD;
float3 vNormalWorld : NORMAL;
float2 vTexUV : TEXCOORD0;
};
PS_INPUT1 VS1( VS_INPUT1 input )
{
PS_INPUT1 output;
float4 vPosWorld = mul( float4(input.vPosObject,1), g_mWorld );
output.vPosViewer= vPosWorld;
output.vPosProj = mul( float4(input.vPosObject,1), g_mWorldViewProjection );
float3 vNormalWorld = normalize( mul( input.vNormalObject, (float3x3)g_mWorld ) );
output.vNormalWorld = vNormalWorld;
output.vTexUV = input.vTexUV;
return output;
}
float4 PS1( PS_INPUT1 input) : SV_Target
{
float4 output = float4(g_vAmbientColor+g_vLightColor* saturate(-dot(g_vLightDirection, input.vNormalWorld)),1);
if (g_nShininess)
{
float3 vCamera = normalize(input.vPosViewer-g_vCameraPosition);
float3 vReflection = reflect( g_vLightDirection, input.vNormalWorld );
float fPhoneValue = saturate( -dot(vReflection, vCamera) );
output.rgb += g_vLightColor* pow( fPhoneValue,100 );
}
float4 color=g_MeshTexture.Sample( samLinear, input.vTexUV );
output *= color;
return output;
}
Thank you very much
NB : if you know a site with DX10 HLSL examples, I'm interested !
