raymarch_sphere_shaded.vsh
1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
attribute mediump vec2 aPosition;
uniform mediump mat4 uMvpMatrix; // DALi shader builtin
uniform mediump vec3 uSize; // DALi shader builtin
varying mediump vec2 vTexCoord;
varying mediump vec2 vRayCastCoord;
void main()
{
mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);
vertexPosition.xyz *= uSize;
// In this ray march example we supply the fragment shader with 0..1 UV texture co-ordinates
// incase someone wants to extend the code and add texture mapping to it.
// DALi geometry typically ranges from -0.5 to 0.5, hence the +0.5 to make it 0..1
vTexCoord = aPosition + vec2(0.5);
// Our UV texture co-ordinates for the quad geometry should now range from 0..1
//
// (0,0)
// |--------|
// | / |
// | / |
// | / |
// |/-------|(1,1)
//
//
//
// We're going to use the UV co-ordinates as our virtual screen / plane of projection on to our
// raycasted scene.
//
// We first modify the range to be from -1,-1 to 1,1 with 0,0 in the centre. Then
// pass this as a varying value to the fragment shader.
//
//
// (-1,-1)
// |--------------|
// | | |
// | | |
// |_____(0,0)____|
// | | |
// | | |
// |_______|______|(1,1)
//
//
vRayCastCoord = (2.0 * vTexCoord ) - 1.0 ;
gl_Position = uMvpMatrix * vertexPosition;
}