5 #include "PackedDiffuseTransitionShader.h"
6 #include "ShaderMacros.h"
7 #include "FogShaderIncludes.h"
8 #include "VectorMath.h"
10 #include "LightmappedPackedDiffuseShader.h"
19 namespace LightmappedPackedDiffuseTransitionShaderCode
21 const std::string UV2Name =
"UV2";
22 const std::string GlowmapName =
"Glowmap";
23 const std::string GlowmapColourName =
"GlowmapColour";
24 const std::string GlowmapParamName =
"GlowmapParam";
25 const std::string AmbientColourName =
"AmbientColour";
27 const std::string _vertexDecls =
28 "attribute lowp vec2 "+UV2Name+
";\n"
29 "varying highp vec2 DestinationUV2;\n";
31 const std::string _fragmentDecls =
32 "varying highp vec2 DestinationUV2;\n"
33 "uniform lowp float "+GlowmapParamName+
";\n"
34 "uniform lowp vec3 "+GlowmapColourName+
";\n"
35 "uniform sampler2D "+GlowmapName+
";\n"
36 "uniform lowp vec3 "+AmbientColourName+
";\n";
38 const std::string _vertexCode =
39 FOG_VERTEX_SHADER_FUNCTIONS
40 "void main(void) { \n"
41 "DestinationUV = mix(MinUVRange, MaxUVRange, UV);\n"
42 "DestinationUV2 = UV2;\n"
43 "highp vec3 unpackedPosition = mix(MinPosRange.xyz, MaxPosRange.xyz, Position.xyz);\n"
44 "ColorVarying.rgb = (LightColorMatrix * vec4(fract(Position.w * LightDotUnpack), 1.0)).rgb;\n"
45 "ColorVarying.a = CalcHeightFogDensity(unpackedPosition);\n"
46 "gl_Position = UnpackModelViewProjectionMatrix * vec4(Position.rgb, 1.0);\n"
49 const std::string _fragmentPunchThroughCode =
50 "void main(void) { \n"
51 "highp vec4 col = " TEXTURE2D(Diffuse, DestinationUV)
"; \n"
52 "if(col.w<" EEGEO_ALPHA_TEST_VALUE
") discard; \n"
53 "gl_FragColor.rgb = col.rgb * ColorVarying.rgb; \n"
54 "gl_FragColor.a = 1.0;\n"
57 const std::string _fragmentCode =
58 "void main(void) { \n"
59 "highp vec3 fromColor = " TEXTURE2D(DiffuseFrom, DestinationUV)
".rgb; \n"
60 "highp vec3 toColor = " TEXTURE2D(DiffuseTo, DestinationUV)
".rgb; \n"
61 "lowp vec3 diffuse = mix(fromColor, toColor, LerpParam);\n"
62 "lowp vec3 dayColour = diffuse * ColorVarying.rgb;\n"
63 "lowp float luma = dot(diffuse, vec3(0.3, 0.59, 0.11));\n"
64 "lowp vec3 greyscale = vec3(luma, luma, luma);\n"
65 "lowp vec3 glow = "+GlowmapColourName+
" * " TEXTURE2D(Glowmap, DestinationUV2)
".rgb;\n"
66 "lowp vec3 desatDiffuse = mix(greyscale, diffuse, 0.2);\n"
67 "lowp vec3 nightColour = desatDiffuse * (glow + "+AmbientColourName+
");\n"
68 "gl_FragColor.rgb = mix(mix(dayColour, nightColour, "+GlowmapParamName+
"), FogColour.rgb, ColorVarying.a); \n"
69 "gl_FragColor.a = 1.0;\n"
80 PackedDiffuseTransitionShaderCode::_vertexDecls + LightmappedPackedDiffuseTransitionShaderCode::_vertexDecls + LightmappedPackedDiffuseTransitionShaderCode::_vertexCode,
81 PackedDiffuseTransitionShaderCode::_fragmentDecls + LightmappedPackedDiffuseTransitionShaderCode::_fragmentDecls + LightmappedPackedDiffuseTransitionShaderCode::_fragmentCode
85 const GLuint GetLightmapSamplerId()
const {
return 2; }
87 void SetLightmapColour(
const v3& color)
const
89 SetUniformV3(color, m_glowMapColourUniformLocation);
92 void SetLightmapIntensity(
const float intensity)
const
94 SetUniformFloat(intensity, m_glowMapParamUniformLocation);
97 void SetAmbientColor(
const v3& color)
const
99 SetUniformV3(color, m_ambientUniformLocation);
106 SetUniformTextureSampler(glState, GetFromDiffuseSamplerId(), m_fromDiffuseTextureSamplerUniformLocation);
107 SetUniformTextureSampler(glState, GetToDiffuseSamplerId(), m_toDiffuseTextureSamplerUniformLocation);
108 SetUniformTextureSampler(glState, GetLightmapSamplerId(), m_glowMapTextureSamplerUniformLocation);
110 const GLfloat lightDotUnpack[] = {1.f, 32.f, 1024.f};
111 SetUniformV3(lightDotUnpack, m_lightDotUnpackUniformLocation);
118 m_glowMapColourUniformLocation = GetUniformLocation(LightmappedPackedDiffuseShaderCode::GlowmapColourName);
119 m_glowMapParamUniformLocation = GetUniformLocation(LightmappedPackedDiffuseShaderCode::GlowmapParamName);
121 m_glowMapTextureSamplerUniformLocation = GetUniformLocation(LightmappedPackedDiffuseShaderCode::GlowmapName);
123 m_lightDotUnpackUniformLocation = GetUniformLocation(PackedDiffuseShaderCode::LightDotUnpackName);
124 m_ambientUniformLocation = GetUniformLocation(LightmappedPackedDiffuseShaderCode::AmbientColourName);
128 GLuint m_glowMapColourUniformLocation;
129 GLuint m_glowMapParamUniformLocation;
130 GLuint m_glowMapTextureSamplerUniformLocation;
131 GLuint m_lightDotUnpackUniformLocation;
132 GLuint m_ambientUniformLocation;