From e752edc44ae42d6501b7c35c19a95d9cfe9adb09 Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Tue, 30 Dec 2014 12:35:00 -0800 Subject: [PATCH 1/2] Moving the shaders used in Model.cpp from resources folder into the built-in executable --- .../resources/shaders/model_lightmap.frag | 37 ---- .../resources/shaders/model_lightmap.vert | 40 ---- .../shaders/model_lightmap_normal_map.frag | 50 ----- .../shaders/model_lightmap_normal_map.vert | 46 ----- .../model_lightmap_normal_specular_map.frag | 54 ------ .../shaders/model_lightmap_specular_map.frag | 40 ---- .../resources/shaders/model_normal_map.frag | 43 ----- .../resources/shaders/model_normal_map.vert | 40 ---- .../shaders/model_normal_specular_map.frag | 47 ----- interface/resources/shaders/model_shadow.frag | 17 -- interface/resources/shaders/model_shadow.vert | 17 -- .../resources/shaders/model_specular_map.frag | 33 ---- .../resources/shaders/model_translucent.frag | 20 -- interface/resources/shaders/skin_model.vert | 46 ----- .../shaders/skin_model_normal_map.vert | 54 ------ .../resources/shaders/skin_model_shadow.vert | 30 --- libraries/render-utils/src/Model.cpp | 177 ++++++++---------- 17 files changed, 79 insertions(+), 712 deletions(-) delete mode 100644 interface/resources/shaders/model_lightmap.frag delete mode 100644 interface/resources/shaders/model_lightmap.vert delete mode 100644 interface/resources/shaders/model_lightmap_normal_map.frag delete mode 100644 interface/resources/shaders/model_lightmap_normal_map.vert delete mode 100644 interface/resources/shaders/model_lightmap_normal_specular_map.frag delete mode 100644 interface/resources/shaders/model_lightmap_specular_map.frag delete mode 100644 interface/resources/shaders/model_normal_map.frag delete mode 100644 interface/resources/shaders/model_normal_map.vert delete mode 100644 interface/resources/shaders/model_normal_specular_map.frag delete mode 100644 interface/resources/shaders/model_shadow.frag delete mode 100644 interface/resources/shaders/model_shadow.vert delete mode 100644 interface/resources/shaders/model_specular_map.frag delete mode 100644 interface/resources/shaders/model_translucent.frag delete mode 100644 interface/resources/shaders/skin_model.vert delete mode 100644 interface/resources/shaders/skin_model_normal_map.vert delete mode 100644 interface/resources/shaders/skin_model_shadow.vert diff --git a/interface/resources/shaders/model_lightmap.frag b/interface/resources/shaders/model_lightmap.frag deleted file mode 100644 index 7c352b877e..0000000000 --- a/interface/resources/shaders/model_lightmap.frag +++ /dev/null @@ -1,37 +0,0 @@ -#version 120 - -// -// model_lightmap.frag -// fragment shader -// -// Created by Samuel Gateau on 11/19/14. -// Copyright 2013 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -// the diffuse texture -uniform sampler2D diffuseMap; - -// the emissive map texture and parameters -uniform sampler2D emissiveMap; -uniform vec2 emissiveParams; - -// the alpha threshold -uniform float alphaThreshold; - -// the interpolated normal -varying vec4 normal; - -// the interpolated texcoord1 -varying vec2 interpolatedTexcoord1; - -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, 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, 0.5); - gl_FragData[2] = vec4((vec3(emissiveParams.x) + emissiveParams.y * emissive.rgb), gl_FrontMaterial.shininess / 128.0); -} diff --git a/interface/resources/shaders/model_lightmap.vert b/interface/resources/shaders/model_lightmap.vert deleted file mode 100644 index ff1b07e503..0000000000 --- a/interface/resources/shaders/model_lightmap.vert +++ /dev/null @@ -1,40 +0,0 @@ -#version 120 - -// -// model_lightmap.vert -// vertex shader -// -// Created by Sam Gateau on 11/21/14. -// Copyright 2013 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -const int MAX_TEXCOORDS = 2; - -uniform mat4 texcoordMatrices[MAX_TEXCOORDS]; - -attribute vec2 texcoord1; - -// the interpolated normal -varying vec4 normal; - -// the interpolated texcoord1 -varying vec2 interpolatedTexcoord1; - -void main(void) { - // transform and store the normal for interpolation - normal = normalize(gl_ModelViewMatrix * vec4(gl_Normal, 0.0)); - - // pass along the diffuse color - gl_FrontColor = gl_Color * gl_FrontMaterial.diffuse; - - // and the texture coordinates - 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 deleted file mode 100644 index 475126eb0c..0000000000 --- a/interface/resources/shaders/model_lightmap_normal_map.frag +++ /dev/null @@ -1,50 +0,0 @@ -#version 120 - -// -// model_lightmap_normal_map.frag -// fragment shader -// -// Created by Samuel Gateau on 11/19/14. -// Copyright 2013 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -// the diffuse texture -uniform sampler2D diffuseMap; - -// the normal map texture -uniform sampler2D normalMap; - -// the emissive map texture and parameters -uniform sampler2D emissiveMap; -uniform vec2 emissiveParams; - -// the alpha threshold -uniform float alphaThreshold; - -// the interpolated normal -varying vec4 interpolatedNormal; - -// the interpolated tangent -varying vec4 interpolatedTangent; - -varying vec2 interpolatedTexcoord1; - -void main(void) { - // compute the view normal from the various bits - vec3 normalizedNormal = normalize(vec3(interpolatedNormal)); - vec3 normalizedTangent = normalize(vec3(interpolatedTangent)); - vec3 normalizedBitangent = normalize(cross(normalizedNormal, normalizedTangent)); - vec3 localNormal = vec3(texture2D(normalMap, gl_TexCoord[0].st)) - vec3(0.5, 0.5, 0.5); - vec4 viewNormal = vec4(normalizedTangent * localNormal.x + - normalizedBitangent * localNormal.y + normalizedNormal * localNormal.z, 0.0); - - // 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(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_map.vert b/interface/resources/shaders/model_lightmap_normal_map.vert deleted file mode 100644 index 4faf5688cf..0000000000 --- a/interface/resources/shaders/model_lightmap_normal_map.vert +++ /dev/null @@ -1,46 +0,0 @@ -#version 120 - -// -// model_lightmap_normal_map.vert -// vertex shader -// -// Created by Sam Gateau on 11/21/14. -// Copyright 2013 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -const int MAX_TEXCOORDS = 2; - -uniform mat4 texcoordMatrices[MAX_TEXCOORDS]; - -// the tangent vector -attribute vec3 tangent; - -attribute vec2 texcoord1; - -// the interpolated normal -varying vec4 interpolatedNormal; - -// the interpolated tangent -varying vec4 interpolatedTangent; - -// the interpolated texcoord1 -varying vec2 interpolatedTexcoord1; - -void main(void) { - // transform and store the normal and tangent for interpolation - interpolatedNormal = gl_ModelViewMatrix * vec4(gl_Normal, 0.0); - interpolatedTangent = gl_ModelViewMatrix * vec4(tangent, 0.0); - - // pass along the diffuse color - gl_FrontColor = gl_Color * gl_FrontMaterial.diffuse; - - // and the texture coordinates - 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_specular_map.frag b/interface/resources/shaders/model_lightmap_normal_specular_map.frag deleted file mode 100644 index 4d0d29ed71..0000000000 --- a/interface/resources/shaders/model_lightmap_normal_specular_map.frag +++ /dev/null @@ -1,54 +0,0 @@ -#version 120 - -// -// model_lightmap_normal_specular_map.frag -// fragment shader -// -// Created by Samuel Gateau on 11/19/14. -// Copyright 2014 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -// the diffuse texture -uniform sampler2D diffuseMap; - -// the emissive map texture and parameters -uniform sampler2D emissiveMap; -uniform vec2 emissiveParams; - -// the normal map texture -uniform sampler2D normalMap; - -// the specular map texture -uniform sampler2D specularMap; - -// the alpha threshold -uniform float alphaThreshold; - -// the interpolated normal -varying vec4 interpolatedNormal; - -// the interpolated tangent -varying vec4 interpolatedTangent; - -varying vec2 interpolatedTexcoord1; - -void main(void) { - // compute the view normal from the various bits - vec3 normalizedNormal = normalize(vec3(interpolatedNormal)); - vec3 normalizedTangent = normalize(vec3(interpolatedTangent)); - vec3 normalizedBitangent = normalize(cross(normalizedNormal, normalizedTangent)); - vec3 localNormal = vec3(texture2D(normalMap, gl_TexCoord[0].st)) - vec3(0.5, 0.5, 0.5); - vec4 viewNormal = vec4(normalizedTangent * localNormal.x + - normalizedBitangent * localNormal.y + normalizedNormal * localNormal.z, 0.0); - - // 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(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 deleted file mode 100644 index c616764cae..0000000000 --- a/interface/resources/shaders/model_lightmap_specular_map.frag +++ /dev/null @@ -1,40 +0,0 @@ -#version 120 - -// -// model_lightmap_specular_map.frag -// fragment shader -// -// Created by Samuel Gateau on 11/19/14. -// Copyright 2014 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -// the diffuse texture -uniform sampler2D diffuseMap; - -// the emissive map texture and parameters -uniform sampler2D emissiveMap; -uniform vec2 emissiveParams; - -// the specular texture -uniform sampler2D specularMap; - -// the alpha threshold -uniform float alphaThreshold; - -// the interpolated normal -varying vec4 normal; - -varying vec2 interpolatedTexcoord1; - -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(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.frag b/interface/resources/shaders/model_normal_map.frag deleted file mode 100644 index f5a1047b2b..0000000000 --- a/interface/resources/shaders/model_normal_map.frag +++ /dev/null @@ -1,43 +0,0 @@ -#version 120 - -// -// model_normal_map.frag -// fragment shader -// -// Created by Andrzej Kapolka on 10/29/13. -// Copyright 2013 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -// the diffuse texture -uniform sampler2D diffuseMap; - -// the normal map texture -uniform sampler2D normalMap; - -// the alpha threshold -uniform float alphaThreshold; - -// the interpolated normal -varying vec4 interpolatedNormal; - -// the interpolated tangent -varying vec4 interpolatedTangent; - -void main(void) { - // compute the view normal from the various bits - vec3 normalizedNormal = normalize(vec3(interpolatedNormal)); - vec3 normalizedTangent = normalize(vec3(interpolatedTangent)); - vec3 normalizedBitangent = normalize(cross(normalizedNormal, normalizedTangent)); - vec3 localNormal = vec3(texture2D(normalMap, gl_TexCoord[0].st)) - vec3(0.5, 0.5, 0.5); - vec4 viewNormal = vec4(normalizedTangent * localNormal.x + - normalizedBitangent * localNormal.y + normalizedNormal * localNormal.z, 0.0); - - // set the diffuse, normal, specular data - vec4 diffuse = texture2D(diffuseMap, gl_TexCoord[0].st); - gl_FragData[0] = vec4(gl_Color.rgb * diffuse.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_normal_map.vert b/interface/resources/shaders/model_normal_map.vert deleted file mode 100644 index 3d91a75c63..0000000000 --- a/interface/resources/shaders/model_normal_map.vert +++ /dev/null @@ -1,40 +0,0 @@ -#version 120 - -// -// model.vert -// vertex shader -// -// Created by Andrzej Kapolka on 10/14/13. -// Copyright 2013 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -const int MAX_TEXCOORDS = 2; - -uniform mat4 texcoordMatrices[MAX_TEXCOORDS]; - -// the tangent vector -attribute vec3 tangent; - -// the interpolated normal -varying vec4 interpolatedNormal; - -// the interpolated tangent -varying vec4 interpolatedTangent; - -void main(void) { - // transform and store the normal and tangent for interpolation - interpolatedNormal = gl_ModelViewMatrix * vec4(gl_Normal, 0.0); - interpolatedTangent = gl_ModelViewMatrix * vec4(tangent, 0.0); - - // pass along the diffuse color - gl_FrontColor = gl_Color * gl_FrontMaterial.diffuse; - - // and the texture coordinates - 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_normal_specular_map.frag b/interface/resources/shaders/model_normal_specular_map.frag deleted file mode 100644 index 08321c0017..0000000000 --- a/interface/resources/shaders/model_normal_specular_map.frag +++ /dev/null @@ -1,47 +0,0 @@ -#version 120 - -// -// model_normal_specular_map.frag -// fragment shader -// -// Created by Andrzej Kapolka on 5/6/14. -// Copyright 2014 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -// the diffuse texture -uniform sampler2D diffuseMap; - -// the normal map texture -uniform sampler2D normalMap; - -// the specular map texture -uniform sampler2D specularMap; - -// the alpha threshold -uniform float alphaThreshold; - -// the interpolated normal -varying vec4 interpolatedNormal; - -// the interpolated tangent -varying vec4 interpolatedTangent; - -void main(void) { - // compute the view normal from the various bits - vec3 normalizedNormal = normalize(vec3(interpolatedNormal)); - vec3 normalizedTangent = normalize(vec3(interpolatedTangent)); - vec3 normalizedBitangent = normalize(cross(normalizedNormal, normalizedTangent)); - vec3 localNormal = vec3(texture2D(normalMap, gl_TexCoord[0].st)) - vec3(0.5, 0.5, 0.5); - vec4 viewNormal = vec4(normalizedTangent * localNormal.x + - normalizedBitangent * localNormal.y + normalizedNormal * localNormal.z, 0.0); - - // set the diffuse, normal, specular data - vec4 diffuse = texture2D(diffuseMap, gl_TexCoord[0].st); - gl_FragData[0] = vec4(gl_Color.rgb * diffuse.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_shadow.frag b/interface/resources/shaders/model_shadow.frag deleted file mode 100644 index 567899fd82..0000000000 --- a/interface/resources/shaders/model_shadow.frag +++ /dev/null @@ -1,17 +0,0 @@ -#version 120 - -// -// model_shadow.frag -// fragment shader -// -// Created by Andrzej Kapolka on 3/24/14. -// Copyright 2013 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -void main(void) { - // fixed color for now (we may eventually want to use texture alpha) - gl_FragColor = vec4(1.0, 1.0, 1.0, 0.0); -} diff --git a/interface/resources/shaders/model_shadow.vert b/interface/resources/shaders/model_shadow.vert deleted file mode 100644 index a18f5fcd5d..0000000000 --- a/interface/resources/shaders/model_shadow.vert +++ /dev/null @@ -1,17 +0,0 @@ -#version 120 - -// -// model_shadow.vert -// vertex shader -// -// Created by Andrzej Kapolka on 3/24/14. -// Copyright 2014 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -void main(void) { - // just use standard pipeline transform - gl_Position = ftransform(); -} diff --git a/interface/resources/shaders/model_specular_map.frag b/interface/resources/shaders/model_specular_map.frag deleted file mode 100644 index bcf658dc15..0000000000 --- a/interface/resources/shaders/model_specular_map.frag +++ /dev/null @@ -1,33 +0,0 @@ -#version 120 - -// -// model_specular_map.frag -// fragment shader -// -// Created by Andrzej Kapolka on 5/6/14. -// Copyright 2014 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -// the diffuse texture -uniform sampler2D diffuseMap; - -// the specular texture -uniform sampler2D specularMap; - -// the alpha threshold -uniform float alphaThreshold; - -// the interpolated normal -varying vec4 normal; - -void main(void) { - // set the diffuse, normal, specular data - vec4 diffuse = texture2D(diffuseMap, gl_TexCoord[0].st); - gl_FragData[0] = vec4(gl_Color.rgb * diffuse.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_translucent.frag b/interface/resources/shaders/model_translucent.frag deleted file mode 100644 index dbb640d3b1..0000000000 --- a/interface/resources/shaders/model_translucent.frag +++ /dev/null @@ -1,20 +0,0 @@ -#version 120 - -// -// model_translucent.frag -// fragment shader -// -// Created by Andrzej Kapolka on 9/19/14. -// Copyright 2014 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -// the diffuse texture -uniform sampler2D diffuseMap; - -void main(void) { - // set the diffuse data - gl_FragData[0] = gl_Color * texture2D(diffuseMap, gl_TexCoord[0].st); -} diff --git a/interface/resources/shaders/skin_model.vert b/interface/resources/shaders/skin_model.vert deleted file mode 100644 index fd4dea51bb..0000000000 --- a/interface/resources/shaders/skin_model.vert +++ /dev/null @@ -1,46 +0,0 @@ -#version 120 - -// -// skin_model.vert -// vertex shader -// -// Created by Andrzej Kapolka on 10/14/13. -// Copyright 2013 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -const int MAX_TEXCOORDS = 2; -const int MAX_CLUSTERS = 128; -const int INDICES_PER_VERTEX = 4; - -uniform mat4 clusterMatrices[MAX_CLUSTERS]; -uniform mat4 texcoordMatrices[MAX_TEXCOORDS]; - -attribute vec4 clusterIndices; -attribute vec4 clusterWeights; - -// the interpolated normal -varying vec4 normal; - -void main(void) { - vec4 position = vec4(0.0, 0.0, 0.0, 0.0); - normal = vec4(0.0, 0.0, 0.0, 0.0); - for (int i = 0; i < INDICES_PER_VERTEX; i++) { - mat4 clusterMatrix = clusterMatrices[int(clusterIndices[i])]; - float clusterWeight = clusterWeights[i]; - position += clusterMatrix * gl_Vertex * clusterWeight; - normal += clusterMatrix * vec4(gl_Normal, 0.0) * clusterWeight; - } - - normal = normalize(gl_ModelViewMatrix * normal); - - // pass along the diffuse color - gl_FrontColor = gl_FrontMaterial.diffuse; - - // and the texture coordinates - gl_TexCoord[0] = texcoordMatrices[0] * vec4(gl_MultiTexCoord0.xy, 0.0, 1.0); - - gl_Position = gl_ModelViewProjectionMatrix * position; -} diff --git a/interface/resources/shaders/skin_model_normal_map.vert b/interface/resources/shaders/skin_model_normal_map.vert deleted file mode 100644 index 5814dfc584..0000000000 --- a/interface/resources/shaders/skin_model_normal_map.vert +++ /dev/null @@ -1,54 +0,0 @@ -#version 120 - -// -// skin_model_normal_map.vert -// vertex shader -// -// Created by Andrzej Kapolka on 10/29/13. -// Copyright 2013 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -const int MAX_TEXCOORDS = 2; -const int MAX_CLUSTERS = 128; -const int INDICES_PER_VERTEX = 4; - -uniform mat4 clusterMatrices[MAX_CLUSTERS]; -uniform mat4 texcoordMatrices[MAX_TEXCOORDS]; - -// the tangent vector -attribute vec3 tangent; - -attribute vec4 clusterIndices; -attribute vec4 clusterWeights; - -// the interpolated normal -varying vec4 interpolatedNormal; - -// the interpolated tangent -varying vec4 interpolatedTangent; - -void main(void) { - vec4 interpolatedPosition = vec4(0.0, 0.0, 0.0, 0.0); - interpolatedNormal = vec4(0.0, 0.0, 0.0, 0.0); - interpolatedTangent = vec4(0.0, 0.0, 0.0, 0.0); - for (int i = 0; i < INDICES_PER_VERTEX; i++) { - mat4 clusterMatrix = clusterMatrices[int(clusterIndices[i])]; - float clusterWeight = clusterWeights[i]; - interpolatedPosition += clusterMatrix * gl_Vertex * clusterWeight; - interpolatedNormal += clusterMatrix * vec4(gl_Normal, 0.0) * clusterWeight; - interpolatedTangent += clusterMatrix * vec4(tangent, 0.0) * clusterWeight; - } - interpolatedNormal = gl_ModelViewMatrix * interpolatedNormal; - interpolatedTangent = gl_ModelViewMatrix * interpolatedTangent; - - // pass along the diffuse color - gl_FrontColor = gl_FrontMaterial.diffuse; - - // and the texture coordinates - gl_TexCoord[0] = texcoordMatrices[0] * vec4(gl_MultiTexCoord0.xy, 0.0, 1.0); - - gl_Position = gl_ModelViewProjectionMatrix * interpolatedPosition; -} diff --git a/interface/resources/shaders/skin_model_shadow.vert b/interface/resources/shaders/skin_model_shadow.vert deleted file mode 100644 index 6d9d5ebbf5..0000000000 --- a/interface/resources/shaders/skin_model_shadow.vert +++ /dev/null @@ -1,30 +0,0 @@ -#version 120 - -// -// skin_model_shadow.vert -// vertex shader -// -// Created by Andrzej Kapolka on 3/24/14. -// Copyright 2014 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -const int MAX_CLUSTERS = 128; -const int INDICES_PER_VERTEX = 4; - -uniform mat4 clusterMatrices[MAX_CLUSTERS]; - -attribute vec4 clusterIndices; -attribute vec4 clusterWeights; - -void main(void) { - vec4 position = vec4(0.0, 0.0, 0.0, 0.0); - for (int i = 0; i < INDICES_PER_VERTEX; i++) { - mat4 clusterMatrix = clusterMatrices[int(clusterIndices[i])]; - float clusterWeight = clusterWeights[i]; - position += clusterMatrix * gl_Vertex * clusterWeight; - } - gl_Position = gl_ModelViewProjectionMatrix * position; -} diff --git a/libraries/render-utils/src/Model.cpp b/libraries/render-utils/src/Model.cpp index 680d193aa3..ce121f616c 100644 --- a/libraries/render-utils/src/Model.cpp +++ b/libraries/render-utils/src/Model.cpp @@ -36,7 +36,25 @@ #include "Model.h" #include "model_vert.h" +#include "model_shadow_vert.h" +#include "model_normal_map_vert.h" +#include "model_lightmap_vert.h" +#include "model_lightmap_normal_map_vert.h" +#include "skin_model_vert.h" +#include "skin_model_shadow_vert.h" +#include "skin_model_normal_map_vert.h" + #include "model_frag.h" +#include "model_shadow_frag.h" +#include "model_normal_map_frag.h" +#include "model_normal_specular_map_frag.h" +#include "model_specular_map_frag.h" +#include "model_lightmap_frag.h" +#include "model_lightmap_normal_map_frag.h" +#include "model_lightmap_normal_specular_map_frag.h" +#include "model_lightmap_specular_map_frag.h" +#include "model_translucent_frag.h" + #define GLBATCH( call ) batch._##call //#define GLBATCH( call ) call @@ -237,106 +255,69 @@ void Model::init() { if (!_program.isLinked()) { _program.addShaderFromSourceCode(QGLShader::Vertex, model_vert); _program.addShaderFromSourceCode(QGLShader::Fragment, model_frag); - initProgram(_program, _locations); - _normalMapProgram.addShaderFromSourceFile(QGLShader::Vertex, - PathUtils::resourcesPath() + "shaders/model_normal_map.vert"); - _normalMapProgram.addShaderFromSourceFile(QGLShader::Fragment, - PathUtils::resourcesPath() + "shaders/model_normal_map.frag"); - - initProgram(_normalMapProgram, _normalMapLocations); - - _specularMapProgram.addShaderFromSourceCode(QGLShader::Vertex, model_vert); - _specularMapProgram.addShaderFromSourceFile(QGLShader::Fragment, - PathUtils::resourcesPath() + "shaders/model_specular_map.frag"); - - initProgram(_specularMapProgram, _specularMapLocations); - - _normalSpecularMapProgram.addShaderFromSourceFile(QGLShader::Vertex, - PathUtils::resourcesPath() + "shaders/model_normal_map.vert"); - _normalSpecularMapProgram.addShaderFromSourceFile(QGLShader::Fragment, - PathUtils::resourcesPath() + "shaders/model_normal_specular_map.frag"); - - initProgram(_normalSpecularMapProgram, _normalSpecularMapLocations); - - _translucentProgram.addShaderFromSourceCode(QGLShader::Vertex, model_vert); - _translucentProgram.addShaderFromSourceFile(QGLShader::Fragment, - PathUtils::resourcesPath() + "shaders/model_translucent.frag"); - - initProgram(_translucentProgram, _translucentLocations); - - // Lightmap - _lightmapProgram.addShaderFromSourceFile(QGLShader::Vertex, PathUtils::resourcesPath() + "shaders/model_lightmap.vert"); - _lightmapProgram.addShaderFromSourceFile(QGLShader::Fragment, PathUtils::resourcesPath() + "shaders/model_lightmap.frag"); - - initProgram(_lightmapProgram, _lightmapLocations); - - _lightmapNormalMapProgram.addShaderFromSourceFile(QGLShader::Vertex, - PathUtils::resourcesPath() + "shaders/model_lightmap_normal_map.vert"); - _lightmapNormalMapProgram.addShaderFromSourceFile(QGLShader::Fragment, - PathUtils::resourcesPath() + "shaders/model_lightmap_normal_map.frag"); - - initProgram(_lightmapNormalMapProgram, _lightmapNormalMapLocations); - - _lightmapSpecularMapProgram.addShaderFromSourceFile(QGLShader::Vertex, - PathUtils::resourcesPath() + "shaders/model_lightmap.vert"); - _lightmapSpecularMapProgram.addShaderFromSourceFile(QGLShader::Fragment, - PathUtils::resourcesPath() + "shaders/model_lightmap_specular_map.frag"); - - initProgram(_lightmapSpecularMapProgram, _lightmapSpecularMapLocations); - - _lightmapNormalSpecularMapProgram.addShaderFromSourceFile(QGLShader::Vertex, - PathUtils::resourcesPath() + "shaders/model_lightmap_normal_map.vert"); - _lightmapNormalSpecularMapProgram.addShaderFromSourceFile(QGLShader::Fragment, - PathUtils::resourcesPath() + "shaders/model_lightmap_normal_specular_map.frag"); - - initProgram(_lightmapNormalSpecularMapProgram, _lightmapNormalSpecularMapLocations); - // end lightmap - - - _shadowProgram.addShaderFromSourceFile(QGLShader::Vertex, PathUtils::resourcesPath() + "shaders/model_shadow.vert"); - _shadowProgram.addShaderFromSourceFile(QGLShader::Fragment, - PathUtils::resourcesPath() + "shaders/model_shadow.frag"); - - _skinProgram.addShaderFromSourceFile(QGLShader::Vertex, PathUtils::resourcesPath() + "shaders/skin_model.vert"); - _skinProgram.addShaderFromSourceCode(QGLShader::Fragment, model_frag); - - initSkinProgram(_skinProgram, _skinLocations); - - _skinNormalMapProgram.addShaderFromSourceFile(QGLShader::Vertex, - PathUtils::resourcesPath() + "shaders/skin_model_normal_map.vert"); - _skinNormalMapProgram.addShaderFromSourceFile(QGLShader::Fragment, - PathUtils::resourcesPath() + "shaders/model_normal_map.frag"); - - initSkinProgram(_skinNormalMapProgram, _skinNormalMapLocations); - - _skinSpecularMapProgram.addShaderFromSourceFile(QGLShader::Vertex, - PathUtils::resourcesPath() + "shaders/skin_model.vert"); - _skinSpecularMapProgram.addShaderFromSourceFile(QGLShader::Fragment, - PathUtils::resourcesPath() + "shaders/model_specular_map.frag"); - - initSkinProgram(_skinSpecularMapProgram, _skinSpecularMapLocations); - - _skinNormalSpecularMapProgram.addShaderFromSourceFile(QGLShader::Vertex, - PathUtils::resourcesPath() + "shaders/skin_model_normal_map.vert"); - _skinNormalSpecularMapProgram.addShaderFromSourceFile(QGLShader::Fragment, - PathUtils::resourcesPath() + "shaders/model_normal_specular_map.frag"); - - initSkinProgram(_skinNormalSpecularMapProgram, _skinNormalSpecularMapLocations); - - _skinShadowProgram.addShaderFromSourceFile(QGLShader::Vertex, - PathUtils::resourcesPath() + "shaders/skin_model_shadow.vert"); - _skinShadowProgram.addShaderFromSourceFile(QGLShader::Fragment, - PathUtils::resourcesPath() + "shaders/model_shadow.frag"); - - initSkinProgram(_skinShadowProgram, _skinShadowLocations); - - _skinTranslucentProgram.addShaderFromSourceFile(QGLShader::Vertex, - PathUtils::resourcesPath() + "shaders/skin_model.vert"); - _skinTranslucentProgram.addShaderFromSourceFile(QGLShader::Fragment, - PathUtils::resourcesPath() + "shaders/model_translucent.frag"); - + _normalMapProgram.addShaderFromSourceCode(QGLShader::Vertex, model_normal_map_vert); + _normalMapProgram.addShaderFromSourceCode(QGLShader::Fragment, model_normal_map_frag); + initProgram(_normalMapProgram, _normalMapLocations); + + _specularMapProgram.addShaderFromSourceCode(QGLShader::Vertex, model_vert); + _specularMapProgram.addShaderFromSourceCode(QGLShader::Fragment, model_specular_map_frag); + initProgram(_specularMapProgram, _specularMapLocations); + + _normalSpecularMapProgram.addShaderFromSourceCode(QGLShader::Vertex, model_normal_map_vert); + _normalSpecularMapProgram.addShaderFromSourceCode(QGLShader::Fragment, model_normal_specular_map_frag); + initProgram(_normalSpecularMapProgram, _normalSpecularMapLocations); + + _translucentProgram.addShaderFromSourceCode(QGLShader::Vertex, model_vert); + _translucentProgram.addShaderFromSourceCode(QGLShader::Fragment, model_translucent_frag); + initProgram(_translucentProgram, _translucentLocations); + + // Lightmap + _lightmapProgram.addShaderFromSourceCode(QGLShader::Vertex, model_lightmap_vert); + _lightmapProgram.addShaderFromSourceCode(QGLShader::Fragment, model_lightmap_frag); + initProgram(_lightmapProgram, _lightmapLocations); + + _lightmapNormalMapProgram.addShaderFromSourceCode(QGLShader::Vertex, model_lightmap_normal_map_vert); + _lightmapNormalMapProgram.addShaderFromSourceCode(QGLShader::Fragment, model_lightmap_normal_map_frag); + initProgram(_lightmapNormalMapProgram, _lightmapNormalMapLocations); + + _lightmapSpecularMapProgram.addShaderFromSourceCode(QGLShader::Vertex, model_lightmap_vert); + _lightmapSpecularMapProgram.addShaderFromSourceCode(QGLShader::Fragment, model_lightmap_specular_map_frag); + initProgram(_lightmapSpecularMapProgram, _lightmapSpecularMapLocations); + + _lightmapNormalSpecularMapProgram.addShaderFromSourceCode(QGLShader::Vertex, model_lightmap_normal_map_vert); + _lightmapNormalSpecularMapProgram.addShaderFromSourceCode(QGLShader::Fragment, model_lightmap_normal_specular_map_frag); + initProgram(_lightmapNormalSpecularMapProgram, _lightmapNormalSpecularMapLocations); + // end lightmap + + + _shadowProgram.addShaderFromSourceCode(QGLShader::Vertex, model_shadow_vert); + _shadowProgram.addShaderFromSourceCode(QGLShader::Fragment, model_shadow_frag); + + _skinProgram.addShaderFromSourceCode(QGLShader::Vertex, skin_model_vert); + _skinProgram.addShaderFromSourceCode(QGLShader::Fragment, model_frag); + initSkinProgram(_skinProgram, _skinLocations); + + _skinNormalMapProgram.addShaderFromSourceCode(QGLShader::Vertex, skin_model_normal_map_vert); + _skinNormalMapProgram.addShaderFromSourceCode(QGLShader::Fragment, model_normal_map_frag); + initSkinProgram(_skinNormalMapProgram, _skinNormalMapLocations); + + _skinSpecularMapProgram.addShaderFromSourceCode(QGLShader::Vertex, model_vert); + _skinSpecularMapProgram.addShaderFromSourceCode(QGLShader::Fragment, model_specular_map_frag); + initSkinProgram(_skinSpecularMapProgram, _skinSpecularMapLocations); + + _skinNormalSpecularMapProgram.addShaderFromSourceCode(QGLShader::Vertex, skin_model_normal_map_vert); + _skinNormalSpecularMapProgram.addShaderFromSourceCode(QGLShader::Fragment, model_normal_specular_map_frag); + initSkinProgram(_skinNormalSpecularMapProgram, _skinNormalSpecularMapLocations); + + _skinShadowProgram.addShaderFromSourceCode(QGLShader::Vertex, skin_model_shadow_vert); + _skinShadowProgram.addShaderFromSourceCode(QGLShader::Fragment, model_shadow_frag); + initSkinProgram(_skinShadowProgram, _skinShadowLocations); + + + _skinTranslucentProgram.addShaderFromSourceCode(QGLShader::Vertex, skin_model_vert); + _skinTranslucentProgram.addShaderFromSourceCode(QGLShader::Fragment, model_translucent_frag); initSkinProgram(_skinTranslucentProgram, _skinTranslucentLocations); } } From a022e948146f132096e210bcd7267679445d9e0a Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Tue, 30 Dec 2014 12:38:36 -0800 Subject: [PATCH 2/2] Adding the shader files --- libraries/render-utils/src/model_lightmap.slf | 38 +++++++++++++ libraries/render-utils/src/model_lightmap.slv | 41 ++++++++++++++ .../src/model_lightmap_normal_map.slf | 51 +++++++++++++++++ .../src/model_lightmap_normal_map.slv | 47 ++++++++++++++++ .../model_lightmap_normal_specular_map.slf | 55 +++++++++++++++++++ .../src/model_lightmap_specular_map.slf | 41 ++++++++++++++ .../render-utils/src/model_normal_map.slf | 44 +++++++++++++++ .../render-utils/src/model_normal_map.slv | 41 ++++++++++++++ .../src/model_normal_specular_map.slf | 48 ++++++++++++++++ libraries/render-utils/src/model_shadow.slf | 18 ++++++ libraries/render-utils/src/model_shadow.slv | 18 ++++++ .../render-utils/src/model_specular_map.slf | 34 ++++++++++++ .../render-utils/src/model_translucent.slf | 21 +++++++ libraries/render-utils/src/skin_model.slv | 47 ++++++++++++++++ .../src/skin_model_normal_map.slv | 55 +++++++++++++++++++ .../render-utils/src/skin_model_shadow.slv | 31 +++++++++++ 16 files changed, 630 insertions(+) create mode 100755 libraries/render-utils/src/model_lightmap.slf create mode 100755 libraries/render-utils/src/model_lightmap.slv create mode 100755 libraries/render-utils/src/model_lightmap_normal_map.slf create mode 100755 libraries/render-utils/src/model_lightmap_normal_map.slv create mode 100755 libraries/render-utils/src/model_lightmap_normal_specular_map.slf create mode 100755 libraries/render-utils/src/model_lightmap_specular_map.slf create mode 100755 libraries/render-utils/src/model_normal_map.slf create mode 100755 libraries/render-utils/src/model_normal_map.slv create mode 100755 libraries/render-utils/src/model_normal_specular_map.slf create mode 100755 libraries/render-utils/src/model_shadow.slf create mode 100755 libraries/render-utils/src/model_shadow.slv create mode 100755 libraries/render-utils/src/model_specular_map.slf create mode 100755 libraries/render-utils/src/model_translucent.slf create mode 100755 libraries/render-utils/src/skin_model.slv create mode 100755 libraries/render-utils/src/skin_model_normal_map.slv create mode 100755 libraries/render-utils/src/skin_model_shadow.slv diff --git a/libraries/render-utils/src/model_lightmap.slf b/libraries/render-utils/src/model_lightmap.slf new file mode 100755 index 0000000000..9feacbe057 --- /dev/null +++ b/libraries/render-utils/src/model_lightmap.slf @@ -0,0 +1,38 @@ +<@include Config.slh@> +<$VERSION_HEADER$> +// Generated on <$_SCRIBE_DATE$> +// +// model_lightmap.frag +// fragment shader +// +// Created by Samuel Gateau on 11/19/14. +// Copyright 2013 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +// the diffuse texture +uniform sampler2D diffuseMap; + +// the emissive map texture and parameters +uniform sampler2D emissiveMap; +uniform vec2 emissiveParams; + +// the alpha threshold +uniform float alphaThreshold; + +// the interpolated normal +varying vec4 normal; + +// the interpolated texcoord1 +varying vec2 interpolatedTexcoord1; + +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, 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, 0.5); + gl_FragData[2] = vec4((vec3(emissiveParams.x) + emissiveParams.y * emissive.rgb), gl_FrontMaterial.shininess / 128.0); +} diff --git a/libraries/render-utils/src/model_lightmap.slv b/libraries/render-utils/src/model_lightmap.slv new file mode 100755 index 0000000000..9f19ae8de2 --- /dev/null +++ b/libraries/render-utils/src/model_lightmap.slv @@ -0,0 +1,41 @@ +<@include Config.slh@> +<$VERSION_HEADER$> +// Generated on <$_SCRIBE_DATE$> +// +// model_lightmap.vert +// vertex shader +// +// Created by Sam Gateau on 11/21/14. +// Copyright 2013 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +const int MAX_TEXCOORDS = 2; + +uniform mat4 texcoordMatrices[MAX_TEXCOORDS]; + +attribute vec2 texcoord1; + +// the interpolated normal +varying vec4 normal; + +// the interpolated texcoord1 +varying vec2 interpolatedTexcoord1; + +void main(void) { + // transform and store the normal for interpolation + normal = normalize(gl_ModelViewMatrix * vec4(gl_Normal, 0.0)); + + // pass along the diffuse color + gl_FrontColor = gl_Color * gl_FrontMaterial.diffuse; + + // and the texture coordinates + 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/libraries/render-utils/src/model_lightmap_normal_map.slf b/libraries/render-utils/src/model_lightmap_normal_map.slf new file mode 100755 index 0000000000..5bebbee3f6 --- /dev/null +++ b/libraries/render-utils/src/model_lightmap_normal_map.slf @@ -0,0 +1,51 @@ +<@include Config.slh@> +<$VERSION_HEADER$> +// Generated on <$_SCRIBE_DATE$> +// +// model_lightmap_normal_map.frag +// fragment shader +// +// Created by Samuel Gateau on 11/19/14. +// Copyright 2013 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +// the diffuse texture +uniform sampler2D diffuseMap; + +// the normal map texture +uniform sampler2D normalMap; + +// the emissive map texture and parameters +uniform sampler2D emissiveMap; +uniform vec2 emissiveParams; + +// the alpha threshold +uniform float alphaThreshold; + +// the interpolated normal +varying vec4 interpolatedNormal; + +// the interpolated tangent +varying vec4 interpolatedTangent; + +varying vec2 interpolatedTexcoord1; + +void main(void) { + // compute the view normal from the various bits + vec3 normalizedNormal = normalize(vec3(interpolatedNormal)); + vec3 normalizedTangent = normalize(vec3(interpolatedTangent)); + vec3 normalizedBitangent = normalize(cross(normalizedNormal, normalizedTangent)); + vec3 localNormal = vec3(texture2D(normalMap, gl_TexCoord[0].st)) - vec3(0.5, 0.5, 0.5); + vec4 viewNormal = vec4(normalizedTangent * localNormal.x + + normalizedBitangent * localNormal.y + normalizedNormal * localNormal.z, 0.0); + + // 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(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/libraries/render-utils/src/model_lightmap_normal_map.slv b/libraries/render-utils/src/model_lightmap_normal_map.slv new file mode 100755 index 0000000000..c19336ddae --- /dev/null +++ b/libraries/render-utils/src/model_lightmap_normal_map.slv @@ -0,0 +1,47 @@ +<@include Config.slh@> +<$VERSION_HEADER$> +// Generated on <$_SCRIBE_DATE$> +// +// model_lightmap_normal_map.vert +// vertex shader +// +// Created by Sam Gateau on 11/21/14. +// Copyright 2013 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +const int MAX_TEXCOORDS = 2; + +uniform mat4 texcoordMatrices[MAX_TEXCOORDS]; + +// the tangent vector +attribute vec3 tangent; + +attribute vec2 texcoord1; + +// the interpolated normal +varying vec4 interpolatedNormal; + +// the interpolated tangent +varying vec4 interpolatedTangent; + +// the interpolated texcoord1 +varying vec2 interpolatedTexcoord1; + +void main(void) { + // transform and store the normal and tangent for interpolation + interpolatedNormal = gl_ModelViewMatrix * vec4(gl_Normal, 0.0); + interpolatedTangent = gl_ModelViewMatrix * vec4(tangent, 0.0); + + // pass along the diffuse color + gl_FrontColor = gl_Color * gl_FrontMaterial.diffuse; + + // and the texture coordinates + 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/libraries/render-utils/src/model_lightmap_normal_specular_map.slf b/libraries/render-utils/src/model_lightmap_normal_specular_map.slf new file mode 100755 index 0000000000..d2f76e4ef3 --- /dev/null +++ b/libraries/render-utils/src/model_lightmap_normal_specular_map.slf @@ -0,0 +1,55 @@ +<@include Config.slh@> +<$VERSION_HEADER$> +// Generated on <$_SCRIBE_DATE$> +// +// model_lightmap_normal_specular_map.frag +// fragment shader +// +// Created by Samuel Gateau on 11/19/14. +// Copyright 2014 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +// the diffuse texture +uniform sampler2D diffuseMap; + +// the emissive map texture and parameters +uniform sampler2D emissiveMap; +uniform vec2 emissiveParams; + +// the normal map texture +uniform sampler2D normalMap; + +// the specular map texture +uniform sampler2D specularMap; + +// the alpha threshold +uniform float alphaThreshold; + +// the interpolated normal +varying vec4 interpolatedNormal; + +// the interpolated tangent +varying vec4 interpolatedTangent; + +varying vec2 interpolatedTexcoord1; + +void main(void) { + // compute the view normal from the various bits + vec3 normalizedNormal = normalize(vec3(interpolatedNormal)); + vec3 normalizedTangent = normalize(vec3(interpolatedTangent)); + vec3 normalizedBitangent = normalize(cross(normalizedNormal, normalizedTangent)); + vec3 localNormal = vec3(texture2D(normalMap, gl_TexCoord[0].st)) - vec3(0.5, 0.5, 0.5); + vec4 viewNormal = vec4(normalizedTangent * localNormal.x + + normalizedBitangent * localNormal.y + normalizedNormal * localNormal.z, 0.0); + + // 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(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/libraries/render-utils/src/model_lightmap_specular_map.slf b/libraries/render-utils/src/model_lightmap_specular_map.slf new file mode 100755 index 0000000000..40879a8fc3 --- /dev/null +++ b/libraries/render-utils/src/model_lightmap_specular_map.slf @@ -0,0 +1,41 @@ +<@include Config.slh@> +<$VERSION_HEADER$> +// Generated on <$_SCRIBE_DATE$> +// +// model_lightmap_specular_map.frag +// fragment shader +// +// Created by Samuel Gateau on 11/19/14. +// Copyright 2014 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +// the diffuse texture +uniform sampler2D diffuseMap; + +// the emissive map texture and parameters +uniform sampler2D emissiveMap; +uniform vec2 emissiveParams; + +// the specular texture +uniform sampler2D specularMap; + +// the alpha threshold +uniform float alphaThreshold; + +// the interpolated normal +varying vec4 normal; + +varying vec2 interpolatedTexcoord1; + +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(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/libraries/render-utils/src/model_normal_map.slf b/libraries/render-utils/src/model_normal_map.slf new file mode 100755 index 0000000000..b625b346ed --- /dev/null +++ b/libraries/render-utils/src/model_normal_map.slf @@ -0,0 +1,44 @@ +<@include Config.slh@> +<$VERSION_HEADER$> +// Generated on <$_SCRIBE_DATE$> +// +// model_normal_map.frag +// fragment shader +// +// Created by Andrzej Kapolka on 10/29/13. +// Copyright 2013 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +// the diffuse texture +uniform sampler2D diffuseMap; + +// the normal map texture +uniform sampler2D normalMap; + +// the alpha threshold +uniform float alphaThreshold; + +// the interpolated normal +varying vec4 interpolatedNormal; + +// the interpolated tangent +varying vec4 interpolatedTangent; + +void main(void) { + // compute the view normal from the various bits + vec3 normalizedNormal = normalize(vec3(interpolatedNormal)); + vec3 normalizedTangent = normalize(vec3(interpolatedTangent)); + vec3 normalizedBitangent = normalize(cross(normalizedNormal, normalizedTangent)); + vec3 localNormal = vec3(texture2D(normalMap, gl_TexCoord[0].st)) - vec3(0.5, 0.5, 0.5); + vec4 viewNormal = vec4(normalizedTangent * localNormal.x + + normalizedBitangent * localNormal.y + normalizedNormal * localNormal.z, 0.0); + + // set the diffuse, normal, specular data + vec4 diffuse = texture2D(diffuseMap, gl_TexCoord[0].st); + gl_FragData[0] = vec4(gl_Color.rgb * diffuse.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/libraries/render-utils/src/model_normal_map.slv b/libraries/render-utils/src/model_normal_map.slv new file mode 100755 index 0000000000..0eb974912f --- /dev/null +++ b/libraries/render-utils/src/model_normal_map.slv @@ -0,0 +1,41 @@ +<@include Config.slh@> +<$VERSION_HEADER$> +// Generated on <$_SCRIBE_DATE$> +// +// model.vert +// vertex shader +// +// Created by Andrzej Kapolka on 10/14/13. +// Copyright 2013 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +const int MAX_TEXCOORDS = 2; + +uniform mat4 texcoordMatrices[MAX_TEXCOORDS]; + +// the tangent vector +attribute vec3 tangent; + +// the interpolated normal +varying vec4 interpolatedNormal; + +// the interpolated tangent +varying vec4 interpolatedTangent; + +void main(void) { + // transform and store the normal and tangent for interpolation + interpolatedNormal = gl_ModelViewMatrix * vec4(gl_Normal, 0.0); + interpolatedTangent = gl_ModelViewMatrix * vec4(tangent, 0.0); + + // pass along the diffuse color + gl_FrontColor = gl_Color * gl_FrontMaterial.diffuse; + + // and the texture coordinates + gl_TexCoord[0] = texcoordMatrices[0] * vec4(gl_MultiTexCoord0.xy, 0.0, 1.0); + + // use standard pipeline transform + gl_Position = ftransform(); +} diff --git a/libraries/render-utils/src/model_normal_specular_map.slf b/libraries/render-utils/src/model_normal_specular_map.slf new file mode 100755 index 0000000000..fd288f0867 --- /dev/null +++ b/libraries/render-utils/src/model_normal_specular_map.slf @@ -0,0 +1,48 @@ +<@include Config.slh@> +<$VERSION_HEADER$> +// Generated on <$_SCRIBE_DATE$> +// +// model_normal_specular_map.frag +// fragment shader +// +// Created by Andrzej Kapolka on 5/6/14. +// Copyright 2014 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +// the diffuse texture +uniform sampler2D diffuseMap; + +// the normal map texture +uniform sampler2D normalMap; + +// the specular map texture +uniform sampler2D specularMap; + +// the alpha threshold +uniform float alphaThreshold; + +// the interpolated normal +varying vec4 interpolatedNormal; + +// the interpolated tangent +varying vec4 interpolatedTangent; + +void main(void) { + // compute the view normal from the various bits + vec3 normalizedNormal = normalize(vec3(interpolatedNormal)); + vec3 normalizedTangent = normalize(vec3(interpolatedTangent)); + vec3 normalizedBitangent = normalize(cross(normalizedNormal, normalizedTangent)); + vec3 localNormal = vec3(texture2D(normalMap, gl_TexCoord[0].st)) - vec3(0.5, 0.5, 0.5); + vec4 viewNormal = vec4(normalizedTangent * localNormal.x + + normalizedBitangent * localNormal.y + normalizedNormal * localNormal.z, 0.0); + + // set the diffuse, normal, specular data + vec4 diffuse = texture2D(diffuseMap, gl_TexCoord[0].st); + gl_FragData[0] = vec4(gl_Color.rgb * diffuse.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/libraries/render-utils/src/model_shadow.slf b/libraries/render-utils/src/model_shadow.slf new file mode 100755 index 0000000000..1fbb44140b --- /dev/null +++ b/libraries/render-utils/src/model_shadow.slf @@ -0,0 +1,18 @@ +<@include Config.slh@> +<$VERSION_HEADER$> +// Generated on <$_SCRIBE_DATE$> +// +// model_shadow.frag +// fragment shader +// +// Created by Andrzej Kapolka on 3/24/14. +// Copyright 2013 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +void main(void) { + // fixed color for now (we may eventually want to use texture alpha) + gl_FragColor = vec4(1.0, 1.0, 1.0, 0.0); +} diff --git a/libraries/render-utils/src/model_shadow.slv b/libraries/render-utils/src/model_shadow.slv new file mode 100755 index 0000000000..6ff8c23f5a --- /dev/null +++ b/libraries/render-utils/src/model_shadow.slv @@ -0,0 +1,18 @@ +<@include Config.slh@> +<$VERSION_HEADER$> +// Generated on <$_SCRIBE_DATE$> +// +// model_shadow.vert +// vertex shader +// +// Created by Andrzej Kapolka on 3/24/14. +// Copyright 2014 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +void main(void) { + // just use standard pipeline transform + gl_Position = ftransform(); +} diff --git a/libraries/render-utils/src/model_specular_map.slf b/libraries/render-utils/src/model_specular_map.slf new file mode 100755 index 0000000000..4428173562 --- /dev/null +++ b/libraries/render-utils/src/model_specular_map.slf @@ -0,0 +1,34 @@ +<@include Config.slh@> +<$VERSION_HEADER$> +// Generated on <$_SCRIBE_DATE$> +// +// model_specular_map.frag +// fragment shader +// +// Created by Andrzej Kapolka on 5/6/14. +// Copyright 2014 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +// the diffuse texture +uniform sampler2D diffuseMap; + +// the specular texture +uniform sampler2D specularMap; + +// the alpha threshold +uniform float alphaThreshold; + +// the interpolated normal +varying vec4 normal; + +void main(void) { + // set the diffuse, normal, specular data + vec4 diffuse = texture2D(diffuseMap, gl_TexCoord[0].st); + gl_FragData[0] = vec4(gl_Color.rgb * diffuse.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/libraries/render-utils/src/model_translucent.slf b/libraries/render-utils/src/model_translucent.slf new file mode 100755 index 0000000000..497f5962bc --- /dev/null +++ b/libraries/render-utils/src/model_translucent.slf @@ -0,0 +1,21 @@ +<@include Config.slh@> +<$VERSION_HEADER$> +// Generated on <$_SCRIBE_DATE$> +// +// model_translucent.frag +// fragment shader +// +// Created by Andrzej Kapolka on 9/19/14. +// Copyright 2014 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +// the diffuse texture +uniform sampler2D diffuseMap; + +void main(void) { + // set the diffuse data + gl_FragData[0] = gl_Color * texture2D(diffuseMap, gl_TexCoord[0].st); +} diff --git a/libraries/render-utils/src/skin_model.slv b/libraries/render-utils/src/skin_model.slv new file mode 100755 index 0000000000..4144198969 --- /dev/null +++ b/libraries/render-utils/src/skin_model.slv @@ -0,0 +1,47 @@ +<@include Config.slh@> +<$VERSION_HEADER$> +// Generated on <$_SCRIBE_DATE$> +// +// skin_model.vert +// vertex shader +// +// Created by Andrzej Kapolka on 10/14/13. +// Copyright 2013 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +const int MAX_TEXCOORDS = 2; +const int MAX_CLUSTERS = 128; +const int INDICES_PER_VERTEX = 4; + +uniform mat4 clusterMatrices[MAX_CLUSTERS]; +uniform mat4 texcoordMatrices[MAX_TEXCOORDS]; + +attribute vec4 clusterIndices; +attribute vec4 clusterWeights; + +// the interpolated normal +varying vec4 normal; + +void main(void) { + vec4 position = vec4(0.0, 0.0, 0.0, 0.0); + normal = vec4(0.0, 0.0, 0.0, 0.0); + for (int i = 0; i < INDICES_PER_VERTEX; i++) { + mat4 clusterMatrix = clusterMatrices[int(clusterIndices[i])]; + float clusterWeight = clusterWeights[i]; + position += clusterMatrix * gl_Vertex * clusterWeight; + normal += clusterMatrix * vec4(gl_Normal, 0.0) * clusterWeight; + } + + normal = normalize(gl_ModelViewMatrix * normal); + + // pass along the diffuse color + gl_FrontColor = gl_FrontMaterial.diffuse; + + // and the texture coordinates + gl_TexCoord[0] = texcoordMatrices[0] * vec4(gl_MultiTexCoord0.xy, 0.0, 1.0); + + gl_Position = gl_ModelViewProjectionMatrix * position; +} diff --git a/libraries/render-utils/src/skin_model_normal_map.slv b/libraries/render-utils/src/skin_model_normal_map.slv new file mode 100755 index 0000000000..b021184591 --- /dev/null +++ b/libraries/render-utils/src/skin_model_normal_map.slv @@ -0,0 +1,55 @@ +<@include Config.slh@> +<$VERSION_HEADER$> +// Generated on <$_SCRIBE_DATE$> +// +// skin_model_normal_map.vert +// vertex shader +// +// Created by Andrzej Kapolka on 10/29/13. +// Copyright 2013 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +const int MAX_TEXCOORDS = 2; +const int MAX_CLUSTERS = 128; +const int INDICES_PER_VERTEX = 4; + +uniform mat4 clusterMatrices[MAX_CLUSTERS]; +uniform mat4 texcoordMatrices[MAX_TEXCOORDS]; + +// the tangent vector +attribute vec3 tangent; + +attribute vec4 clusterIndices; +attribute vec4 clusterWeights; + +// the interpolated normal +varying vec4 interpolatedNormal; + +// the interpolated tangent +varying vec4 interpolatedTangent; + +void main(void) { + vec4 interpolatedPosition = vec4(0.0, 0.0, 0.0, 0.0); + interpolatedNormal = vec4(0.0, 0.0, 0.0, 0.0); + interpolatedTangent = vec4(0.0, 0.0, 0.0, 0.0); + for (int i = 0; i < INDICES_PER_VERTEX; i++) { + mat4 clusterMatrix = clusterMatrices[int(clusterIndices[i])]; + float clusterWeight = clusterWeights[i]; + interpolatedPosition += clusterMatrix * gl_Vertex * clusterWeight; + interpolatedNormal += clusterMatrix * vec4(gl_Normal, 0.0) * clusterWeight; + interpolatedTangent += clusterMatrix * vec4(tangent, 0.0) * clusterWeight; + } + interpolatedNormal = gl_ModelViewMatrix * interpolatedNormal; + interpolatedTangent = gl_ModelViewMatrix * interpolatedTangent; + + // pass along the diffuse color + gl_FrontColor = gl_FrontMaterial.diffuse; + + // and the texture coordinates + gl_TexCoord[0] = texcoordMatrices[0] * vec4(gl_MultiTexCoord0.xy, 0.0, 1.0); + + gl_Position = gl_ModelViewProjectionMatrix * interpolatedPosition; +} diff --git a/libraries/render-utils/src/skin_model_shadow.slv b/libraries/render-utils/src/skin_model_shadow.slv new file mode 100755 index 0000000000..9a594ac26c --- /dev/null +++ b/libraries/render-utils/src/skin_model_shadow.slv @@ -0,0 +1,31 @@ +<@include Config.slh@> +<$VERSION_HEADER$> +// Generated on <$_SCRIBE_DATE$> +// +// skin_model_shadow.vert +// vertex shader +// +// Created by Andrzej Kapolka on 3/24/14. +// Copyright 2014 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +const int MAX_CLUSTERS = 128; +const int INDICES_PER_VERTEX = 4; + +uniform mat4 clusterMatrices[MAX_CLUSTERS]; + +attribute vec4 clusterIndices; +attribute vec4 clusterWeights; + +void main(void) { + vec4 position = vec4(0.0, 0.0, 0.0, 0.0); + for (int i = 0; i < INDICES_PER_VERTEX; i++) { + mat4 clusterMatrix = clusterMatrices[int(clusterIndices[i])]; + float clusterWeight = clusterWeights[i]; + position += clusterMatrix * gl_Vertex * clusterWeight; + } + gl_Position = gl_ModelViewProjectionMatrix * position; +}