bad vshader

haho

New member
//c0 world marix
//c4 light position world space
//c5 light consts (light range, 0.0 , 1.0 , 1.0 )
//c6 view*proj matrix

//v0 vertex position object space
//v1 face normal object space

vs.1.1
m4x4 r0, v0, c0 // world transform of point
m3x3 r2, v1, c0 //rotate normal to world space
sub r3, r0, c4 //light to point vector
dp3 r4.x, r3, r3 // (light to point length) ^ 2
rsq r4.y, r4.x //1/(light to point length)
mul r3, r3, r4.y //normalized light to point vector
rcp r4.y, r4.y //light to point length
sub r4.z, c5.x, r4.y //extrusion length
max r4.z, r4.z, c5.y //clamp extrusion length to 0
dp3 r5.x, r2, r3 //if !(normal<dot>light_to_point < 0)...
slt r5.y, r5.x, c5.y //vertex must be extruded...
mad r6, r3, r4.z, r0 //extrude along light to point
m4x4 r6, r6, c6 //extruded position to clip space
m4x4 r0, r0, c6 //original position to clip space

//chose between original position and extruded position
//based on if(normal<dot>light_to_point < 0)
sub r5.z, c5.w, r5.y
mul r3, r6, r5.z
mad oPos, r0, r5.y, r3

hi,

i use this vertex shader in many shadow extrusion techniques.
but the result is unexpected when device type is D3DDEVTYPE_HAL.
maybe there is an appropriate registry usage sequence during shader flow ????

radeon8500 - gigabyte
catalyst 02.2
winxp
 
Re: bad vshader

haho said:
m4x4 r0, r0, c6 //original position to clip space
Don't do this. This expands to
Code:
dp4 r0.x, r0, c6
dp4 r0.y, r0, c7
dp4 r0.z, r0, c8
dp4 r0.w, r0, c9
which makes all but x wrong. I've been burnt by this myself a couple times.
 
Re: bad vshader

haho said:

vs.1.1
m4x4 r0, v0, c0 // world transform of point
m3x3 r2, v1, c0 //rotate normal to world space
sub r3, r0, c4 //light to point vector
dp3 r4.x, r3, r3 // (light to point length) ^ 2
rsq r4.y, r4.x //1/(light to point length)
mul r3, r3, r4.y //normalized light to point vector
rcp r4.y, r4.y //light to point length
sub r4.z, c5.x, r4.y //extrusion length
max r4.z, r4.z, c5.y //clamp extrusion length to 0
dp3 r5.x, r2, r3 //if !(normal<dot>light_to_point < 0)...
slt r5.y, r5.x, c5.y //vertex must be extruded...
mad r6, r3, r4.z, r0 //extrude along light to point
m4x4 r6, r6, c6 //extruded position to clip space
m4x4 r0, r0, c6 //original position to clip space

Wow that looks kind of like the interrupt handler in my OS kernel. Maybe I should take up 3d coding.
 
Re: Re: bad vshader

Re: Re: bad vshader

CBrennan [ATI] said:

Don't do this. This expands to
Code:
dp4 r0.x, r0, c6
dp4 r0.y, r0, c7
dp4 r0.z, r0, c8
dp4 r0.w, r0, c9
which makes all but x wrong. I've been burnt by this myself a couple times.

Ah! That explains an old problem I had when I first started working with vertex shaders. . .
 
Re: Re: Re: bad vshader

Re: Re: Re: bad vshader

Ostsol said:
Ah! That explains an old problem I had when I first started working with vertex shaders. . .

We don't need no stinkin' macros!
:D
 
Back
Top