Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Renderer|Refactor: Moved general purpose shader functions to GLSL files
In the "net.dengine.client.renderer" pack, shaders/include/ contains GLSL files with functions useful for many shaders. This allows more easily creating new custom shaders for instance for models. Uses the include feature in GLShaderBank.
- Loading branch information
Showing
5 changed files
with
195 additions
and
85 deletions.
There are no files selected for viewing
95 changes: 95 additions & 0 deletions
95
doomsday/apps/client/net.dengine.client.pack/renderer.pack/shaders/include/lighting.glsl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/* | ||
* The Doomsday Engine Project | ||
* Common OpenGL Shaders: Lighting | ||
* | ||
* Copyright (c) 2015 Jaakko Keränen <jaakko.keranen@iki.fi> | ||
* | ||
* @par License | ||
* LGPL: http://www.gnu.org/licenses/lgpl.html | ||
* | ||
* <small>This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation; either version 3 of the License, or (at your | ||
* option) any later version. This program is distributed in the hope that it | ||
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty | ||
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser | ||
* General Public License for more details. You should have received a copy of | ||
* the GNU Lesser General Public License along with this program; if not, see: | ||
* http://www.gnu.org/licenses</small> | ||
*/ | ||
|
||
uniform highp float uEmission; // factor for emissive light | ||
|
||
uniform highp vec4 uAmbientLight; | ||
uniform highp vec4 uLightIntensities[4]; | ||
uniform highp vec3 uLightDirs[4]; | ||
|
||
varying highp vec3 vLightDirs[4]; // tangent space | ||
varying highp vec3 vEyeDir; // tangent space | ||
|
||
highp vec4 diffuseLightContrib(int index, highp vec3 normal) | ||
{ | ||
if(uLightIntensities[index].a <= 0.001) | ||
{ | ||
return vec4(0.0); // too dim | ||
} | ||
highp float d = dot(normal, normalize(vLightDirs[index])); | ||
return max(d * uLightIntensities[index], vec4(0.0)); | ||
} | ||
|
||
highp vec4 diffuseLight(highp vec3 normal) | ||
{ | ||
return (uAmbientLight + | ||
diffuseLightContrib(0, normal) + | ||
diffuseLightContrib(1, normal) + | ||
diffuseLightContrib(2, normal) + | ||
diffuseLightContrib(3, normal)); | ||
} | ||
|
||
#ifdef DENG_HAVE_UTEX | ||
|
||
highp vec4 specularLightContrib(highp vec2 specularUV, int index, highp vec3 normal) | ||
{ | ||
if(uLightIntensities[index].a <= 0.001) | ||
{ | ||
return vec4(0.0); // too dim | ||
} | ||
|
||
// Is the surface facing the light direction? | ||
highp float facing = smoothstep(0.0, 0.2, dot(vLightDirs[index], normal)); | ||
if(facing <= 0.0) | ||
{ | ||
return vec4(0.0); // wrong way | ||
} | ||
|
||
highp vec3 reflected = reflect(-vLightDirs[index], normal); | ||
|
||
// Check the specular texture for parameters. | ||
highp vec4 specular = texture2D(uTex, specularUV); | ||
highp float shininess = max(1.0, specular.a * 7.0); | ||
|
||
highp float d = | ||
facing * | ||
dot(normalize(vEyeDir), reflected) * | ||
shininess - max(0.0, shininess - 1.0); | ||
return max(0.0, d) * | ||
uLightIntensities[index] * | ||
vec4(specular.rgb * 2.0, max(max(specular.r, specular.g), specular.b)); | ||
} | ||
|
||
highp vec4 specularLight(highp vec2 specularUV, highp vec3 normal) | ||
{ | ||
return specularLightContrib(specularUV, 0, normal) + | ||
specularLightContrib(specularUV, 1, normal) + | ||
specularLightContrib(specularUV, 2, normal) + | ||
specularLightContrib(specularUV, 3, normal); | ||
} | ||
|
||
highp vec4 emittedLight(highp vec2 emissiveUV) | ||
{ | ||
highp vec4 emission = uEmission * texture2D(uTex, emissiveUV); | ||
emission.a = 0.0; // Does not contribute to alpha. | ||
return emission; | ||
} | ||
|
||
#endif // DENG_HAVE_UTEX |
36 changes: 36 additions & 0 deletions
36
doomsday/apps/client/net.dengine.client.pack/renderer.pack/shaders/include/skeletal.glsl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* The Doomsday Engine Project | ||
* Common OpenGL Shaders: Skeletal animation (vertex shader) | ||
* | ||
* Copyright (c) 2015 Jaakko Keränen <jaakko.keranen@iki.fi> | ||
* | ||
* @par License | ||
* LGPL: http://www.gnu.org/licenses/lgpl.html | ||
* | ||
* <small>This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation; either version 3 of the License, or (at your | ||
* option) any later version. This program is distributed in the hope that it | ||
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty | ||
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser | ||
* General Public License for more details. You should have received a copy of | ||
* the GNU Lesser General Public License along with this program; if not, see: | ||
* http://www.gnu.org/licenses</small> | ||
*/ | ||
|
||
uniform highp mat4 uBoneMatrices[64]; | ||
|
||
attribute highp vec4 aBoneIDs; | ||
attribute highp vec4 aBoneWeights; | ||
|
||
/* | ||
* Calculates the bone matrix for the current vertex. Bones and their weights | ||
* are determined by vertex attributes. | ||
*/ | ||
highp mat4 vertexBoneTransform() | ||
{ | ||
return uBoneMatrices[int(aBoneIDs.x + 0.5)] * aBoneWeights.x + | ||
uBoneMatrices[int(aBoneIDs.y + 0.5)] * aBoneWeights.y + | ||
uBoneMatrices[int(aBoneIDs.z + 0.5)] * aBoneWeights.z + | ||
uBoneMatrices[int(aBoneIDs.w + 0.5)] * aBoneWeights.w; | ||
} |
36 changes: 36 additions & 0 deletions
36
doomsday/apps/client/net.dengine.client.pack/renderer.pack/shaders/include/texture.glsl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* The Doomsday Engine Project | ||
* Common OpenGL Shaders: Texture manipulation | ||
* | ||
* Copyright (c) 2015 Jaakko Keränen <jaakko.keranen@iki.fi> | ||
* | ||
* @par License | ||
* LGPL: http://www.gnu.org/licenses/lgpl.html | ||
* | ||
* <small>This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation; either version 3 of the License, or (at your | ||
* option) any later version. This program is distributed in the hope that it | ||
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty | ||
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser | ||
* General Public License for more details. You should have received a copy of | ||
* the GNU Lesser General Public License along with this program; if not, see: | ||
* http://www.gnu.org/licenses</small> | ||
*/ | ||
|
||
#define DENG_HAVE_UTEX | ||
|
||
uniform sampler2D uTex; // texture atlas | ||
|
||
/* | ||
* Maps the normalized @a uv to the rectangle defined by @a bounds. | ||
*/ | ||
highp vec2 mapToBounds(highp vec2 uv, highp vec4 bounds) | ||
{ | ||
return bounds.xy + uv * bounds.zw; | ||
} | ||
|
||
highp vec3 normalVector(highp vec2 uv) | ||
{ | ||
return normalize((texture2D(uTex, uv).xyz * 2.0) - 1.0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters