8 #include "VectorMath.h"
16 namespace BlueSphereShaderCode
18 const std::string PositionName =
"Position";
19 const std::string UVName =
"UV";
20 const std::string ModelViewProjectionMatrixName =
"ModelViewProjectionMatrix";
22 const std::string _vertexDecls =
23 "attribute highp vec3 "+PositionName+
";\n"
24 "attribute mediump vec2 "+UVName+
";\n"
25 "varying mediump vec2 DestinationUV;\n"
26 "uniform highp mat4 "+ModelViewProjectionMatrixName+
";\n";
28 const std::string DiffuseDayName =
"DiffuseDay";
29 const std::string DiffuseNightName =
"DiffuseNight";
30 const std::string TextureLerpValueName =
"TextureLerpValue";
31 const std::string ColorName =
"ColorName";
32 const std::string ColorLerpValueName =
"ColorLerpValue";
34 const std::string _fragmentDecls =
35 "varying mediump vec2 DestinationUV;\n"
36 "uniform sampler2D "+DiffuseDayName+
";\n"
37 "uniform sampler2D "+DiffuseNightName+
";\n"
38 "uniform lowp float "+TextureLerpValueName+
";\n"
39 "uniform lowp vec4 "+ColorName+
";\n"
40 "uniform lowp float "+ColorLerpValueName+
";\n";
42 const std::string _vertexCode =
"void main(void) { \n"
43 "DestinationUV = UV;\n"
44 "gl_Position = ModelViewProjectionMatrix * vec4(Position.xyz, 1.0);\n"
47 const std::string _fragmentCode =
"void main(void) { \n"
48 "highp vec4 textureColor = mix(texture2D("+DiffuseDayName+
", DestinationUV.xy), texture2D("+DiffuseNightName+
", DestinationUV.xy), "+TextureLerpValueName+
");\n"
49 "gl_FragColor = mix(textureColor, "+ColorName+
", "+ColorLerpValueName+
");\n"
59 BlueSphereShaderCode::_vertexDecls + BlueSphereShaderCode::_vertexCode,
60 BlueSphereShaderCode::_fragmentDecls + BlueSphereShaderCode::_fragmentCode);
63 const GLuint GetDiffuseDaySamplerId()
const {
return 0; }
64 const GLuint GetDiffuseNightSamplerId()
const {
return 1; }
68 bool transpose =
false;
69 SetUniformM44(mvp, m_mvpUniformLocation, transpose);
72 void SetColor(
const Eegeo::v4& color)
const
74 SetUniformV4(color, m_colorUniformLocation);
77 void SetColorLerpValue(
float colorLerpValue)
const
79 SetUniformFloat(colorLerpValue, m_colorLerpValueLocation);
82 void SetTextureLerpValue(
float textureLerpValue)
const
84 SetUniformFloat(textureLerpValue, m_textureLerpValueLocation);
90 SetUniformTextureSampler(glState, GetDiffuseDaySamplerId(), m_diffuseDayTextureSamplerUniformLocation);
91 SetUniformTextureSampler(glState, GetDiffuseNightSamplerId(), m_diffuseNightTextureSamplerUniformLocation);
95 BlueSphereShader(
const Eegeo::Rendering::TShaderId shaderId,
const std::string& vertexShaderCode,
const std::string& fragmentShaderCode) : Shader(shaderId)
97 CompileProgram(vertexShaderCode, fragmentShaderCode);
99 m_mvpUniformLocation = GetUniformLocation(BlueSphereShaderCode::ModelViewProjectionMatrixName);
100 m_colorUniformLocation = GetUniformLocation(BlueSphereShaderCode::ColorName);
101 m_diffuseDayTextureSamplerUniformLocation = GetUniformLocation(BlueSphereShaderCode::DiffuseDayName);
102 m_diffuseNightTextureSamplerUniformLocation = GetUniformLocation(BlueSphereShaderCode::DiffuseNightName);
103 m_colorLerpValueLocation = GetUniformLocation(BlueSphereShaderCode::ColorLerpValueName);
104 m_textureLerpValueLocation = GetUniformLocation(BlueSphereShaderCode::TextureLerpValueName);
108 GLuint m_mvpUniformLocation;
109 GLuint m_colorUniformLocation;
110 GLuint m_colorLerpValueLocation;
111 GLuint m_diffuseDayTextureSamplerUniformLocation;
112 GLuint m_diffuseNightTextureSamplerUniformLocation;
113 GLuint m_textureLerpValueLocation;