|
|
@@ -1,10 +1,11 @@
|
|
|
/// @file
|
|
|
///
|
|
|
-/// This a generic shader to fill the deferred shading buffers. You can always build your own if you dont need to write
|
|
|
-/// in all the buffers
|
|
|
+/// This a generic shader to fill the deferred shading buffers. You can always
|
|
|
+/// build your own if you dont need to write in all the buffers
|
|
|
///
|
|
|
/// Control defines:
|
|
|
-/// DIFFUSE_MAPPING, NORMAL_MAPPING, SPECULAR_MAPPING, PARALLAX_MAPPING, ENVIRONMENT_MAPPING, ALPHA_TESTING
|
|
|
+/// DIFFUSE_MAPPING, NORMAL_MAPPING, SPECULAR_MAPPING, PARALLAX_MAPPING,
|
|
|
+/// ENVIRONMENT_MAPPING, ALPHA_TESTING
|
|
|
|
|
|
#if defined(ALPHA_TESTING) && !defined(DIFFUSE_MAPPING)
|
|
|
#error "Cannot have ALPHA_TESTING without DIFFUSE_MAPPING"
|
|
|
@@ -59,9 +60,9 @@ out vec3 vVertPosViewSpace; ///< For env mapping. AKA view vector
|
|
|
|
|
|
|
|
|
|
|
|
-//======================================================================================================================
|
|
|
-// main =
|
|
|
-//======================================================================================================================
|
|
|
+//==============================================================================
|
|
|
+// main =
|
|
|
+//==============================================================================
|
|
|
void main()
|
|
|
{
|
|
|
// calculate the vert pos, normal and tangent
|
|
|
@@ -93,12 +94,15 @@ void main()
|
|
|
|
|
|
#pragma anki fragShaderBegins
|
|
|
|
|
|
-/// @note The process of calculating the diffuse color for the diffuse MSFAI is divided into two parts. The first
|
|
|
-/// happens before the normal calculation and the other just after it. In the first part we read the texture (or the
|
|
|
-/// gl_Color) and we set the _diffColl_. In case of grass we discard. In the second part we calculate a SEM color and
|
|
|
-/// we combine it with the _diffColl_. We cannot put the second part before normal calculation because SEM needs
|
|
|
-/// the _normal_. Also we cannot put the first part after normal calculation because in case of grass we will waste
|
|
|
-/// calculations for the normal. For that two reasons we split the diffuse calculations in two parts
|
|
|
+/// @note The process of calculating the diffuse color for the diffuse MSFAI is
|
|
|
+/// divided into two parts. The first happens before the normal calculation and
|
|
|
+/// the other just after it. In the first part we read the texture (or the
|
|
|
+/// gl_Color) and we set the _diffColl_. In case of grass we discard. In the
|
|
|
+/// second part we calculate a SEM color and we combine it with the _diffColl_.
|
|
|
+/// We cannot put the second part before normal calculation because SEM needs
|
|
|
+/// the _normal_. Also we cannot put the first part after normal calculation
|
|
|
+/// because in case of grass we will waste calculations for the normal. For
|
|
|
+/// that two reasons we split the diffuse calculations in two parts
|
|
|
|
|
|
#pragma anki include "shaders/Pack.glsl"
|
|
|
|
|
|
@@ -122,7 +126,8 @@ uniform float shininess = 50.0;
|
|
|
uniform vec3 diffuseCol = vec3(1.0, 0.0, 1.0);
|
|
|
uniform vec3 specularCol = vec3(1.0, 0.0, 1.0);
|
|
|
#if defined(ALPHA_TESTING)
|
|
|
- uniform float alphaTestingTolerance = 0.5; ///< Below this value the pixels are getting discarded
|
|
|
+ /// Below this value the pixels are getting discarded
|
|
|
+ uniform float alphaTestingTolerance = 0.5;
|
|
|
#endif
|
|
|
uniform float blurring = 0.0;
|
|
|
|
|
|
@@ -141,25 +146,26 @@ layout(location = 2) out vec4 fMsSpecularFai;
|
|
|
const float MAX_SHININESS = 128.0;
|
|
|
|
|
|
|
|
|
-//======================================================================================================================
|
|
|
-// Normal funcs =
|
|
|
-//======================================================================================================================
|
|
|
+//==============================================================================
|
|
|
+// Normal funcs =
|
|
|
+//==============================================================================
|
|
|
/// @param[in] normal The fragment's normal in view space
|
|
|
/// @param[in] tangent The tangent
|
|
|
/// @param[in] tangent Extra stuff for the tangent
|
|
|
/// @param[in] map The map
|
|
|
/// @param[in] texCoords Texture coordinates
|
|
|
-vec3 getNormalUsingMap(in vec3 normal, in vec3 tangent, in float tangentW, in sampler2D map, in vec2 texCoords)
|
|
|
+vec3 getNormalUsingMap(in vec3 normal, in vec3 tangent, in float tangentW,
|
|
|
+ in sampler2D map, in vec2 texCoords)
|
|
|
{
|
|
|
- vec3 n = normalize(normal);
|
|
|
- vec3 t = normalize(tangent);
|
|
|
- vec3 b = cross(n, t) * tangentW;
|
|
|
+ vec3 n = normalize(normal);
|
|
|
+ vec3 t = normalize(tangent);
|
|
|
+ vec3 b = cross(n, t) * tangentW;
|
|
|
|
|
|
- mat3 tbnMat = mat3(t, b, n);
|
|
|
+ mat3 tbnMat = mat3(t, b, n);
|
|
|
|
|
|
- vec3 nAtTangentspace = (texture2D(map, texCoords).rgb - 0.5) * 2.0;
|
|
|
+ vec3 nAtTangentspace = (texture2D(map, texCoords).rgb - 0.5) * 2.0;
|
|
|
|
|
|
- return normalize(tbnMat * nAtTangentspace);
|
|
|
+ return normalize(tbnMat * nAtTangentspace);
|
|
|
}
|
|
|
|
|
|
/// Just normalize
|
|
|
@@ -169,9 +175,9 @@ vec3 getNormalSimple(in vec3 normal)
|
|
|
}
|
|
|
|
|
|
|
|
|
-//======================================================================================================================
|
|
|
-// doEnvMapping =
|
|
|
-//======================================================================================================================
|
|
|
+//==============================================================================
|
|
|
+// doEnvMapping =
|
|
|
+//==============================================================================
|
|
|
/// Environment mapping calculations
|
|
|
/// @param[in] vertPosViewSpace Fragment position in view space
|
|
|
/// @param[in] normal Fragment's normal in view space as well
|
|
|
@@ -179,8 +185,8 @@ vec3 getNormalSimple(in vec3 normal)
|
|
|
/// @return The color
|
|
|
vec3 doEnvMapping(in vec3 vertPosViewSpace, in vec3 normal, in sampler2D map)
|
|
|
{
|
|
|
- // In case of normal mapping I could play with vertex's normal but this gives better results and its allready
|
|
|
- // computed
|
|
|
+ // In case of normal mapping I could play with vertex's normal but this
|
|
|
+ // gives better results and its allready computed
|
|
|
|
|
|
vec3 u = normalize(vertPosViewSpace);
|
|
|
vec3 r = reflect(u, normal);
|
|
|
@@ -193,10 +199,11 @@ vec3 doEnvMapping(in vec3 vertPosViewSpace, in vec3 normal, in sampler2D map)
|
|
|
}
|
|
|
|
|
|
|
|
|
-//======================================================================================================================
|
|
|
-// doAlpha =
|
|
|
-//======================================================================================================================
|
|
|
-/// Using a 4-channel texture and a tolerance discard the fragment if the texture's alpha is less than the tolerance
|
|
|
+//==============================================================================
|
|
|
+// doAlpha =
|
|
|
+//==============================================================================
|
|
|
+/// Using a 4-channel texture and a tolerance discard the fragment if the
|
|
|
+/// texture's alpha is less than the tolerance
|
|
|
/// @param[in] map The diffuse map
|
|
|
/// @param[in] tolerance Tolerance value
|
|
|
/// @param[in] texCoords Texture coordinates
|
|
|
@@ -212,14 +219,15 @@ vec3 doAlpha(in sampler2D map, in float tolerance, in vec2 texCoords)
|
|
|
}
|
|
|
|
|
|
|
|
|
-//======================================================================================================================
|
|
|
-// main =
|
|
|
-//======================================================================================================================
|
|
|
+//==============================================================================
|
|
|
+// main =
|
|
|
+//==============================================================================
|
|
|
void main()
|
|
|
{
|
|
|
//
|
|
|
// Paralax Mapping Calculations
|
|
|
- // The code below reads the height map, makes some calculations and returns a new texCoords
|
|
|
+ // The code below reads the height map, makes some calculations and returns
|
|
|
+ // a new texCoords
|
|
|
//
|
|
|
#if defined(PARALLAX_MAPPING)
|
|
|
/*const float _scale = 0.04;
|
|
|
@@ -260,13 +268,15 @@ void main()
|
|
|
|
|
|
//
|
|
|
// Diffuse Calculations (Part I)
|
|
|
- // Get the color from the diffuse map and discard if alpha testing is on and alpha is zero
|
|
|
+ // Get the color from the diffuse map and discard if alpha testing is on
|
|
|
+ // and alpha is zero
|
|
|
//
|
|
|
vec3 _diffColl_;
|
|
|
#if defined(DIFFUSE_MAPPING)
|
|
|
|
|
|
#if defined(ALPHA_TESTING)
|
|
|
- _diffColl_ = doAlpha(diffuseMap, alphaTestingTolerance, _superTexCoords_);
|
|
|
+ _diffColl_ = doAlpha(diffuseMap, alphaTestingTolerance,
|
|
|
+ _superTexCoords_);
|
|
|
#else // no alpha
|
|
|
_diffColl_ = texture2D(diffuseMap, _superTexCoords_).rgb;
|
|
|
#endif
|
|
|
@@ -279,10 +289,12 @@ void main()
|
|
|
|
|
|
//
|
|
|
// Normal Calculations
|
|
|
- // Either use a normap map and make some calculations or use the vertex normal
|
|
|
+ // Either use a normap map and make some calculations or use the vertex
|
|
|
+ // normal
|
|
|
//
|
|
|
#if defined(NORMAL_MAPPING)
|
|
|
- vec3 _normal_ = getNormalUsingMap(vNormal, vTangent, vTangentW, normalMap, _superTexCoords_);
|
|
|
+ vec3 _normal_ = getNormalUsingMap(vNormal, vTangent, vTangentW,
|
|
|
+ normalMap, _superTexCoords_);
|
|
|
#else
|
|
|
vec3 _normal_ = getNormalSimple(vNormal);
|
|
|
#endif
|
|
|
@@ -290,7 +302,8 @@ void main()
|
|
|
|
|
|
//
|
|
|
// Diffuse Calculations (Part II)
|
|
|
- // If SEM is enabled make some calculations (using the vVertPosViewSpace, environmentMap and the _normal_) and
|
|
|
+ // If SEM is enabled make some calculations (using the vVertPosViewSpace,
|
|
|
+ // environmentMap and the _normal_) and
|
|
|
// combine colors of SEM and the _diffColl_
|
|
|
//
|
|
|
#if defined(ENVIRONMENT_MAPPING)
|
|
|
@@ -303,8 +316,9 @@ void main()
|
|
|
// Specular Calculations
|
|
|
//
|
|
|
#if defined(SPECULAR_MAPPING)
|
|
|
- vec4 _specularCol_ = vec4(texture2D(specularMap, _superTexCoords_).rgb * specularCol,
|
|
|
- shininess / MAX_SHININESS);
|
|
|
+ vec4 _specularCol_ = vec4(
|
|
|
+ texture2D(specularMap, _superTexCoords_).rgb * specularCol,
|
|
|
+ shininess / MAX_SHININESS);
|
|
|
#else // no specular map
|
|
|
vec4 _specularCol_ = vec4(specularCol, shininess / MAX_SHININESS);
|
|
|
#endif
|