57 " attribute vec3 aPosition; \n" 58 " attribute vec3 aNormal; \n" 59 " attribute vec3 aTexCoord; \n" 60 " attribute vec4 aColor; \n" 61 " attribute vec3 aTangent; \n" 62 " attribute vec3 aBitangent; \n" 64 " // vertex position and normal in eye coordinate space \n" 65 " varying vec4 vPosition; \n" 66 " varying vec3 vNormal; \n" 68 " //---------------------------------------------------------------------- \n" 69 " // Main vertex shader code. \n" 70 " //---------------------------------------------------------------------- \n" 74 " // pass along a transformed vertex position, normal, and texture \n" 75 " vPosition = gl_ModelViewMatrix * gl_Vertex; \n" 76 " vNormal = gl_NormalMatrix * aNormal; \n" 77 " gl_TexCoord[0] = gl_TextureMatrix[0] * vec4(aTexCoord, 1.0); \n" 79 " // transform the vertex to get shadow map texture coordinates \n" 80 " float s = dot(gl_EyePlaneS[1], vPosition); \n" 81 " float t = dot(gl_EyePlaneT[1], vPosition); \n" 82 " float r = dot(gl_EyePlaneR[1], vPosition); \n" 83 " float q = dot(gl_EyePlaneQ[1], vPosition); \n" 84 " gl_TexCoord[1] = vec4(s, t, r, q); \n" 86 " // fixed function vertex transform \n" 87 " gl_Position = ftransform(); \n" 93 "// interpolated vertex position in eye coordinate space (from vertex shader) \n" 94 " varying vec4 vPosition; \n" 95 " varying vec3 vNormal; \n" 97 " // shadow (depth) map \n" 98 " uniform sampler2DShadow uShadowMap; \n" 100 " //---------------------------------------------------------------------- \n" 101 " // Computes lighting power and attenuation (Section 2.14.1 of specification) \n" 102 " //---------------------------------------------------------------------- \n" 104 " float attenuation(vec3 p, int i) \n" 106 " vec4 p_l = gl_LightSource[i].position; \n" 107 " if (p_l.w == 0.0) return 1.0; \n" 109 " float d = distance(p, p_l.xyz); \n" 110 " float k0 = gl_LightSource[i].constantAttenuation; \n" 111 " float k1 = gl_LightSource[i].linearAttenuation; \n" 112 " float k2 = gl_LightSource[i].quadraticAttenuation; \n" 114 " return 1.0 / (k0 + k1*d + k2*d*d); \n" 117 " float spotlight(vec3 p, int i) \n" 119 " if (gl_LightSource[i].spotCosCutoff < 0.0) return 1.0; \n" 121 " vec4 p_l = gl_LightSource[i].position; \n" 122 " if (p_l.w == 0.0) return 1.0; \n" 124 " vec3 v = normalize(p - p_l.xyz); \n" 125 " vec3 s = normalize(gl_LightSource[i].spotDirection); \n" 127 " float cosine = max(dot(v, s), 0.0); \n" 128 " if (cosine >= gl_LightSource[i].spotCosCutoff) \n" 129 " return pow(cosine, gl_LightSource[i].spotExponent); \n" 130 " else return 0.0; \n" 134 " //---------------------------------------------------------------------- \n" 135 " // Computes phong shading based on current light and material properties. \n" 136 " //---------------------------------------------------------------------- \n" 138 " vec4 shade(vec3 p, vec3 v, vec3 n) \n" 140 " vec3 Ie = gl_FrontMaterial.emission.rgb; \n" 141 " vec3 Ia = gl_FrontLightModelProduct.sceneColor.rgb; \n" 142 " vec3 Il = vec3(0.0); \n" 144 " for (int i = 0; i < gl_MaxLights; ++i) \n" 146 " vec4 p_l = gl_LightSource[i].position; \n" 147 " vec3 l = normalize(p_l.xyz - p * p_l.w); \n" 148 " vec3 h = normalize(l + v); \n" 149 " float s_m = gl_FrontMaterial.shininess; \n" 151 " float cosNL = max(dot(n, l), 0.0); \n" 152 " float cosNH = max(dot(n, h), 0.0); \n" 154 " vec3 phong = gl_FrontLightProduct[i].ambient.rgb \n" 155 " + cosNL * gl_FrontLightProduct[i].diffuse.rgb \n" 156 " + pow(cosNH, s_m) * gl_FrontLightProduct[i].specular.rgb; \n" 157 " Il += attenuation(p, i) * spotlight(p, i) * phong; \n" 160 " float alpha = gl_FrontMaterial.diffuse.a; \n" 161 " return vec4(Ie + Ia + Il, alpha); \n" 165 " //---------------------------------------------------------------------- \n" 166 " // Main fragment shader code. \n" 167 " //---------------------------------------------------------------------- \n" 169 " void main(void) \n" 171 " vec3 view = normalize(-vPosition.xyz); \n" 172 " vec3 normal = normalize(vNormal); \n" 173 " vec4 shadow = shadow2DProj(uShadowMap, gl_TexCoord[1]); \n" 174 " gl_FragColor = vec4(shade(vPosition.xyz, view, normal).rgb, shadow.a); \n" const std::string C_SHADER_FONG_FRAG
Definition: CShaderFong.h:91
const std::string C_SHADER_FONG_VERT
Definition: CShaderFong.h:55
Implements option settings for CHAI3D.
Definition: CAudioBuffer.cpp:56