Question about Reflection Map Texture Coordinates?

Started by
1 comment, last by sevecol 20 years, 10 months ago
I use CPU to calculate the Reflection Map Texture Coordinates,the display is ok: Then I move the codes into vertex shader and when I rotate the water surface,they display error: error1 error2 My vertex shader code: vs.1.1 dcl_position0 v0 dcl_normal0 v1 dcl_texcoord0 v2 def c24,-0.6f, 0.0f,0.6f,1.0f def c25, 0.0f, 0.0f,0.6f,1.0f def c26, 0.6f, 0.0f,0.0f,1.0f def c27, 0.6f,0.0f,-0.6f,1.0f def c28, 0.0f,0.0f,-0.6f,1.0f def c29,-0.6f, 0.0f,0.0f,1.0f def c30,1.0f,1.0f,0.5f,0.0f m4x4 r10,v0,c0 mov oPos,r10 ;calculate normal mov r0,c24 mov r0.y,v1.x add r0.y,r0.y,-v0.y mov r1,c25 mov r1.y,v1.y add r1.y,r1.y,-v0.y mov r2,c26 mov r2.y,v1.z add r2.y,r2.y,-v0.y mov r3,c27 mov r3.y,v2.x add r3.y,r3.y,-v0.y mov r4,c28 mov r4.y,v2.y add r4.y,r4.y,-v0.y mov r5,c29 mov r5.y,v2.z add r5.y,r5.y,-v0.y mul r6,-r1.zxyw,r0.yzxw mad r8,-r1.yzxw,r0.zxyw,-r6 mul r6,-r2.zxyw,r1.yzxw mad r7,-r2.yzxw,r1.zxyw,-r6 add r8,r8,r7 mul r6,-r3.zxyw,r2.yzxw mad r7,-r3.yzxw,r2.zxyw,-r6 add r8,r8,r7 mul r6,-r4.zxyw,r3.yzxw mad r7,-r4.yzxw,r3.zxyw,-r6 add r8,r8,r7 mul r6,-r5.zxyw,r4.yzxw mad r7,-r5.yzxw,r4.zxyw,-r6 add r8,r8,r7 mul r6,-r0.zxyw,r5.yzxw mad r7,-r0.yzxw,r5.zxyw,-r6 add r8,r8,r7 dp3 r7.w,r8,r8 rsq r7,r7.w mul r8,r8,r7 ;calculate the texture coordinates rcp r10.w,r10.w mul r10,r10,r10.w add r0.xy,r10.xy,c30 mul oT0.xy,r0.xy,c30.z Please Help me.
Advertisement
waiting help......
Here I go...

This is my shader, I used 4 neighbor points instead of 6, looks fine.

// Vertex Shader for Water Surface Texture Processing - 2
// With normal generate on the fly ver.

// Register declarations

// c0 : WorldViewProjection Matrix
// c4 : WorldView Matrix
// c8-c9: View-Rotation Correction Matrix
// c10 : Water color( r, g, b, a )
//
//
// v0 : Vertex Position
// v1 : 4 Neighbor Heights: x:left, y: right, z: up, w:down

// oPos : Homogenous Position of Vertex
// oT0 : Refraction Texture Coordinate
// oT1 : Reflection Texture Coordinate
// oD0 : Diffuse color

vs.1.1
dcl_position v0
dcl_texcoord v1

def c11, 0.675, -0.9, 0.5, 0.0
def c12, 0.3, -0.3, -1.0, 1.0

// Transform to screen space
dp4 r0.x, v0, c0
dp4 r0.y, v0, c1
dp4 r0.z, v0, c2
dp4 r0.w, v0, c3

mov oPos, r0
mov oD0, c10

// Get reciprocal of w;
rcp r0.w, r0.w

// Transform to view space as texture coordinates
dp4 r1.x, v0, c4
dp4 r1.y, v0, c5
dp4 r1.z, v0, c6


// Do projection divison
rcp r1.z, r1.z
mul r1.xy, r1.xy, r1.zz;

// Transform to view space
mad r1.xy, r1.xy, c11.xy, c11.zz

// Generate Normal by getting difference between neighbors
mov r2.w, v0.y
sub r3.xw, r2.ww, v1.xw
sub r3.yz, v1.yz, r2.ww
add r2.xz, r3.xz, r3.yw

// Normalize Normal
mov r2.y, c12.w
dp3 r8.x, r2.xyz, r2.xyz
rsq r8.xyz, r8.x
mul r5.xyz, r2.xyz, r8.xyz

// Transform normal using correction rotation matrix
dp3 r6.x, r5.xz, c8.xy
dp3 r6.y, r5.xz, c9.xy

// Scale displacement by distance of vertex
mul r6.xy, r6.xy, r0.ww

// Calculate refraction
mad oT0.xy, r6.xy, c12.xy, r1.xy

// Calculate reflection
mad oT1.xy, r6.xy, c12.zw, r1.xy

Crazying for Programmable Graphics Cards...
Crazying for Programmable Graphics Cards...

This topic is closed to new replies.

Advertisement