Skip to content

Commit 551d07f

Browse files
committed
Added VRML version to example.
1 parent c285ef4 commit 551d07f

File tree

1 file changed

+61
-1
lines changed

1 file changed

+61
-1
lines changed

docs/_posts/custom-shaders.md

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ However, you will often want to perform special effects or special cases for you
2323

2424
WebGL uses the GLSL language to write shaders that can be run across all browsers. With X_ITE you create your own shader using [ComposedShader](/x_ite/components/shaders/composedshader/) and [ShaderPart](/x_ite/components/shaders/shaderpart/) nodes and than attach the ComposedShader to the *shader* field of an [Appearance](/x_ite/components/shape/appearance/) node and that is a child's play with [Sunrize](/sunrize/).
2525

26-
### X3D
26+
### XML Encoding
2727

2828
```xml
2929
<?xml version="1.0" encoding="UTF-8"?>
@@ -76,6 +76,66 @@ uniform sampler2D x3d_Texture2D [1]; // image from ImageTexture node
7676
</X3D>
7777
```
7878

79+
### Classic VRML Encoding
80+
81+
```vrml
82+
#X3D V{{ site.x3d_latest_version }} utf8
83+
84+
PROFILE Interchange
85+
86+
COMPONENT Shaders : 1
87+
88+
Viewpoint {
89+
position 9.279771 8.706816 16.22163
90+
orientation -0.83432609774564 0.526445494105168 0.163569876068002 0.712985187365762
91+
centerOfRotation 4.5 0 4.5
92+
}
93+
94+
DEF Timer TimeSensor {
95+
loop TRUE
96+
}
97+
98+
Transform {
99+
children Shape {
100+
appearance Appearance {
101+
texture ImageTexture {
102+
url "image.png"
103+
}
104+
shaders DEF Shader ComposedShader {
105+
inputOnly SFTime set_time
106+
107+
language "GLSL"
108+
parts [
109+
ShaderPart {
110+
url "data:x-shader/x-vertex,#version 300 es
111+
// Vertex Shader
112+
...
113+
uniform float set_time; // value from set_time field
114+
...
115+
"
116+
}
117+
ShaderPart {
118+
type "FRAGMENT"
119+
url "data:x-shader/x-fragment,#version 300 es
120+
// Fragment Shader
121+
...
122+
uniform sampler2D x3d_Texture2D [1]; // image from ImageTexture node
123+
...
124+
"
125+
}
126+
]
127+
}
128+
}
129+
geometry ElevationGrid {
130+
xDimension 10
131+
zDimension 10
132+
}
133+
}
134+
}
135+
136+
ROUTE Timer.elapsedTime TO Shader.set_time
137+
```
138+
79139
Once the X3D is defined we can now write the vertex and the fragment shader source. This is a simple example where a texture is applied to the geometry.
80140

81141
### Vertex Shader

0 commit comments

Comments
 (0)