Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Basic per-vertex lighting shaders

This topic is 5136 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am trying to do the fixed function per-vertex lighting with shaders, but I don''t know how to write the pixel shader to see the result good, I am using rendermonkey and DX, and I get only object with plain colour, without ilumination. (Note: Its needed to write a pixel shader in rendermonkey, it can''t use the fixed function, so I want to write a pixel shader that lets me see the vertex shader result) Here is my trying in ASM and HLSL:

dcl_position v0
dcl_normal v3
dcl_color v5
dcl_texcoord0 v7

def c4, 0.577f, 0.577f, 0.577f, 1.0f

//m4x4 oPos, v0, c0

dp4 oPos.x, c0, v0
dp4 oPos.y, c1, v0
dp4 oPos.z, c2, v0
dp4 oPos.w, c3, v0

dp3 r0, v3, c4
mul oD0, r0.x, v5
mov oT0.xy, v7

tex t0
//mul r0, v0, t0

mov r0, t0

float4x4 view_proj_matrix;

struct VS_OUTPUT 
   float4 Pos: POSITION;
   float3 Col: COLOR0;
   float2 TexCoord: TEXCOORD0;

const static float3 light_dir = float3(2.0f,2.0f,2.0f);

VS_OUTPUT vs_main( float4 inPos: POSITION, 
                   float3 inNormal: NORMAL,
                   float2 inTexCoord: TEXCOORD0 )

   Out.Pos = mul(view_proj_matrix,inPos);
   //Out.Col = dot(float4(inNormal,1.0f),-light_dir);

   Out.Col = dot(normalize(inNormal),-normalize(light_dir));
   Out.TexCoord = inTexCoord;

   return Out;

float4 ps_main( float4 inDiffuse: COLOR0 ) : COLOR0
   return inDiffuse + float4(1.0f, 0.5f, 0.0f, 1.0f);

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!