7 #include "VectorMath.h"
9 #include "ShaderMacros.h"
18 namespace FireworksShaderCode
20 const std::string PositionName =
"Position";
21 const std::string UVName =
"UV";
22 const std::string ModelViewProjectionMatrixName =
"ModelViewProjectionMatrix";
23 const std::string ColorName =
"Color";
24 const std::string ColorVaryingName =
"ColorVarying";
25 const std::string UVVaryingName =
"UVVarying";
26 const std::string DiffuseName =
"Diffuse";
28 const std::string _vertexDecls =
29 "attribute highp vec3 "+PositionName+
";\n"
30 "attribute mediump vec2 "+UVName+
";\n"
31 "attribute vec4 "+ColorName+
";\n"
32 "varying lowp vec4 "+ColorVaryingName+
";\n"
33 "varying mediump vec2 "+UVVaryingName+
";\n"
34 "uniform highp mat4 "+ModelViewProjectionMatrixName+
";\n";
36 const std::string _fragmentDecls =
37 "varying lowp vec4 "+ColorVaryingName+
";\n"
38 "varying mediump vec2 "+UVVaryingName+
";\n"
39 "uniform sampler2D "+DiffuseName+
";\n";
41 const std::string _vertexCode =
42 "void main(void) { \n"
43 ""+ColorVaryingName+
" = "+ColorName+
";\n"
44 ""+UVVaryingName+
" = "+UVName+
";\n"
45 "gl_Position = "+ModelViewProjectionMatrixName+
" * vec4(Position.xyz, 1.0);\n"
48 const std::string _fragmentCode =
49 "void main(void) { \n"
50 "lowp vec4 sampleCol = " TEXTURE2D(Diffuse, UVVarying)
".rgba;\n"
51 "gl_FragColor.rgba = (sampleCol.rgba * mix(" + ColorVaryingName +
".rgba, vec4(1,1,1,1), sampleCol.r)) * "+ColorVaryingName+
".a;\n"
63 FireworksShaderCode::_vertexDecls + FireworksShaderCode::_vertexCode,
64 FireworksShaderCode::_fragmentDecls + FireworksShaderCode::_fragmentCode
68 void SetMVP(
const m44& mvp)
const
70 bool transpose =
false;
71 SetUniformM44(mvp, m_mvpUniformLocation, transpose);
74 GLuint GetPositionUniform()
const {
return GetVertexAttributes().GetElement(0).GetLocation(); }
75 GLuint GetUVUniform()
const {
return GetVertexAttributes().GetElement(1).GetLocation(); }
76 GLuint GetColorUniform()
const {
return GetVertexAttributes().GetElement(2).GetLocation(); }
84 FireworksShader(
const TShaderId shaderId,
const std::string& vertexShaderCode,
const std::string& fragmentShaderCode) :
Shader(shaderId)
86 CompileProgram(vertexShaderCode, fragmentShaderCode);
87 m_mvpUniformLocation = GetUniformLocation(FireworksShaderCode::ModelViewProjectionMatrixName);
93 GLuint m_mvpUniformLocation;