vrecko
virtual reality framework
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
grass_shaders_source.h
Go to the documentation of this file.
1
#ifndef GRASS_SHADERS_SOURCE_H
2
#define GRASS_SHADERS_SOURCE_H
3
4
5
const
char
*
lowDetailVertexShaderSource
=
6
" varying float angle; \n"
7
" varying float distance; \n"
8
" uniform float maxVisibility; \n"
9
" uniform float minVisibility; \n"
10
" void main() \n"
11
" { \n"
12
" gl_Position = ftransform(); \n"
13
" angle = 1.0 - max(0.0, dot(vec3(0.0, 0.0, 1.0), gl_NormalMatrix * gl_Normal)); \n"
14
" distance = smoothstep(minVisibility, maxVisibility, \n"
15
" length(gl_ModelViewMatrix * gl_Vertex)); \n"
16
" gl_TexCoord[0].st = gl_MultiTexCoord0.st; \n"
17
" } \n"
;
18
19
20
const
char
*
lowDetailFragmentShaderSource
=
21
" uniform sampler2D far_soil; \n"
22
" uniform sampler2D far_grass; \n"
23
" varying float angle; \n"
24
" varying float distance; \n"
25
" void main( void ) \n"
26
" { \n"
27
" vec4 soilColor = texture2D(far_soil, gl_TexCoord[0].st, -2.0); \n"
28
" vec4 grassColor = texture2D(far_grass, gl_TexCoord[0].st, -2.0); \n"
29
" gl_FragColor = mix(soilColor, grassColor, distance); \n"
30
" } \n"
;
31
32
33
34
const
char
*
detailedVertexShaderSource
=
35
" // uniforms \n"
36
" uniform float osg_FrameTime; \n"
37
" uniform float maxVisibility; \n"
38
" uniform float minVisibility; \n"
39
" \n"
40
" // constants \n"
41
" const vec4 swingConstants1 = vec4(-10.45201, 6.78566, 3.45622, -8.12345); \n"
42
" const vec4 swingConstants2 = vec4(0.37698, 2.67035, 0.47124, 1.69646); \n"
43
" const vec4 swingConstants3 = vec4(0.05457, 0.08145, 0.14247, 0.05442); \n"
44
" \n"
45
" // attributes \n"
46
" attribute mat3 bladeSpaceBase; // (up, orientation, side) \n"
47
" attribute vec4 look; // (width, height, topColor, bottomColor) \n"
48
" attribute vec4 position; // (x, y, z, bend) \n"
49
" \n"
50
" \n"
51
" void main( void ) \n"
52
" { \n"
53
" // compute swing phase of the blade \n"
54
" vec4 swingvec = sin((osg_FrameTime + position.x + position.y + position.z) \n"
55
" * swingConstants1 + swingConstants2); \n"
56
" float bend = position.w + dot(swingvec, swingConstants3); \n"
57
" \n"
58
" // ensure bend is not zero (we will divide by it) \n"
59
" if(bend == 0.0) \n"
60
" bend = 0.00001; \n"
61
" \n"
62
" // compute the angle of the blade \n"
63
" float angle = bend * gl_Vertex.y; \n"
64
" \n"
65
" vec3 bladePoint; \n"
66
" \n"
67
" // normalize previous results and add the width of blade in current point \n"
68
" bladePoint.xy = vec2(sin(angle), 1.0-cos(angle)) * (look.y / bend); \n"
69
" bladePoint.z = look.x * gl_Vertex.x; \n"
70
" \n"
71
" vec4 tempPosition = vec4(position.xyz, 1.0); \n"
72
" \n"
73
" // compute the distance to the root of the blade \n"
74
" float distance = length(gl_ModelViewMatrix * tempPosition); \n"
75
" \n"
76
" // compute scale of the whole blade \n"
77
" float scale = (1.0 - smoothstep(minVisibility, maxVisibility, distance)); \n"
78
" \n"
79
" // compute the position of this point of the blade \n"
80
" tempPosition.xyz += bladeSpaceBase * (bladePoint * scale); \n"
81
" gl_Position = gl_ModelViewProjectionMatrix * tempPosition; \n"
82
" \n"
83
" // forward texture coordinates to fragment shader \n"
84
" gl_TexCoord[0].y = gl_Vertex.y; \n"
85
" gl_TexCoord[0].x = sign(gl_Vertex.x)*0.49 + 0.5; \n"
86
" gl_TexCoord[0].z = scale; \n"
87
" } \n"
;
88
89
90
const
char
*
detailedFragmentShaderSource
=
91
" uniform sampler2D texture; \n"
92
" uniform vec4 neutralColor; \n"
93
" void main( void ) \n"
94
" { \n"
95
" gl_FragColor = mix( neutralColor, \n"
96
" texture2D(texture, gl_TexCoord[0].xy), \n"
97
" gl_TexCoord[0].z \n"
98
" ); \n"
99
" } \n"
;
100
101
102
103
#endif // GRASS_SHADERS_SOURCE_H
include
vreckoAP
Nature
Grass
grass_shaders_source.h
Generated on Tue Feb 19 2013 10:23:44 for vrecko by
1.8.3.1