float4 PS( PS_INPUT input ) : SV_Target
{
//return saturate( dot((float3)LightDir, input.Normal) ) * DiffuseTexture.Sample(samLinear, input.Texcoord);
return saturate( dot( normalize((float3)input.Pos - (float3)LightPos), input.Normal) ) * DiffuseTexture.Sample(samLinear, input.Texcoord);
}
Simple Point Light Tutorial- link me plz?
I am working through the DirectX tutorials right now, but only found a tutorial with a simple directional light. I need a simple example of the proper implementation of a point light.
I know the theory behind lighting/phong shading, but I'm a little foggy on the specifics in HLSL.
This was my shot in the dark(pun intended lol):
I kinda just rewrote the shader output with the same setup as the directional light...
any ideas? links to tutors?
thanks for any help =)
That one should kinda work, though you should do LightPos-InputPos, not the other way around. Also, is input.Pos in the correct space?
If it's the projected vertex from the vertex-shader then it won't work, you need the world-space position. So you would pass along two positions from your vertex-shader, the standard projected position and the input-position to the vertex-shader unmodified (or multiplied only by the world-matrix if you have a world-matrix).
If it's the projected vertex from the vertex-shader then it won't work, you need the world-space position. So you would pass along two positions from your vertex-shader, the standard projected position and the input-position to the vertex-shader unmodified (or multiplied only by the world-matrix if you have a world-matrix).
no, it's not in the correct space =/
I thought of that, but HLSL seems to be unpredictable most of the time for some reason..
I have:
so I tried:
I got a memory access error though when I tried to use this =/
edit- yeah..grr...this line gives me an access violation when I add it into my pixel shader input struct:
float4 Pos2 : SV_POSITION2;
ONE LAST Edit: OK!
I tried taking off the "SV_", and now it works. There are a few very strange nuances in this language...anywho, I'm off to read this:
http://www.neatware.com/lbstudio/web/hlsl.html
thanks again for the help!
[Edited by - CPPNick on October 27, 2009 5:23:48 PM]
I thought of that, but HLSL seems to be unpredictable most of the time for some reason..
I have:
struct PS_INPUT{ float4 Pos : SV_POSITION; float3 Normal : NORMAL0; float2 Texcoord : TEXCOORD0;};PS_INPUT VS(VS_INPUT input){ PS_INPUT output = (PS_INPUT)0; output.Pos = mul(input.Pos, World); output.Pos = mul(output.Pos, View); output.Pos = mul(output.Pos, Projection); output.Normal = mul(input.Normal, World); output.Texcoord = input.Texcoord; return output;}
so I tried:
struct PS_INPUT{ float4 Pos : SV_POSITION; float3 Normal : NORMAL0; float2 Texcoord : TEXCOORD0; float4 Pos2 : SV_POSITION2; //extra variable};PS_INPUT VS(VS_INPUT input){ PS_INPUT output = (PS_INPUT)0; output.Pos = mul(input.Pos, World); output.Pos = mul(output.Pos, View); output.Pos2 = output.Pos; //save an unprojected copy output.Pos = mul(output.Pos, Projection); output.Normal = mul(input.Normal, World); output.Texcoord = input.Texcoord; return output;}
I got a memory access error though when I tried to use this =/
edit- yeah..grr...this line gives me an access violation when I add it into my pixel shader input struct:
float4 Pos2 : SV_POSITION2;
ONE LAST Edit: OK!
I tried taking off the "SV_", and now it works. There are a few very strange nuances in this language...anywho, I'm off to read this:
http://www.neatware.com/lbstudio/web/hlsl.html
thanks again for the help!
[Edited by - CPPNick on October 27, 2009 5:23:48 PM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement