DOT3 bump mapping vertex shader

Started by
0 comments, last by Jimfing 19 years, 11 months ago
Hi, i''m trying to write a vertex shader to take the light vector of a direction light, transform it into texture space, then put the resulting vector into the diffuse component of each vertex so the texture blender can do it''s magic with the DOT3 colour operation. My problem i think is the vertex shader (i''m a shader n00b), and I can''t for the life of me get it to work. Probably something really obvious but here goes:

vs.1.1

dcl_position v0 
dcl_normal v3 
dcl_texcoord0 v5 
dcl_texcoord1 v6 
dcl_tangent   v7
dcl_binormal  v8

// Transform position by world*view*projection

m4x4 oPos, v0, c0

// Copy base texture coords

mov oT0, v5
mov oT1, v5

// transform texture space vectors into world space

m3x3 r0, v3, c4
m3x3 r1, v7, c4
m3x3 r2, v8, c4

// transform light vector into texture space

// putting the resulting vector into the diffuse colour component

dp3 oD0.x, r0, c9
dp3 oD0.y, r1, c9
dp3 oD0.z, r2, c9
c0-c3 is the world*view*projection c4-c7 is the world matrix c9 is the light vector Thanks for any help.
Advertisement
Just do:

vs.1.1dcl_position v0 dcl_normal v3 dcl_texcoord0 v5 dcl_texcoord1 v6 dcl_tangent   v7dcl_binormal  v8// Transform position by world*view*projectionm4x4 oPos, v0, c0// Copy base texture coordsmov oT0, v5mov oT1, v5// transform light vector into texture space// putting the resulting vector into the diffuse colour componentdp3 oD0.x, v7, c9dp3 oD0.y, v8, c9dp3 oD0.z, v3, c9


Whatch out because putting things in the color clamps it to [0,1]

This topic is closed to new replies.

Advertisement