From 68e2df8fc2e02dc0223ebe271ac90a48726936b9 Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Mon, 24 Nov 2014 14:35:42 -0800 Subject: [PATCH] add a emissive parameter value to the lightmap shaders --- interface/resources/shaders/model.vert | 2 +- .../resources/shaders/model_lightmap.frag | 5 +++-- .../resources/shaders/model_lightmap.vert | 4 ++-- .../shaders/model_lightmap_normal_map.frag | 5 +++-- .../model_lightmap_normal_specular_map.frag | 5 +++-- .../shaders/model_lightmap_specular_map.frag | 5 +++-- .../resources/shaders/model_normal_map.vert | 2 +- interface/src/gpu/Batch.h | 2 ++ interface/src/gpu/GLBackend.cpp | 18 ++++++++++++++++++ interface/src/gpu/GLBackend.h | 1 + interface/src/renderer/GeometryCache.cpp | 2 ++ interface/src/renderer/Model.cpp | 5 +++++ interface/src/renderer/Model.h | 1 + 13 files changed, 45 insertions(+), 12 deletions(-) diff --git a/interface/resources/shaders/model.vert b/interface/resources/shaders/model.vert index 5ae6ea1cb6..bb0cb32d05 100644 --- a/interface/resources/shaders/model.vert +++ b/interface/resources/shaders/model.vert @@ -26,7 +26,7 @@ void main(void) { gl_FrontColor = gl_Color * gl_FrontMaterial.diffuse; // and the texture coordinates - gl_TexCoord[0] = texcoordMatrices[0] * vec4(gl_MultiTexCoord0.xy, 0.f, 1.f); + gl_TexCoord[0] = texcoordMatrices[0] * vec4(gl_MultiTexCoord0.xy, 0.0, 1.0); // use standard pipeline transform gl_Position = ftransform(); diff --git a/interface/resources/shaders/model_lightmap.frag b/interface/resources/shaders/model_lightmap.frag index 67d9cd0218..b93f0abc6f 100644 --- a/interface/resources/shaders/model_lightmap.frag +++ b/interface/resources/shaders/model_lightmap.frag @@ -14,8 +14,9 @@ // the diffuse texture uniform sampler2D diffuseMap; -// the emissive map texture +// the emissive map texture and parameters uniform sampler2D emissiveMap; +uniform vec2 emissiveParams; // the alpha threshold uniform float alphaThreshold; @@ -30,7 +31,7 @@ void main(void) { // set the diffuse, normal, specular data vec4 diffuse = texture2D(diffuseMap, gl_TexCoord[0].st); vec4 emissive = texture2D(emissiveMap, interpolatedTexcoord1.st); - gl_FragData[0] = vec4(gl_Color.rgb * diffuse.rgb * (vec3(0.1) + 4 * emissive.rgb), mix(gl_Color.a, 1.0 - gl_Color.a, step(diffuse.a, alphaThreshold))); + gl_FragData[0] = vec4(gl_Color.rgb * diffuse.rgb * (vec3(emissiveParams.x) + emissiveParams.y * emissive.rgb), mix(gl_Color.a, 1.0 - gl_Color.a, step(diffuse.a, alphaThreshold))); gl_FragData[1] = normalize(normal) * 0.5 + vec4(0.5, 0.5, 0.5, 1.0); gl_FragData[2] = vec4(gl_FrontMaterial.specular.rgb, gl_FrontMaterial.shininess / 128.0); } diff --git a/interface/resources/shaders/model_lightmap.vert b/interface/resources/shaders/model_lightmap.vert index 021db11796..ff1b07e503 100644 --- a/interface/resources/shaders/model_lightmap.vert +++ b/interface/resources/shaders/model_lightmap.vert @@ -31,8 +31,8 @@ void main(void) { gl_FrontColor = gl_Color * gl_FrontMaterial.diffuse; // and the texture coordinates - gl_TexCoord[0] = texcoordMatrices[0] * vec4(gl_MultiTexCoord0.xy, 0.f, 1.f); - interpolatedTexcoord1 = vec2(texcoordMatrices[1] * vec4(texcoord1.xy, 0.f, 1.f)).xy; + gl_TexCoord[0] = texcoordMatrices[0] * vec4(gl_MultiTexCoord0.xy, 0.0, 1.0); + interpolatedTexcoord1 = vec2(texcoordMatrices[1] * vec4(texcoord1.xy, 0.0, 1.0)).xy; // use standard pipeline transform gl_Position = ftransform(); diff --git a/interface/resources/shaders/model_lightmap_normal_map.frag b/interface/resources/shaders/model_lightmap_normal_map.frag index 6d3e3aa861..475126eb0c 100644 --- a/interface/resources/shaders/model_lightmap_normal_map.frag +++ b/interface/resources/shaders/model_lightmap_normal_map.frag @@ -17,8 +17,9 @@ uniform sampler2D diffuseMap; // the normal map texture uniform sampler2D normalMap; -// the emissive map texture +// the emissive map texture and parameters uniform sampler2D emissiveMap; +uniform vec2 emissiveParams; // the alpha threshold uniform float alphaThreshold; @@ -43,7 +44,7 @@ void main(void) { // set the diffuse, normal, specular data vec4 diffuse = texture2D(diffuseMap, gl_TexCoord[0].st); vec4 emissive = texture2D(emissiveMap, interpolatedTexcoord1.st); - gl_FragData[0] = vec4(gl_Color.rgb * diffuse.rgb * (vec3(0.1) + 4 * emissive.rgb), mix(gl_Color.a, 1.0 - gl_Color.a, step(diffuse.a, alphaThreshold))); + gl_FragData[0] = vec4(gl_Color.rgb * diffuse.rgb * (vec3(emissiveParams.x) + emissiveParams.y * emissive.rgb), mix(gl_Color.a, 1.0 - gl_Color.a, step(diffuse.a, alphaThreshold))); gl_FragData[1] = viewNormal + vec4(0.5, 0.5, 0.5, 1.0); gl_FragData[2] = vec4(gl_FrontMaterial.specular.rgb, gl_FrontMaterial.shininess / 128.0); } diff --git a/interface/resources/shaders/model_lightmap_normal_specular_map.frag b/interface/resources/shaders/model_lightmap_normal_specular_map.frag index 89333bbcef..4d0d29ed71 100644 --- a/interface/resources/shaders/model_lightmap_normal_specular_map.frag +++ b/interface/resources/shaders/model_lightmap_normal_specular_map.frag @@ -14,8 +14,9 @@ // the diffuse texture uniform sampler2D diffuseMap; -// the emissive map texture +// the emissive map texture and parameters uniform sampler2D emissiveMap; +uniform vec2 emissiveParams; // the normal map texture uniform sampler2D normalMap; @@ -46,7 +47,7 @@ void main(void) { // set the diffuse, normal, specular data vec4 diffuse = texture2D(diffuseMap, gl_TexCoord[0].st); vec4 emissive = texture2D(emissiveMap, interpolatedTexcoord1.st); - gl_FragData[0] = vec4(gl_Color.rgb * diffuse.rgb * (vec3(0.1) + 4 * emissive.rgb), mix(gl_Color.a, 1.0 - gl_Color.a, step(diffuse.a, alphaThreshold))); + gl_FragData[0] = vec4(gl_Color.rgb * diffuse.rgb * (vec3(emissiveParams.x) + emissiveParams.y * emissive.rgb), mix(gl_Color.a, 1.0 - gl_Color.a, step(diffuse.a, alphaThreshold))); gl_FragData[1] = viewNormal + vec4(0.5, 0.5, 0.5, 1.0); gl_FragData[2] = vec4(gl_FrontMaterial.specular.rgb * texture2D(specularMap, gl_TexCoord[0].st).rgb, gl_FrontMaterial.shininess / 128.0); diff --git a/interface/resources/shaders/model_lightmap_specular_map.frag b/interface/resources/shaders/model_lightmap_specular_map.frag index 3526ecdf9c..c616764cae 100644 --- a/interface/resources/shaders/model_lightmap_specular_map.frag +++ b/interface/resources/shaders/model_lightmap_specular_map.frag @@ -14,8 +14,9 @@ // the diffuse texture uniform sampler2D diffuseMap; -// the emissive map texture +// the emissive map texture and parameters uniform sampler2D emissiveMap; +uniform vec2 emissiveParams; // the specular texture uniform sampler2D specularMap; @@ -32,7 +33,7 @@ void main(void) { // set the diffuse, normal, specular data vec4 diffuse = texture2D(diffuseMap, gl_TexCoord[0].st); vec4 emissive = texture2D(emissiveMap, interpolatedTexcoord1.st); - gl_FragData[0] = vec4(gl_Color.rgb * diffuse.rgb * (vec3(0.1) + 4 * emissive.rgb), mix(gl_Color.a, 1.0 - gl_Color.a, step(diffuse.a, alphaThreshold))); + gl_FragData[0] = vec4(gl_Color.rgb * diffuse.rgb * (vec3(emissiveParams.x) + emissiveParams.y * emissive.rgb), mix(gl_Color.a, 1.0 - gl_Color.a, step(diffuse.a, alphaThreshold))); gl_FragData[1] = normalize(normal) * 0.5 + vec4(0.5, 0.5, 0.5, 1.0); gl_FragData[2] = vec4(gl_FrontMaterial.specular.rgb * texture2D(specularMap, gl_TexCoord[0].st).rgb, gl_FrontMaterial.shininess / 128.0); diff --git a/interface/resources/shaders/model_normal_map.vert b/interface/resources/shaders/model_normal_map.vert index 2e98b8c4fc..3d91a75c63 100644 --- a/interface/resources/shaders/model_normal_map.vert +++ b/interface/resources/shaders/model_normal_map.vert @@ -33,7 +33,7 @@ void main(void) { gl_FrontColor = gl_Color * gl_FrontMaterial.diffuse; // and the texture coordinates - gl_TexCoord[0] = texcoordMatrices[0] * vec4(gl_MultiTexCoord0.xy, 0.f, 1.f); + gl_TexCoord[0] = texcoordMatrices[0] * vec4(gl_MultiTexCoord0.xy, 0.0, 1.0); // use standard pipeline transform gl_Position = ftransform(); diff --git a/interface/src/gpu/Batch.h b/interface/src/gpu/Batch.h index d006473b50..5304740dd3 100644 --- a/interface/src/gpu/Batch.h +++ b/interface/src/gpu/Batch.h @@ -116,6 +116,7 @@ public: void _glUseProgram(GLuint program); void _glUniform1f(GLint location, GLfloat v0); + void _glUniform2f(GLint location, GLfloat v0, GLfloat v1); void _glUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value); void _glMatrixMode(GLenum mode); @@ -185,6 +186,7 @@ public: COMMAND_glUseProgram, COMMAND_glUniform1f, + COMMAND_glUniform2f, COMMAND_glUniformMatrix4fv, COMMAND_glMatrixMode, diff --git a/interface/src/gpu/GLBackend.cpp b/interface/src/gpu/GLBackend.cpp index d6e1a011a3..1f8e7bf99f 100644 --- a/interface/src/gpu/GLBackend.cpp +++ b/interface/src/gpu/GLBackend.cpp @@ -53,6 +53,7 @@ GLBackend::CommandCall GLBackend::_commandCalls[Batch::NUM_COMMANDS] = (&::gpu::GLBackend::do_glUseProgram), (&::gpu::GLBackend::do_glUniform1f), + (&::gpu::GLBackend::do_glUniform2f), (&::gpu::GLBackend::do_glUniformMatrix4fv), (&::gpu::GLBackend::do_glMatrixMode), @@ -691,6 +692,23 @@ void GLBackend::do_glUniform1f(Batch& batch, uint32 paramOffset) { CHECK_GL_ERROR(); } +void Batch::_glUniform2f(GLint location, GLfloat v0, GLfloat v1) { + ADD_COMMAND_GL(glUniform2f); + + _params.push_back(v1); + _params.push_back(v0); + _params.push_back(location); + + DO_IT_NOW(_glUniform2f, 1); +} +void GLBackend::do_glUniform2f(Batch& batch, uint32 paramOffset) { + glUniform2f( + batch._params[paramOffset + 2]._int, + batch._params[paramOffset + 1]._float, + batch._params[paramOffset + 0]._float); + CHECK_GL_ERROR(); +} + void Batch::_glUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value) { ADD_COMMAND_GL(glUniformMatrix4fv); diff --git a/interface/src/gpu/GLBackend.h b/interface/src/gpu/GLBackend.h index 71869229fd..0e4b38d89e 100644 --- a/interface/src/gpu/GLBackend.h +++ b/interface/src/gpu/GLBackend.h @@ -147,6 +147,7 @@ protected: void do_glUseProgram(Batch& batch, uint32 paramOffset); void do_glUniform1f(Batch& batch, uint32 paramOffset); + void do_glUniform2f(Batch& batch, uint32 paramOffset); void do_glUniformMatrix4fv(Batch& batch, uint32 paramOffset); void do_glMatrixMode(Batch& batch, uint32 paramOffset); diff --git a/interface/src/renderer/GeometryCache.cpp b/interface/src/renderer/GeometryCache.cpp index 04ff7bdecd..ab27678546 100644 --- a/interface/src/renderer/GeometryCache.cpp +++ b/interface/src/renderer/GeometryCache.cpp @@ -830,6 +830,8 @@ void GeometryReader::run() { } try { QMetaObject::invokeMethod(geometry.data(), "setGeometry", Q_ARG(const FBXGeometry&, + + _url.path().toLower().endsWith(".svo") ? readSVO(_reply->readAll()) : readFBX(_reply->readAll(), _mapping))); } catch (const QString& error) { diff --git a/interface/src/renderer/Model.cpp b/interface/src/renderer/Model.cpp index 3f68201386..2c43113b62 100644 --- a/interface/src/renderer/Model.cpp +++ b/interface/src/renderer/Model.cpp @@ -160,6 +160,8 @@ void Model::initProgram(ProgramObject& program, Model::Locations& locations, int locations.texcoordMatrices = program.uniformLocation("texcoordMatrices"); + locations.emissiveParams = program.uniformLocation("emissiveParams"); + program.setUniformValue("diffuseMap", 0); @@ -2378,6 +2380,9 @@ int Model::renderMeshesFromList(QVector& list, gpu::Batch& batch, RenderMod } if (locations->emissiveTextureUnit >= 0) { + assert(locations->emissiveParams >= 0); // we should have the emissiveParams defined in the shader + GLBATCH(glUniform2f)(locations->emissiveParams, 0.1f, 4.0f); + GLBATCH(glActiveTexture)(GL_TEXTURE0 + locations->emissiveTextureUnit); Texture* emissiveMap = networkPart.emissiveTexture.data(); GLBATCH(glBindTexture)(GL_TEXTURE_2D, !emissiveMap ? diff --git a/interface/src/renderer/Model.h b/interface/src/renderer/Model.h index 7a3457423e..d24e4d9f2e 100644 --- a/interface/src/renderer/Model.h +++ b/interface/src/renderer/Model.h @@ -329,6 +329,7 @@ private: int texcoordMatrices; int specularTextureUnit; int emissiveTextureUnit; + int emissiveParams; }; static Locations _locations;