Not logged in, Join Here! or Log In Below:  
 
News Articles Search    
 

 Home / 3D Theory & Graphics / Parallax Mapping Account Manager
 
Archive Notice: This thread is old and no longer active. It is here for reference purposes. This thread was created on an older version of the flipcode forums, before the site closed in 2005. Please keep that in mind as you view this thread, as many of the topics and opinions may be outdated.
 
Christian Oberholzer

May 30, 2005, 07:46 AM

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

  1.  
  2. vs.2.0
  3. dcl_position v0
  4. dcl_texcoord0 v1
  5. dcl_normal v2
  6. dcl_tangent v3
  7. ; transforming position
  8. m4x4 oPos,v0,c0
  9. ; # transforming normal to worldspace
  10. ; mul(mat_world,normal)
  11. m4x4 r0,v2,c5
  12. ; # transforming tangent to worldspace
  13. ; mul(mat_world,tangent)
  14. m4x4 r1,v3,c5
  15. ; computing binormal = mul(tangent x normal, mat_world)
  16. mov r3,v3
  17. crs r2.xyz,r3,v2
  18. m4x4 r4,r2,c5
  19. ; # transforming position to worldspace
  20. ; mul(mat_world,position)
  21. m4x4 r2,v0,c5
  22. ; worldToTangentSpace * (eye_position - worldspace_position)
  23. sub r3,c9,r2
  24. dp3 oT0.x,r3,r1
  25. dp3 oT0.y,r3,r4
  26. dp3 oT0.z,r3,r0
  27. ; transfer the texture coordinates onto the pixel shader
  28. mov oT1,v1
  29. ; transfer the texture coordinates onto the pixel shader
  30. mov oT2,v1
  31. ; worldToTangentSpace * (lightposition - worldspace_position)
  32. sub r3,c10,r2
  33. dp3 oT3.x,r3,r1
  34. dp3 oT3.y,r3,r4
  35. dp3 oT3.z,r3,r0
  36. ; transfer the texture coordinates onto the pixel shader
  37. mov oT4,v1
  38.  


  1.  
  2. #line 1 "c:/pshader.txt"
  3. ps.2.0
  4. dcl t0.xyz
  5. dcl t1
  6. dcl t2
  7. dcl t3.xyz
  8. dcl t4
  9. dcl_2d s0
  10. dcl_2d s1
  11. dcl_2d s2
  12. dcl_2d s3
  13. dcl_2d s4
  14. dcl_2d s5
  15. ; # normalizing V
  16. nrm r0,t0
  17. ; sample pixel color
  18. texld r1,t1,s0
  19. ; correcting height according to material
  20. mad r1,c0.y,r1,-c0.z
  21. ; computing parallax effect
  22. mad r2,r1,r0,t1
  23. ; sample pixel color
  24. texld r3,r2,s1
  25. ; sample pixel color
  26. texld r2,t2,s2
  27. ; correcting height according to material
  28. mad r2,c0.y,r2,-c0.z
  29. ; computing parallax effect
  30. mad r4,r2,r0,t2
  31. ; sample pixel color
  32. texld r5,r4,s3
  33. ; putting normal vector into useful range!
  34. mad r5,c1.x,r5,-c1.y
  35. ; # normalizing L
  36. nrm r4,t3
  37. ; # compute diffuse intensity
  38. ; saturate(dot(N,L))
  39. dp3_sat r6,r5,r4
  40. ; mul(I, light_color)
  41. mul r6,r6,c2
  42. ; # mov diffuse light contribution to lighting intensity
  43. mov r7,r6
  44. mul r5,r3,r7
  45. ; sample pixel color
  46. texld r3,t4,s4
  47. ; correcting height according to material
  48. mad r3,c0.y,r3,-c0.z
  49. ; computing parallax effect
  50. mad r6,r3,r0,t4
  51. ; sample pixel color
  52. texld r7,r6,s5
  53. ; putting normal vector into useful range!
  54. mad r7,c1.x,r7,-c1.y
  55. ; R = normalize(2 * (N.L) * N - L)
  56. dp3_sat r8,r7,r4
  57. mul r8,c1.x,r8
  58. mul r8,r8,r7
  59. sub r6,r8,r4
  60. nrm r8,r6
  61. ; # compute specular intensity
  62. ; I = pow(saturate(dot(R,V)),reflective_power)
  63. dp3_sat r6.x,r8,r0
  64. pow r6,r6.x,c0.x
  65. ; mul(I, light_color)
  66. mul r6,r6,c2
  67. ; # mov specular light contribution to lighting intensity
  68. mov r9,r6
  69. add r6,r5,r9
  70. ; output final color!
  71. mov oC0,r6
  72.  

 
Wernaeh

May 30, 2005, 06:11 PM

Hi there ;)

Perhaps you should have a look at these two threads, especially the latter - which seems to describe the same problem as you encountered.

As far as I know, you need to use different .v for lighting and parallax offseting, but read it for yourself.

http://www.flipcode.com/cgi-bin/fcmsg.cgi?thread_show=24599
http://www.flipcode.com/cgi-bin/fcmsg.cgi?thread_show=24680

Nebenbei bemerkt, deine Stadt heisst genauso wie meine Autoversicherung... Zufall ?

Cheers,
- Wernaeh

 
Christian Oberholzer

May 31, 2005, 05:17 AM

I've read the first thread already, but I have overseen the second one. it could very well be the solution to my problems. thank you for posting it. I will have a deeper look at it as soon as i get home, where i can test ps2.0-code with a HAL device ;-)

Zur Stadt Winterthur. Winterthur ist eine der grösseren Städte (ca. 100'000 Einwohner) der Schweiz. Sie liegt ca. 40-50km östlich von Zürich. Soviel ich weiss hat die Winterthur Versicherung hier ihren Hauptsitz. Ich bin mir nicht sicher ob es einen direkten Zusammenhang gibt oder ob es Zufall ist, vermute aber, dass die Winterthur Versicherung ihren Namen nach ihrem Herkunftsort Winterthur hat. (Alle Angaben ohne Gewähr ;-) )

Greets
Chris

 
Wernaeh

May 31, 2005, 10:29 AM

Ah oki, danke ;)

Cheers,
- Wernaeh

 
davepermen

May 31, 2005, 01:00 PM

hehe, ich bin auch bei der winterthur versichert.. :D selbst aber vom westen :D (augst, nähe basel)

 
Christian Oberholzer

May 31, 2005, 03:36 PM

Ah da lernt man die Umgebung kennen ;-)

And to close this question about parallax mapping and for the record for everyone searching for help on the same topic...

With reading what's described in the second thread i managed to find the error. with inverting the y-component of the normal-vector from the normal-map finally everything worked fine. and that's something i'm able to convert directly on the texture without touching the algorithm in the shader :-)

so for anyone trying to do normalmapping and parallaxmapping as i've done it here are the things i wasted most of my time on:
- if lighting is not as it should be and flipping the direction of the binormal solves the problem be sure that
* the v-coordinate of your model is correct
* the y-component of the normalmap is correct, e.g. try to invert it (normal.y = -normal.y)
- if there are strange artifacts (i can show screenshots to anyone who wants) on your texture mapping when using parallax mapping maybe you are using values to bias the heightmap which are too big. (e.g. incidenntally 0.4 instead of 0.04).

finally, thank you Wernaeh for posting these two links, they saved me from loosing some hours more ;-)

Cheers
Chris

 
This thread contains 6 messages.
 
 
Hosting by Solid Eight Studios, maker of PhotoTangler Collage Maker.