|
|
Some time ago I started to build up a material system which generates automatically asm-code. I worked through the the book "programming vertex- and pixel shaders" written by wolfang engel.(http://www.charlesriver.com/Books/BookDetail.aspx?productID=87398)
there was also one article about parallax mapping and that's where i got stuck.
as you can see on this screenshot http://coberholzer.dyndns.org/parallax.jpg i archieved a parallax-effect but it's doing exactly the opposite of what it sould do. for example those pyramids. faces which are facing the viewer should get bigger, but tey are now smaller. I can correct that when i flip the v-texture-coordinates (e.g. texcoord.v = 1.0f - texcoord.v), but then the lighting is wrong.
I've spent now many hours trying to find that bug and still can't find it, maybe someone has an idea of what could be wrong?
the shader assembly-code i use follows. I'm sorry, it's not the nicest one because it's generated and not hand-written and i had no time until now to optimize it so it gets nicer.
i'd be really gratefull for any tipps on that. chris
vs.2.0
dcl_position v0
dcl_texcoord0 v1
dcl_normal v2
dcl_tangent v3
; transforming position
m4x4 oPos,v0,c0
; # transforming normal to worldspace
; mul(mat_world,normal)
m4x4 r0,v2,c5
; # transforming tangent to worldspace
; mul(mat_world,tangent)
m4x4 r1,v3,c5
; computing binormal = mul(tangent x normal, mat_world)
mov r3,v3
crs r2.xyz,r3,v2
m4x4 r4,r2,c5
; # transforming position to worldspace
; mul(mat_world,position)
m4x4 r2,v0,c5
; worldToTangentSpace * (eye_position - worldspace_position)
sub r3,c9,r2
dp3 oT0.x,r3,r1
dp3 oT0.y,r3,r4
dp3 oT0.z,r3,r0
; transfer the texture coordinates onto the pixel shader
mov oT1,v1
; transfer the texture coordinates onto the pixel shader
mov oT2,v1
; worldToTangentSpace * (lightposition - worldspace_position)
sub r3,c10,r2
dp3 oT3.x,r3,r1
dp3 oT3.y,r3,r4
dp3 oT3.z,r3,r0
; transfer the texture coordinates onto the pixel shader
mov oT4,v1
|
#line 1 "c:/pshader.txt"
ps.2.0
dcl t0.xyz
dcl t1
dcl t2
dcl t3.xyz
dcl t4
dcl_2d s0
dcl_2d s1
dcl_2d s2
dcl_2d s3
dcl_2d s4
dcl_2d s5
; # normalizing V
nrm r0,t0
; sample pixel color
texld r1,t1,s0
; correcting height according to material
mad r1,c0.y,r1,-c0.z
; computing parallax effect
mad r2,r1,r0,t1
; sample pixel color
texld r3,r2,s1
; sample pixel color
texld r2,t2,s2
; correcting height according to material
mad r2,c0.y,r2,-c0.z
; computing parallax effect
mad r4,r2,r0,t2
; sample pixel color
texld r5,r4,s3
; putting normal vector into useful range!
mad r5,c1.x,r5,-c1.y
; # normalizing L
nrm r4,t3
; # compute diffuse intensity
; saturate(dot(N,L))
dp3_sat r6,r5,r4
; mul(I, light_color)
mul r6,r6,c2
; # mov diffuse light contribution to lighting intensity
mov r7,r6
mul r5,r3,r7
; sample pixel color
texld r3,t4,s4
; correcting height according to material
mad r3,c0.y,r3,-c0.z
; computing parallax effect
mad r6,r3,r0,t4
; sample pixel color
texld r7,r6,s5
; putting normal vector into useful range!
mad r7,c1.x,r7,-c1.y
; R = normalize(2 * (N.L) * N - L)
dp3_sat r8,r7,r4
mul r8,c1.x,r8
mul r8,r8,r7
sub r6,r8,r4
nrm r8,r6
; # compute specular intensity
; I = pow(saturate (dot (R ,V )),reflective_power )
dp3_sat r6.x,r8,r0
; mul(I, light_color)
mul r6,r6,c2
; # mov specular light contribution to lighting intensity
mov r9,r6
add r6,r5,r9
; output final color!
mov oC0,r6
|
|