8 #include "WaterTransitionShader.h"
10 #include "Rendering.h"
11 #include "TextureMinifyType.h"
12 #include "VectorMath.h"
14 #include "MathsHelpers.h"
15 #include "GlobalFogging.h"
16 #include "GlobalLighting.h"
17 #include "WaterRenderable.h"
18 #include "GLHelpers.h"
19 #include "EarthConstants.h"
20 #include "WaterMaterial2.h"
21 #include "IAsyncTexture.h"
34 const TMaterialId materialId,
35 const std::string& name,
45 Rendering::TextureMinifyType textureMinifyType,
46 bool useAlternativeAmbient,
50 float envMapFadeoutAltitude
55 , m_lighting(lighting)
57 , m_fromDiffuseTextureId(&fromDiffuseTextureId)
58 , m_toDiffuseTextureId(&toDiffuseTextureId)
59 , m_normalMapTextureId(&normalMapTextureId)
60 , m_fromReflectionMapTextureId(&fromReflectionTextureId)
61 , m_toReflectionMapTextureId(&toReflectionTextureId)
62 , m_defaultReflectionCubeMapTextureId(&defaultReflectionCubeMapTextureId)
63 , m_textureMinifyType(textureMinifyType)
64 , m_textureRepeat(textureRepeat)
65 , m_useAlternativeAmbient(useAlternativeAmbient)
66 , m_altitudeScale(0.f)
67 , m_animationScaleUV(animationScaleUV)
68 , m_animationWrapUV(animationWrapUV)
69 , m_animationStateUV(0,0,1,1)
71 , m_envMapFadeoutAltitude(envMapFadeoutAltitude)
75 bool IsUsingAlternativeAmbient()
const {
return m_useAlternativeAmbient; }
76 void UseAlternativeAmbient(
bool useAlternativeAmbient) { m_useAlternativeAmbient = useAlternativeAmbient; }
78 const TMaterialId GetId()
const {
return m_id; }
79 const Shader& GetShader()
const {
return m_shader; }
80 const std::string& GetName()
const {
return m_name; }
97 void SetLerpParam(
float t) { m_lerpParam = t; }
98 float GetLerpParam()
const {
return m_lerpParam; }
100 void UpdateMaterial(
float deltaTime,
const dv3& ecefCameraPosition)
104 const float MaxEnvMapBlend = 0.5f;
105 const float EnvMapBlendDelta = -0.5f;
106 altitude = Clamp(altitude, 0.0f, m_envMapFadeoutAltitude);
107 m_altitudeScale = Helpers::MathsHelpers::PennerQuadraticEaseOut(altitude,
110 m_envMapFadeoutAltitude);
112 m_animationStateUV.SetX(m_animationStateUV.GetX() + deltaTime * m_animationScaleUV.GetX());
113 m_animationStateUV.SetY(m_animationStateUV.GetY() + deltaTime * m_animationScaleUV.GetY());
115 if(m_animationStateUV.GetX() > m_animationWrapUV.GetX())
117 m_animationStateUV.SetX(m_animationStateUV.GetX() - m_animationWrapUV.GetX());
119 else if(m_animationStateUV.GetX() < -m_animationWrapUV.GetX())
121 m_animationStateUV.SetX(m_animationStateUV.GetX() + m_animationWrapUV.GetX());
124 if(m_animationStateUV.GetY() > m_animationWrapUV.GetY())
126 m_animationStateUV.SetY(m_animationStateUV.GetY() - m_animationWrapUV.GetY());
128 else if(m_animationStateUV.GetY() < -m_animationWrapUV.GetY())
130 m_animationStateUV.SetY(m_animationStateUV.GetY() + m_animationWrapUV.GetY());
136 m_shader.Use(glState);
138 glState.Blend.Disable();
139 glState.DepthTest.Enable();
141 const Eegeo::m44 &lightColors = m_lighting.GetColors(m_useAlternativeAmbient);
142 m_shader.SetLightColors(lightColors);
143 m_shader.SetLerpParam(m_lerpParam);
146 m_fogging.GetUniformValues(fogValues);
147 m_shader.SetFogUniforms(fogValues);
148 m_shader.SetAnimatedUV(m_animationStateUV);
149 m_shader.SetAltitudeEnvMapFade(m_altitudeScale);
150 m_shader.SetWaveDisplacement(1.0f / 16.0f);
152 Helpers::GLHelpers::BindTexture2D(glState, m_shader.GetFromDiffuseSamplerId(), m_fromDiffuseTextureId->GetTextureInfo().textureId, m_textureMinifyType, m_textureRepeat);
153 Helpers::GLHelpers::BindTexture2D(glState, m_shader.GetToDiffuseSamplerId(), m_toDiffuseTextureId->GetTextureInfo().textureId, m_textureMinifyType, m_textureRepeat);
154 Helpers::GLHelpers::BindTexture2D(glState, m_shader.GetNormalSamplerId(), m_normalMapTextureId->GetTextureInfo().textureId, m_textureMinifyType, m_textureRepeat);
156 Helpers::GLHelpers::BindTextureCube(glState, m_shader.GetFromReflectionSamplerId(), m_fromReflectionMapTextureId != NULL ? m_fromReflectionMapTextureId->GetTextureInfo().textureId : m_defaultReflectionCubeMapTextureId->GetTextureInfo().textureId);
157 Helpers::GLHelpers::BindTextureCube(glState, m_shader.GetToReflectionSamplerId(), m_toReflectionMapTextureId != NULL ? m_toReflectionMapTextureId->GetTextureInfo().textureId : m_defaultReflectionCubeMapTextureId->GetTextureInfo().textureId);
163 m_shader.SetMVP(waterRenderable->GetModelViewProjection());
164 m_shader.SetMV(waterRenderable->GetModelView());
166 m44 viewToCubemapMatrix = WaterMaterial2::CalculateViewToCubeMapMatrix(*waterRenderable);
167 m_shader.SetViewToCubeMapMatrix(viewToCubemapMatrix);
169 m_shader.SetUVBounds(waterRenderable->GetUVBoundsMin(), waterRenderable->GetUVBoundsMax());
170 m_shader.SetPositionBounds(waterRenderable->GetPositionBoundsMin(), waterRenderable->GetPositionBoundsMax());
171 m_shader.SetCameraRelativeOrigin(waterRenderable->GetCameraRelativeModelOrigin());
175 const TMaterialId m_id;
176 const std::string m_name;
186 Rendering::TextureMinifyType m_textureMinifyType;
187 bool m_textureRepeat;
188 bool m_useAlternativeAmbient;
189 float m_altitudeScale;
194 float m_envMapFadeoutAltitude;