I'm still trying to convert my pixel shader from PSA2.0 to HLSL to fix
a problem with it cutting off diffuse lighting from directions with negative numbers as representations that I posted weeks ago.
Here is my original shader, which works fine except for cutting off all light when it comes from the left/bottom/front:
ps.2.0
dcl t0 //tex coord
dcl t1 //face normal
dcl_2d s0 //texture
def c3, 0.0f,0.5f,2.0f,-1.0f //handy values for math
//c2.xyz: diffuse licht direction, c2.w=1
//c4: ambient farbe
//c5: diffuse farbe
//c6: difference
dp3_sat r0,t1,c2 //dp face normal (t1) with light direction (c2). Saturates to [0,1]
//dp3 r0,t1,c2//dp face normal (t1) with light direction (c2).
mul r0,r0,c5//multiply by diffuse in [0,1]
mul r0,r0,c6//scale diffuse addend to [0,diffuse-ambient]
add r0,r0,c4//add ambient
//mov r0.w,c2.w
texld r1,t0,s0 //get stage 0 texture from coordinates t0
mul r0,r0,r1//mul texture and light/norm dp
mov oC0,r0//output
Here is the HLSL which
MJP posted on that thread:
float3 LightDir;
float3 AmbientColor;
float3 DiffuseColor;
float3 DiffuseAmbientDiff;
sampler2D DiffuseSampler:register(s0);
float4 PSMain(in float2 texCoord:TEXCOORD0,in float3 normal:TEXCOORD1):COLOR0{
normal=normalize(normal);
float NdotL=saturate(dot(normal,LightDir));
float3 diffuse = NdotL * DiffuseColor * DiffuseAmbientDiff;
//Here is what I believe we'll eventually have to incorporate to include the texture coordinates from the sampler:
//float4 diffuse=tex2D(DiffuseSampler,texCoord)*NdotL*DiffuseColor*DiffuseAmbientDiff+AmbientColor;
return diffuse;
}
I compile the new HLSL shader with:
D3DXCompileShaderFromFile(graphPSFile[dw],NULL,NULL,"PSMain","vs_3_0",D3DXSHADER_DEBUG,&buf,&fehlerMsgs,NULL)
and it gives the error:
hlslPS.txt(12,5): error X3017: cannot implicitly convert from 'float3' to 'float4'
Help appreciated.
Thx.
[Edited by - bababooey on February 27, 2010 3:07:47 PM]