5 #include "PackedDiffuseShader.h"
6 #include "ShaderMacros.h"
7 #include "VectorMath.h"
8 #include "FogShaderIncludes.h"
9 #include "FogShaderUniforms.h"
11 #include "FogShaderOld.h"
12 #include "GlobalFogging.h"
21 namespace LightmappedPackedDiffuseShaderCode
23 const std::string UV2Name =
"UV2";
24 const std::string GlowmapName =
"Glowmap";
25 const std::string GlowmapColourName =
"GlowmapColour";
26 const std::string GlowmapParamName =
"GlowmapParam";
27 const std::string AmbientColourName =
"AmbientColour";
28 const std::string MinPosRangeName =
"MinPosRange";
29 const std::string MaxPosRangeName =
"MaxPosRange";
31 const std::string _vertexDecls =
32 "attribute lowp vec2 "+UV2Name+
";\n"
33 "varying highp vec2 DestinationUV2;\n"
34 "uniform highp vec4 "+MinPosRangeName+
";\n"
35 "uniform highp vec4 "+MaxPosRangeName+
";\n"
36 FOG_VERTEX_SHADER_UNIFORMS;
38 const std::string _fragmentDecls =
39 "varying highp vec2 DestinationUV2;\n"
40 "uniform lowp float "+GlowmapParamName+
";\n"
41 "uniform lowp vec3 "+GlowmapColourName+
";\n"
42 "uniform lowp vec3 "+AmbientColourName+
";\n"
43 "uniform lowp vec4 "+Rendering::FogShaderIncludes::FogColourName+
";\n"
44 "uniform sampler2D "+GlowmapName+
";\n";
46 const std::string _vertexCode =
47 FOG_VERTEX_SHADER_FUNCTIONS
48 "void main(void) { \n"
49 "DestinationUV = mix(MinUVRange, MaxUVRange, UV);\n"
50 "DestinationUV2 = UV2;\n"
51 "highp vec3 unpackedPosition = mix(MinPosRange.xyz, MaxPosRange.xyz, Position.xyz);\n"
52 "ColorVarying.rgb = (LightColorMatrix * vec4(fract(Position.w * LightDotUnpack), 1.0)).rgb;\n"
53 "ColorVarying.a = CalcHeightFogDensity(unpackedPosition);\n"
54 "gl_Position = UnpackModelViewProjectionMatrix * vec4(Position.rgb, 1.0);\n"
57 const std::string _fragmentPunchThroughCode =
58 "void main(void) { \n"
59 "highp vec4 col = " TEXTURE2D(Diffuse, DestinationUV)
"; \n"
60 "if(col.w<" EEGEO_ALPHA_TEST_VALUE
") discard; \n"
61 "gl_FragColor.rgb = col.rgb * ColorVarying.rgb; \n"
62 "gl_FragColor.a = 1.0;\n"
65 const std::string _fragmentCode =
66 "void main(void) { \n"
67 "lowp vec3 diffuse = " TEXTURE2D(Diffuse, DestinationUV)
".rgb;\n"
68 "lowp vec3 dayColour = diffuse * ColorVarying.rgb;\n"
69 "lowp float luma = dot(diffuse, vec3(0.3, 0.59, 0.11));\n"
70 "lowp vec3 greyscale = vec3(luma, luma, luma);\n"
71 "lowp vec3 glow = "+GlowmapColourName+
" * " TEXTURE2D(Glowmap, DestinationUV2)
".rgb;\n"
72 "lowp vec3 desatDiffuse = mix(greyscale, diffuse, 0.2);\n"
73 "lowp vec3 nightColour = desatDiffuse * (glow + "+AmbientColourName+
");\n"
74 "gl_FragColor.rgb = mix(mix(dayColour, nightColour, "+GlowmapParamName+
"), FogColour.rgb, ColorVarying.a); \n"
75 "gl_FragColor.a = 1.0;\n"
86 PackedDiffuseShaderCode::_vertexDecls + LightmappedPackedDiffuseShaderCode::_vertexDecls + LightmappedPackedDiffuseShaderCode::_vertexCode,
87 PackedDiffuseShaderCode::_fragmentDecls + LightmappedPackedDiffuseShaderCode::_fragmentDecls + LightmappedPackedDiffuseShaderCode::_fragmentCode
91 const GLuint GetLightmapSamplerId()
const {
return 1; }
95 Base::FogShaderOld::SetPerMaterialRenderState(m_fogShaderUniforms, fogUniformValues);
98 void SetLightmapColour(
const v3& color)
const
100 SetUniformV3(color, m_glowMapColourUniformLocation);
103 void SetLightmapIntensity(
const float intensity)
const
105 SetUniformFloat(intensity, m_glowMapParamUniformLocation);
108 void SetAmbientColor(
const v3& color)
const
110 SetUniformV3(color, m_ambientUniformLocation);
115 SetUniformV4(min, m_minPosRangeUniformLocation);
116 SetUniformV4(max, m_maxPosRangeUniformLocation);
119 void SetCameraRelativeOrigin(
const Eegeo::v3& cameraRelativeOrigin)
const
121 SetUniformV3(cameraRelativeOrigin, m_cameraRelativeModelOriginUniformLocation);
128 SetUniformTextureSampler(glState, GetDiffuseSamplerId(), m_diffuseTextureSamplerUniformLocation);
129 SetUniformTextureSampler(glState, GetLightmapSamplerId(), m_glowMapTextureSamplerUniformLocation);
131 const GLfloat lightDotUnpack[] = {1.f, 32.f, 1024.f};
132 SetUniformV3(lightDotUnpack, m_lightDotUnpackUniformLocation);
139 m_glowMapColourUniformLocation = GetUniformLocation(LightmappedPackedDiffuseShaderCode::GlowmapColourName);
140 m_glowMapParamUniformLocation = GetUniformLocation(LightmappedPackedDiffuseShaderCode::GlowmapParamName);
142 m_diffuseTextureSamplerUniformLocation = GetUniformLocation(PackedDiffuseShaderCode::DiffuseName);
143 m_glowMapTextureSamplerUniformLocation = GetUniformLocation(LightmappedPackedDiffuseShaderCode::GlowmapName);
145 m_lightDotUnpackUniformLocation = GetUniformLocation(PackedDiffuseShaderCode::LightDotUnpackName);
146 m_ambientUniformLocation = GetUniformLocation(LightmappedPackedDiffuseShaderCode::AmbientColourName);
148 m_cameraRelativeModelOriginUniformLocation = GetUniformLocation(Eegeo::Rendering::FogShaderIncludes::CameraRelativeModelOriginName);
150 m_minPosRangeUniformLocation = GetUniformLocation(LightmappedPackedDiffuseShaderCode::MinPosRangeName);
151 m_maxPosRangeUniformLocation = GetUniformLocation(LightmappedPackedDiffuseShaderCode::MaxPosRangeName);
153 m_fogShaderUniforms.DetermineUniformsFromShader(
this);
157 GLuint m_glowMapColourUniformLocation;
158 GLuint m_glowMapParamUniformLocation;
159 GLuint m_diffuseTextureSamplerUniformLocation;
160 GLuint m_glowMapTextureSamplerUniformLocation;
161 GLuint m_lightDotUnpackUniformLocation;
162 GLuint m_ambientUniformLocation;
163 GLuint m_minPosRangeUniformLocation;
164 GLuint m_maxPosRangeUniformLocation;
165 GLuint m_cameraRelativeModelOriginUniformLocation;