summaryrefslogtreecommitdiffhomepage
path: root/examples/web/models/resources/shaders
diff options
context:
space:
mode:
authorRay <[email protected]>2019-05-18 01:27:54 +0200
committerRay <[email protected]>2019-05-18 01:27:54 +0200
commit210d5ec72bbc4ba426b21f69e6f65b6d75923d05 (patch)
treec01f6e14d673504534602c7ae9609b3dff248806 /examples/web/models/resources/shaders
parent85b11a6baf64a2b4e02c81d4d47b15eb578dc074 (diff)
downloadraylib.com-210d5ec72bbc4ba426b21f69e6f65b6d75923d05.tar.gz
raylib.com-210d5ec72bbc4ba426b21f69e6f65b6d75923d05.zip
Update examples to raylib 2.5 -WIP-
Remove old examples
Diffstat (limited to 'examples/web/models/resources/shaders')
-rw-r--r--examples/web/models/resources/shaders/brdf.fs75
-rw-r--r--examples/web/models/resources/shaders/cubemap.fs4
-rw-r--r--examples/web/models/resources/shaders/cubemap.vs4
-rw-r--r--examples/web/models/resources/shaders/irradiance.fs4
-rw-r--r--examples/web/models/resources/shaders/pbr.vs12
-rw-r--r--examples/web/models/resources/shaders/prefilter.fs4
-rw-r--r--examples/web/models/resources/shaders/skybox.fs4
-rw-r--r--examples/web/models/resources/shaders/skybox.vs4
8 files changed, 52 insertions, 59 deletions
diff --git a/examples/web/models/resources/shaders/brdf.fs b/examples/web/models/resources/shaders/brdf.fs
index 59ae384..d04bc66 100644
--- a/examples/web/models/resources/shaders/brdf.fs
+++ b/examples/web/models/resources/shaders/brdf.fs
@@ -1,60 +1,50 @@
/*******************************************************************************************
*
-* rPBR [shader] - Bidirectional reflectance distribution function fragment shader
+* BRDF LUT Generation - Bidirectional reflectance distribution function fragment shader
+*
+* REF: https://github.com/HectorMF/BRDFGenerator
*
* Copyright (c) 2017 Victor Fisac
*
**********************************************************************************************/
#version 330
-#define MAX_SAMPLES 1024u
+
// Input vertex attributes (from vertex shader)
in vec2 fragTexCoord;
// Constant values
const float PI = 3.14159265359;
+const uint MAX_SAMPLES = 1024u;
// Output fragment color
out vec4 finalColor;
-float DistributionGGX(vec3 N, vec3 H, float roughness);
-float RadicalInverse_VdC(uint bits);
vec2 Hammersley(uint i, uint N);
-vec3 ImportanceSampleGGX(vec2 Xi, vec3 N, float roughness);
+float RadicalInverseVdC(uint bits);
float GeometrySchlickGGX(float NdotV, float roughness);
float GeometrySmith(vec3 N, vec3 V, vec3 L, float roughness);
+vec3 ImportanceSampleGGX(vec2 Xi, vec3 N, float roughness);
vec2 IntegrateBRDF(float NdotV, float roughness);
-float DistributionGGX(vec3 N, vec3 H, float roughness)
-{
- float a = roughness*roughness;
- float a2 = a*a;
- float NdotH = max(dot(N, H), 0.0);
- float NdotH2 = NdotH*NdotH;
-
- float nom = a2;
- float denom = (NdotH2*(a2 - 1.0) + 1.0);
- denom = PI*denom*denom;
-
- return nom/denom;
-}
-
-float RadicalInverse_VdC(uint bits)
+float RadicalInverseVdC(uint bits)
{
- bits = (bits << 16u) | (bits >> 16u);
- bits = ((bits & 0x55555555u) << 1u) | ((bits & 0xAAAAAAAAu) >> 1u);
- bits = ((bits & 0x33333333u) << 2u) | ((bits & 0xCCCCCCCCu) >> 2u);
- bits = ((bits & 0x0F0F0F0Fu) << 4u) | ((bits & 0xF0F0F0F0u) >> 4u);
- bits = ((bits & 0x00FF00FFu) << 8u) | ((bits & 0xFF00FF00u) >> 8u);
- return float(bits) * 2.3283064365386963e-10; // / 0x100000000
+ bits = (bits << 16u) | (bits >> 16u);
+ bits = ((bits & 0x55555555u) << 1u) | ((bits & 0xAAAAAAAAu) >> 1u);
+ bits = ((bits & 0x33333333u) << 2u) | ((bits & 0xCCCCCCCCu) >> 2u);
+ bits = ((bits & 0x0F0F0F0Fu) << 4u) | ((bits & 0xF0F0F0F0u) >> 4u);
+ bits = ((bits & 0x00FF00FFu) << 8u) | ((bits & 0xFF00FF00u) >> 8u);
+ return float(bits) * 2.3283064365386963e-10; // / 0x100000000
}
+// Compute Hammersley coordinates
vec2 Hammersley(uint i, uint N)
{
- return vec2(float(i)/float(N), RadicalInverse_VdC(i));
+ return vec2(float(i)/float(N), RadicalInverseVdC(i));
}
+// Integrate number of importance samples for (roughness and NoV)
vec3 ImportanceSampleGGX(vec2 Xi, vec3 N, float roughness)
{
float a = roughness*roughness;
@@ -85,6 +75,7 @@ float GeometrySchlickGGX(float NdotV, float roughness)
return nom/denom;
}
+// Compute the geometry term for the BRDF given roughness squared, NoV, NoL
float GeometrySmith(vec3 N, vec3 V, vec3 L, float roughness)
{
float NdotV = max(dot(N, V), 0.0);
@@ -97,29 +88,31 @@ float GeometrySmith(vec3 N, vec3 V, vec3 L, float roughness)
vec2 IntegrateBRDF(float NdotV, float roughness)
{
- vec3 V = vec3(sqrt(1.0 - NdotV*NdotV), 0.0, NdotV);
float A = 0.0;
- float B = 0.0;
+ float B = 0.0;
+ vec3 V = vec3(sqrt(1.0 - NdotV*NdotV), 0.0, NdotV);
vec3 N = vec3(0.0, 0.0, 1.0);
- for(uint i = 0u; i < MAX_SAMPLES; i++)
+ for (uint i = 0u; i < MAX_SAMPLES; i++)
{
// Generate a sample vector that's biased towards the preferred alignment direction (importance sampling)
- vec2 Xi = Hammersley(i, MAX_SAMPLES);
- vec3 H = ImportanceSampleGGX(Xi, N, roughness);
- vec3 L = normalize(2.0*dot(V, H)*H - V);
- float NdotL = max(L.z, 0.0);
- float NdotH = max(H.z, 0.0);
- float VdotH = max(dot(V, H), 0.0);
+
+ vec2 Xi = Hammersley(i, MAX_SAMPLES); // Compute a Hammersely coordinate
+ vec3 H = ImportanceSampleGGX(Xi, N, roughness); // Integrate number of importance samples for (roughness and NoV)
+ vec3 L = normalize(2.0*dot(V, H)*H - V); // Compute reflection vector L
+
+ float NdotL = max(L.z, 0.0); // Compute normal dot light
+ float NdotH = max(H.z, 0.0); // Compute normal dot half
+ float VdotH = max(dot(V, H), 0.0); // Compute view dot half
if (NdotL > 0.0)
{
- float G = GeometrySmith(N, V, L, roughness);
- float G_Vis = (G*VdotH)/(NdotH*NdotV);
- float Fc = pow(1.0 - VdotH, 5.0);
+ float G = GeometrySmith(N, V, L, roughness); // Compute the geometry term for the BRDF given roughness squared, NoV, NoL
+ float GVis = (G*VdotH)/(NdotH*NdotV); // Compute the visibility term given G, VoH, NoH, NoV, NoL
+ float Fc = pow(1.0 - VdotH, 5.0); // Compute the fresnel term given VoH
- A += (1.0 - Fc)*G_Vis;
- B += Fc*G_Vis;
+ A += (1.0 - Fc)*GVis; // Sum the result given fresnel, geometry, visibility
+ B += Fc*GVis;
}
}
diff --git a/examples/web/models/resources/shaders/cubemap.fs b/examples/web/models/resources/shaders/cubemap.fs
index 09ae62f..e8e2853 100644
--- a/examples/web/models/resources/shaders/cubemap.fs
+++ b/examples/web/models/resources/shaders/cubemap.fs
@@ -9,7 +9,7 @@
#version 330
// Input vertex attributes (from vertex shader)
-in vec3 fragPos;
+in vec3 fragPosition;
// Input uniform values
uniform sampler2D equirectangularMap;
@@ -28,7 +28,7 @@ vec2 SampleSphericalMap(vec3 v)
void main()
{
// Normalize local position
- vec2 uv = SampleSphericalMap(normalize(fragPos));
+ vec2 uv = SampleSphericalMap(normalize(fragPosition));
// Fetch color from texture map
vec3 color = texture(equirectangularMap, uv).rgb;
diff --git a/examples/web/models/resources/shaders/cubemap.vs b/examples/web/models/resources/shaders/cubemap.vs
index 6e0bf4e..5721eaa 100644
--- a/examples/web/models/resources/shaders/cubemap.vs
+++ b/examples/web/models/resources/shaders/cubemap.vs
@@ -16,12 +16,12 @@ uniform mat4 projection;
uniform mat4 view;
// Output vertex attributes (to fragment shader)
-out vec3 fragPos;
+out vec3 fragPosition;
void main()
{
// Calculate fragment position based on model transformations
- fragPos = vertexPosition;
+ fragPosition = vertexPosition;
// Calculate final vertex position
gl_Position = projection*view*vec4(vertexPosition, 1.0);
diff --git a/examples/web/models/resources/shaders/irradiance.fs b/examples/web/models/resources/shaders/irradiance.fs
index 8711367..b42d214 100644
--- a/examples/web/models/resources/shaders/irradiance.fs
+++ b/examples/web/models/resources/shaders/irradiance.fs
@@ -9,7 +9,7 @@
#version 330
// Input vertex attributes (from vertex shader)
-in vec3 fragPos;
+in vec3 fragPosition;
// Input uniform values
uniform samplerCube environmentMap;
@@ -23,7 +23,7 @@ out vec4 finalColor;
void main()
{
// The sample direction equals the hemisphere's orientation
- vec3 normal = normalize(fragPos);
+ vec3 normal = normalize(fragPosition);
vec3 irradiance = vec3(0.0);
diff --git a/examples/web/models/resources/shaders/pbr.vs b/examples/web/models/resources/shaders/pbr.vs
index e852ac1..8bd3faa 100644
--- a/examples/web/models/resources/shaders/pbr.vs
+++ b/examples/web/models/resources/shaders/pbr.vs
@@ -12,11 +12,11 @@
in vec3 vertexPosition;
in vec2 vertexTexCoord;
in vec3 vertexNormal;
-in vec3 vertexTangent;
+in vec4 vertexTangent;
// Input uniform values
uniform mat4 mvp;
-uniform mat4 mMatrix;
+uniform mat4 matModel;
// Output vertex attributes (to fragment shader)
out vec3 fragPosition;
@@ -28,18 +28,18 @@ out vec3 fragBinormal;
void main()
{
// Calculate binormal from vertex normal and tangent
- vec3 vertexBinormal = cross(vertexNormal, vertexTangent);
+ vec3 vertexBinormal = cross(vertexNormal, vec3(vertexTangent));
// Calculate fragment normal based on normal transformations
- mat3 normalMatrix = transpose(inverse(mat3(mMatrix)));
+ mat3 normalMatrix = transpose(inverse(mat3(matModel)));
// Calculate fragment position based on model transformations
- fragPosition = vec3(mMatrix*vec4(vertexPosition, 1.0f));
+ fragPosition = vec3(matModel*vec4(vertexPosition, 1.0f));
// Send vertex attributes to fragment shader
fragTexCoord = vertexTexCoord;
fragNormal = normalize(normalMatrix*vertexNormal);
- fragTangent = normalize(normalMatrix*vertexTangent);
+ fragTangent = normalize(normalMatrix*vec3(vertexTangent));
fragTangent = normalize(fragTangent - dot(fragTangent, fragNormal)*fragNormal);
fragBinormal = normalize(normalMatrix*vertexBinormal);
fragBinormal = cross(fragNormal, fragTangent);
diff --git a/examples/web/models/resources/shaders/prefilter.fs b/examples/web/models/resources/shaders/prefilter.fs
index f5cf64b..9439810 100644
--- a/examples/web/models/resources/shaders/prefilter.fs
+++ b/examples/web/models/resources/shaders/prefilter.fs
@@ -11,7 +11,7 @@
#define CUBEMAP_RESOLUTION 1024.0
// Input vertex attributes (from vertex shader)
-in vec3 fragPos;
+in vec3 fragPosition;
// Input uniform values
uniform samplerCube environmentMap;
@@ -79,7 +79,7 @@ vec3 ImportanceSampleGGX(vec2 Xi, vec3 N, float roughness)
void main()
{
// Make the simplyfying assumption that V equals R equals the normal
- vec3 N = normalize(fragPos);
+ vec3 N = normalize(fragPosition);
vec3 R = N;
vec3 V = R;
diff --git a/examples/web/models/resources/shaders/skybox.fs b/examples/web/models/resources/shaders/skybox.fs
index 0bd2f32..053a251 100644
--- a/examples/web/models/resources/shaders/skybox.fs
+++ b/examples/web/models/resources/shaders/skybox.fs
@@ -9,7 +9,7 @@
#version 330
// Input vertex attributes (from vertex shader)
-in vec3 fragPos;
+in vec3 fragPosition;
// Input uniform values
uniform samplerCube environmentMap;
@@ -20,7 +20,7 @@ out vec4 finalColor;
void main()
{
// Fetch color from texture map
- vec3 color = texture(environmentMap, fragPos).rgb;
+ vec3 color = texture(environmentMap, fragPosition).rgb;
// Apply gamma correction
color = color/(color + vec3(1.0));
diff --git a/examples/web/models/resources/shaders/skybox.vs b/examples/web/models/resources/shaders/skybox.vs
index f40d615..dcbe6c3 100644
--- a/examples/web/models/resources/shaders/skybox.vs
+++ b/examples/web/models/resources/shaders/skybox.vs
@@ -16,12 +16,12 @@ uniform mat4 projection;
uniform mat4 view;
// Output vertex attributes (to fragment shader)
-out vec3 fragPos;
+out vec3 fragPosition;
void main()
{
// Calculate fragment position based on model transformations
- fragPos = vertexPosition;
+ fragPosition = vertexPosition;
// Remove translation from the view matrix
mat4 rotView = mat4(mat3(view));