Xj3D Programmable Shaders Extension Examples

Simple textured box

Classic brick shader demo. The Hello World equivalent for shaders.
#X3D V3.0 utf8

PROFILE Immersive
COMPONENT Shaders:1

Shape {
  appearance Appearance {
    shader GLSLShader {
      initializeOnly SFVec3f BrickColor 1 0.3 0.2
	  initializeOnly SFVec3f MortarColor 0.85 0.86 0.84
	  initializeOnly SFVec2f BrickSize  0.3 0.15
	  initializeOnly SFVec2f BrickPct 0.9 0.85
	  initializeOnly SFVec3f LightPosition 0 0 4
	  objects [
		GLSLShaderObject {
		  url "brick.vert"
		}
		GLSLShaderObject {
		  type "FRAGMENT"
		  url "brick.frag"
		}
	  ]
	}
  }
  geometry Box {}
}

Fallback Declaration

Showing how to define multiple different shading languages in a fallback structure. Says to use OpenGL if possible, if not, use HLSL.
#X3D V3.0 utf8

PROFILE Immersive
COMPONENT Shaders:1

Shape {
  appearance Appearance {
    shader [
	  GLSLShader {
	    initializeOnly SFVec3f BrickColor 1 0.3 0.2
	    initializeOnly SFVec3f MortarColor 0.85 0.86 0.84
	    initializeOnly SFVec2f BrickSize  0.3 0.15
	    initializeOnly SFVec2f BrickPct 0.9 0.85
	    initializeOnly SFVec3f LightPosition 0 0 4
		objects [
		  GLSLShaderObject {
		    url "brick.vert"
		  }
		  GLSLShaderObject {
		    type "FRAGMENT"
		    url "brick.frag"
		  }
		]
	  }
	  HLSLShader {
		vertexShader HLSLShaderObject {
  	      initializeOnly SFVec3f BrickColor 1 0.3 0.2
		  url "brick.vp"
		}
		fragmentShader HLSLShaderObject {
	      initializeOnly SFVec3f MortarColor 0.85 0.86 0.84
	      initializeOnly SFVec2f BrickSize  0.3 0.15
	      initializeOnly SFVec2f BrickPct 0.9 0.85
	      initializeOnly SFVec3f LightPosition 0 0 4
          url "brick.frag"
		}
	  }
	]
  }
  geometry Box {}
}


[ Xj3D Homepage | Xj3D @ Web3d | Screenshots | Dev docs | Dev Releases | Contributors | Getting Started ]
Last updated: $Date: 2004-09-13 06:15:40 $