DGL
https://delphigl.com/forum/

ASM to GLSL Shader (Geometry Spline)
https://delphigl.com/forum/viewtopic.php?f=20&t=10510
Seite 1 von 1

Autor:  Thmfrnk [ Do Jul 12, 2012 11:50 ]
Betreff des Beitrags:  ASM to GLSL Shader (Geometry Spline)

Moinsen,

ich brächte den Spline Shader aus der NVidia OpenGL SDK in GLSL. Leider liegt der hier nur in Assembler vor. Könnt mir da jemand helfen?

hier der Shader:

Code:
  1.  
  2. !!NVgp4.0
  3.  
  4. # geometry program computing cubic bezier curve
  5. PRIMITIVE_IN LINES_ADJACENCY;
  6. PRIMITIVE_OUT LINE_STRIP;
  7. VERTICES_OUT 100;
  8.  
  9. PARAM segments = program.local[0];
  10. PARAM mvp[4] = { state.matrix.mvp };
  11. TEMP pos, t, dt, temp;
  12. TEMP omt, omt2, b;
  13.  
  14. DIV dt.x, 1.0, segments.x;
  15. MOV t.x, 0.0;
  16. ADD temp.x, segments.x, 1;
  17.  
  18. # loop segments + 1 times to compute the points of the line strip
  19. REP temp.x;
  20.  
  21. # Calculate cubic Bernstein blending functions:
  22. # B0(t) = (1-t)^3  
  23. # B1(t) = 3t(1-t)^2
  24. # B2(t) = 3t^2(1-t)
  25. # B3(t) = t^3
  26. ADD omt.x, 1.0, -t.x;       # omt = 1-t
  27. MUL omt2.x, omt.x, omt.x;   # B1 = (1-t)^2
  28. MUL b.x, omt2.x, omt.x;     # B0 = (1-t)^2 * (1-t) = (1-t)^3
  29. MUL temp.x, 3.0, t.x;       # temp = 3*t
  30. MUL b.y, omt2.x, temp.x;    # B1 = (1-t)^2 * 3*t
  31. MUL b.z, temp.x, t.x;       # B2 = 3*t*t = 3t^2
  32. MUL b.z, b.z, omt.x;        # B2 = 3t^2 * (1-t)
  33. MUL b.w, t.x, t.x;          # B3 = t*t
  34. MUL b.w, b.w, t.x;          # B3 = t*t*t
  35.  
  36. # evaluate curve
  37. MUL pos, vertex[0].position, b.x;
  38. MAD pos, vertex[1].position, b.y, pos;
  39. MAD pos, vertex[2].position, b.z, pos;
  40. MAD pos, vertex[3].position, b.w, pos;
  41.  
  42. # transform to clip space
  43. #DP4 result.position.x, mvp[0], pos;
  44. #DP4 result.position.y, mvp[1], pos;
  45. #DP4 result.position.z, mvp[2], pos;
  46. #DP4 result.position.w, mvp[3], pos;
  47. MOV result.color.x, t.x;
  48. MOV result.position, pos;
  49. EMIT;
  50.  
  51. ADD t, t, dt;
  52. ENDREP;
  53.  
  54. END
  55.  

Autor:  breakdancingYoda [ Do Jul 12, 2012 13:52 ]
Betreff des Beitrags:  Re: ASM to GLSL Shader (Geometry Spline)

Alles was als "PARAM" deklariert ist kannst du durch uniforms ersetzen (bzw die mvp durch die gl_ModelViewProjectionMatrix). Die "TEMP"-Anweisungen machst du einfach zu lok. variablen der "main"-Routine.
Die Arithmetischen Opcodes (ADD, MUL, DIV, MAD, DP4) durch die entsprechenden GLSL-Operatoren ersetzen
(z.B.
ADD omt.x, 1.0, -t.x --> omt = 1.0 - t;
ADD t, t, dt --> t += dt;
MAD pos, vertex[0].position, b.y, pos --> pos = pos + gl_PositionIn[0] * by oder pos += gl_PositionIn[0] * b.y).
Das REP...ENDREP ersetzt du mit einer for-Schleife und alle Operanden mit "vertex[n].~~" mit den entsprechenden attributen (also nur vertex[n].position durch gl_PositionIn[n]). result.position wird zu gl_Position.
EMIT durch EmitVertex() ersetzen und das sollte es gewesen sein.

Autor:  Thmfrnk [ Do Jul 12, 2012 15:10 ]
Betreff des Beitrags:  Re: ASM to GLSL Shader (Geometry Spline)

manche sachen sind mir noch schleiferhaft. Könntest du mir nich das ding bitte schnell zusammen tippen, bevor ich noch 5 fragen habe :roll:

Mercie
Thomas

Autor:  dj3hut1 [ Fr Jul 13, 2012 07:24 ]
Betreff des Beitrags:  Re: ASM to GLSL Shader (Geometry Spline)

Hallo,

vielleicht hilft auch ein Tutorial (Tutorial_Vertexprogramme) im Wiki weiter. ;)

Viele Grüße
dj3hut1

Seite 1 von 1 Alle Zeiten sind UTC + 1 Stunde
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/