9 #include "FogShaderUniforms.h"
10 #include "FogShaderOld.h"
11 #include "VectorMath.h"
12 #include "WaterShader.h"
13 #include "FogShaderIncludes.h"
22 namespace WaterTransitionShaderCode
24 const std::string _fragmentShaderUniformDeclarations =
25 "varying highp vec4 ColorVarying;\n"
26 "varying highp vec2 DestinationUV;\n"
27 "varying highp vec2 DestinationUV2;\n"
28 "varying highp vec4 ReflectVector;\n"
29 "uniform sampler2D FromDiffuse;\n"
30 "uniform sampler2D ToDiffuse;\n"
31 "uniform sampler2D NormalMap;\n"
32 "uniform samplerCube FromReflectionMap;\n"
33 "uniform samplerCube ToReflectionMap;\n"
34 "uniform lowp float ReflectionWaveDisplacement;\n"
35 "uniform lowp float LerpParam;\n";
38 const std::string _fragmentShaderMain =
39 "void main(void) { \n"
40 "highp vec4 diffuseColor = mix(texture2D(FromDiffuse, DestinationUV), texture2D(ToDiffuse, DestinationUV), LerpParam);\n"
41 "highp vec3 normal = ((2.0 * texture2D(NormalMap, DestinationUV2).xyz) - 1.0);\n"
42 "highp vec3 refl = normalize(ReflectVector.xyz + normal*ReflectionWaveDisplacement);\n"
43 "highp vec4 reflection = mix(textureCube(FromReflectionMap, refl), textureCube(ToReflectionMap, refl), LerpParam);\n"
44 "lowp vec3 colour = (diffuseColor.xyz * ColorVarying.xyz) + (reflection.xyz * ColorVarying.w);\n"
45 "gl_FragColor.rgb = mix(colour, FogColour.rgb, ReflectVector.w);\n"
46 "gl_FragColor.a = 1.0;\n"
55 std::string vertexShaderCode = WaterShaderCode::_vertexShaderUniformDeclarations + FOG_VERTEX_SHADER_UNIFORMS + FOG_VERTEX_SHADER_FUNCTIONS + WaterShaderCode::_vertexShaderMain;
56 std::string fragmentShaderCode = WaterTransitionShaderCode::_fragmentShaderUniformDeclarations + FOG_FRAGMENT_SHADER_UNIFORMS + WaterTransitionShaderCode::_fragmentShaderMain;
65 const GLuint GetFromDiffuseSamplerId()
const {
return 0; }
66 const GLuint GetToDiffuseSamplerId()
const {
return 1; }
67 const GLuint GetNormalSamplerId()
const {
return 2; }
68 const GLuint GetFromReflectionSamplerId()
const {
return 3; }
69 const GLuint GetToReflectionSamplerId()
const {
return 3; }
71 void SetLerpParam(
const float l)
73 SetUniformFloat(l, m_lerpParamUniform);
76 void SetMVP(
const m44& mvp)
const
78 bool transpose =
false;
79 SetUniformM44(mvp, m_modelViewProjectionUniform, transpose);
82 void SetMV(
const m44& mv)
const
84 bool transpose =
false;
85 SetUniformM44(mv, m_modelViewUniform, transpose);
90 Eegeo::Base::FogShaderOld::SetPerMaterialRenderState(m_fogShaderUniforms, fogUniformValues);
93 void SetLightColors(
const m44& colors)
const
95 bool transpose =
false;
96 SetUniformM44(colors, m_lightColorsUniform, transpose);
99 void SetAnimatedUV(
const v4& uv)
const
101 SetUniformV4(uv, m_animatedUVUniform);
104 void SetAltitudeEnvMapFade(
const float v)
const
106 SetUniformFloat(v, m_altitudeEnvMapFadeUniform);
111 SetUniformV2(min, m_minUVRangeUniform);
112 SetUniformV2(max, m_maxUVRangeUniform);
117 SetUniformV4(min, m_minVertRangeUniform);
118 SetUniformV4(max, m_maxVertRangeUniform);
121 void SetWaveDisplacement(
const float v)
const
123 SetUniformFloat(v, m_reflectionWaveDisplacementUniform);
126 void SetCameraRelativeOrigin(
const Eegeo::v3& cameraRelativeOrigin)
const
128 SetUniformV3(cameraRelativeOrigin, m_cameraRelativeModelOriginUniformLocation);
131 void SetViewToCubeMapMatrix(
const m44& viewToCubeMapMatrix)
133 bool transpose =
false;
134 SetUniformM44(viewToCubeMapMatrix, m_viewToCubeMapUniform, transpose);
140 SetUniformTextureSampler(glState, GetFromDiffuseSamplerId(), m_fromDiffuseTextureSampler);
141 SetUniformTextureSampler(glState, GetToDiffuseSamplerId(), m_toDiffuseTextureSampler);
142 SetUniformTextureSampler(glState, GetNormalSamplerId(), m_normalMapTextureSampler);
143 SetUniformTextureSampler(glState, GetFromReflectionSamplerId(), m_fromReflectionMapTextureSampler);
144 SetUniformTextureSampler(glState, GetToReflectionSamplerId(), m_toReflectionMapTextureSampler);
148 WaterTransitionShader(
const TShaderId shaderId,
const std::string& vertexShaderCode,
const std::string& fragmentShaderCode) :
Shader(shaderId)
150 CompileProgram(vertexShaderCode, fragmentShaderCode);
152 m_modelViewProjectionUniform = GetUniformLocation(
"ModelViewProjectionMatrix");
153 m_modelViewUniform = GetUniformLocation(
"ModelViewMatrix");
154 m_lightColorsUniform = GetUniformLocation(
"LightColorMatrix");
155 m_animatedUVUniform = GetUniformLocation(
"AnimatedUVUniform");
156 m_fromDiffuseTextureSampler = GetUniformLocation(
"FromDiffuse");
157 m_toDiffuseTextureSampler = GetUniformLocation(
"ToDiffuse");
158 m_normalMapTextureSampler = GetUniformLocation(
"NormalMap");
159 m_fromReflectionMapTextureSampler = GetUniformLocation(
"FromReflectionMap");
160 m_toReflectionMapTextureSampler = GetUniformLocation(
"ToReflectionMap");
161 m_altitudeEnvMapFadeUniform = GetUniformLocation(
"AltitudeEnvMapFade");
162 m_lerpParamUniform = GetUniformLocation(
"LerpParam");
164 m_minVertRangeUniform = GetUniformLocation(
"MinVertRange");
165 m_maxVertRangeUniform = GetUniformLocation(
"MaxVertRange");
166 m_minUVRangeUniform = GetUniformLocation(
"MinUVRange");
167 m_maxUVRangeUniform = GetUniformLocation(
"MaxUVRange");
168 m_reflectionWaveDisplacementUniform = GetUniformLocation(
"ReflectionWaveDisplacement");
170 m_cameraRelativeModelOriginUniformLocation = GetUniformLocation(
"CameraRelativeModelOrigin");
171 m_viewToCubeMapUniform = GetUniformLocation(
"ViewToCubeMapMatrix");
172 m_fogShaderUniforms.DetermineUniformsFromShader(
this);
176 GLuint m_modelViewProjectionUniform;
177 GLuint m_modelViewUniform;
178 GLuint m_altitudeEnvMapFadeUniform;
179 GLuint m_lightColorsUniform;
180 GLuint m_minVertRangeUniform;
181 GLuint m_maxVertRangeUniform;
182 GLuint m_minUVRangeUniform;
183 GLuint m_maxUVRangeUniform;
184 GLuint m_fromDiffuseTextureSampler;
185 GLuint m_toDiffuseTextureSampler;
186 GLuint m_normalMapTextureSampler;
187 GLuint m_fromReflectionMapTextureSampler;
188 GLuint m_toReflectionMapTextureSampler;
189 GLuint m_animatedUVUniform;
190 GLuint m_reflectionWaveDisplacementUniform;
191 GLuint m_cameraRelativeModelOriginUniformLocation;
192 GLuint m_lerpParamUniform;
193 GLuint m_viewToCubeMapUniform;