VRML: 3 ways to embed an HLSL shader


/ Published in: Other
Save to your folder(s)

**Important: this snipplet has moved to Github.**

- [Three ways to embed an HLSL shader in VRML/X3D](https://gist.github.com/1972985)


Copy this code and paste it in your HTML
  1. ## FragmentShader
  2. Transform {
  3. translation -4 2 0
  4. children Shape {
  5. appearance Appearance{material Material{diffuseColor 0 0 0 emissiveColor 1 1 1}}
  6. geometry Text{
  7. string "FragmentShader (inline)"
  8. fontStyle FontStyle{justify "MIDDLE" family "Arial" size 0.3}
  9. }
  10. }
  11. }
  12. Transform {
  13. translation -4 0 0
  14. children Shape {
  15. appearance ShaderAppearance {
  16. textureTransform DEF textureTransform TextureTransform {scale 5 5}
  17. fragmentShader FragmentShader {
  18. exposedField SFNode png DEF png ImageTexture {url "example.png"}
  19. url "hlsl:
  20.  
  21. sampler2D png: register(s0);
  22.  
  23. float4 main( float2 tex0: TEXCOORD0 ): COLOR {
  24. return tex2D(png, tex0);
  25. }
  26.  
  27. "
  28. }
  29.  
  30. }
  31. geometry DEF geometry Box{}
  32. }
  33. }
  34.  
  35.  
  36.  
  37. ## VertexShader
  38. Transform {
  39. translation 0 2 0
  40. children Shape {
  41. appearance Appearance{material Material{diffuseColor 0 0 0 emissiveColor 1 1 1}}
  42. geometry Text{
  43. string "VertexShader (.fx)"
  44. fontStyle FontStyle{justify "MIDDLE" family "Arial" size 0.3}
  45. }
  46. }
  47. }
  48. Transform {
  49. translation 0 0 0
  50. children Shape {
  51. appearance ShaderAppearance {
  52. textureTransform USE textureTransform
  53. vertexShader VertexShader {
  54. exposedField SFNode png USE png
  55. url "example.fx"
  56. }
  57.  
  58. }
  59. geometry USE geometry
  60. }
  61. }
  62.  
  63.  
  64.  
  65. ## PackagedShader
  66. Transform {
  67. translation 4 2 0
  68. children Shape {
  69. appearance Appearance{material Material{diffuseColor 0 0 0 emissiveColor 1 1 1}}
  70. geometry Text{
  71. string "PackagedShader (.fx)"
  72. fontStyle FontStyle{justify "MIDDLE" family "Arial" size 0.3}
  73. }
  74. }
  75. }
  76. Transform {
  77. translation 4 0 0
  78. children Shape {
  79. appearance Appearance {
  80. textureTransform USE textureTransform
  81. shaders PackagedShader {
  82. language "HLSL"
  83. exposedField SFNode png USE png
  84. url "example.fx"
  85. }
  86. }
  87. geometry USE geometry
  88. }
  89. }

URL: http://www.wildpeaks.com

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.