9 #include "VectorMath.h"
18 namespace WeatherOverlayShaderCode
20 const std::string PositionName =
"Position";
21 const std::string UVName =
"UV";
22 const std::string DiffuseName =
"Diffuse";
23 const std::string LayerAlphasName =
"LayerAlphas";
24 const std::string UvOffsetAndScaleLayerOne =
"UvOffsetAndScaleLayerOne";
25 const std::string UvOffsetAndScaleLayerTwo =
"UvOffsetAndScaleLayerTwo";
28 const std::string _vertexDecls =
29 "attribute lowp vec2 "+PositionName+
";\n"
30 "attribute lowp vec2 "+UVName+
";\n"
31 "varying mediump vec2 DestUvLayerOne;\n"
32 "varying mediump vec2 DestUvLayerTwo;\n"
33 "uniform mediump vec4 "+UvOffsetAndScaleLayerOne+
";\n"
34 "uniform mediump vec4 "+UvOffsetAndScaleLayerTwo+
";\n";
36 const std::string _fragmentDecls =
37 "varying mediump vec2 DestUvLayerOne;\n"
38 "varying mediump vec2 DestUvLayerTwo;\n"
39 "uniform sampler2D "+DiffuseName+
";\n"
40 "uniform lowp vec2 "+LayerAlphasName+
";\n";
43 const std::string _vertexCode =
46 "DestUvLayerOne = UvOffsetAndScaleLayerOne.xy + (UV.xy * UvOffsetAndScaleLayerOne.zw);\n"
47 "DestUvLayerTwo = UvOffsetAndScaleLayerTwo.xy + (UV.xy * UvOffsetAndScaleLayerTwo.zw);\n"
48 "gl_Position = vec4(Position.xy, 0.0, 1.0);\n"
51 const std::string _fragmentCode =
54 "lowp vec3 layerOne = texture2D(Diffuse, DestUvLayerOne).rgb*LayerAlphas.x;\n"
55 "lowp vec3 layerTwo = texture2D(Diffuse, DestUvLayerTwo).rgb*LayerAlphas.y;\n"
56 "gl_FragColor.rgb = layerOne + layerTwo;\n"
57 "gl_FragColor.a = 1.0;\n"
68 WeatherOverlayShaderCode::_vertexDecls + WeatherOverlayShaderCode::_vertexCode,
69 WeatherOverlayShaderCode::_fragmentDecls + WeatherOverlayShaderCode::_fragmentCode
73 const GLuint GetDiffuseSamplerId()
const {
return 0; }
74 void SetMVP(
const m44& mvp)
const
79 void SetLayerAlphas(
Eegeo::v2 layerAlphas)
81 SetUniformV2(layerAlphas, m_layerAlphasUniformLocation);
84 void SetUVOffsetAndScaleLayerUniforms(
Eegeo::v4 UvOffsetAndScaleLayerOne,
Eegeo::v4 UvOffsetAndScaleLayerTwo)
86 SetUniformV4(UvOffsetAndScaleLayerOne, m_uvOffsetAndScaleLayerOneUniformLocation);
87 SetUniformV4(UvOffsetAndScaleLayerTwo, m_uvOffsetAndScaleLayerTwoUniformLocation);
93 SetUniformTextureSampler(glState, GetDiffuseSamplerId(), m_diffuseTextureSamplerUniformLocation);
97 WeatherOverlayShader(
const TShaderId shaderId,
const std::string& vertexShaderCode,
const std::string& fragmentShaderCode) :
Shader(shaderId)
99 CompileProgram(vertexShaderCode, fragmentShaderCode);
101 m_diffuseTextureSamplerUniformLocation = GetUniformLocation(WeatherOverlayShaderCode::DiffuseName);
102 m_layerAlphasUniformLocation = GetUniformLocation(WeatherOverlayShaderCode::LayerAlphasName);
103 m_uvOffsetAndScaleLayerOneUniformLocation = GetUniformLocation(WeatherOverlayShaderCode::UvOffsetAndScaleLayerOne);
104 m_uvOffsetAndScaleLayerTwoUniformLocation = GetUniformLocation(WeatherOverlayShaderCode::UvOffsetAndScaleLayerTwo);
108 GLuint m_diffuseTextureSamplerUniformLocation;
109 GLuint m_layerAlphasUniformLocation ;
110 GLuint m_uvOffsetAndScaleLayerOneUniformLocation;
111 GLuint m_uvOffsetAndScaleLayerTwoUniformLocation;