Reset PBR shader features
This commit is contained in:
parent
df6bdb7d81
commit
117e014ee6
|
|
@ -16,10 +16,9 @@
|
||||||
#define LIGHT_POINT 1
|
#define LIGHT_POINT 1
|
||||||
|
|
||||||
struct MaterialProperty {
|
struct MaterialProperty {
|
||||||
int enabled;
|
|
||||||
sampler2D sampler;
|
|
||||||
float value;
|
|
||||||
vec3 color;
|
vec3 color;
|
||||||
|
int useSampler;
|
||||||
|
sampler2D sampler;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Light {
|
struct Light {
|
||||||
|
|
@ -31,8 +30,8 @@ struct Light {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Input vertex attributes (from vertex shader)
|
// Input vertex attributes (from vertex shader)
|
||||||
in vec3 fragPosition;
|
|
||||||
in vec2 fragTexCoord;
|
in vec2 fragTexCoord;
|
||||||
|
in vec3 fragPos;
|
||||||
in vec3 fragNormal;
|
in vec3 fragNormal;
|
||||||
in vec3 fragTangent;
|
in vec3 fragTangent;
|
||||||
in vec3 fragBinormal;
|
in vec3 fragBinormal;
|
||||||
|
|
@ -46,15 +45,14 @@ uniform MaterialProperty occlusion;
|
||||||
uniform MaterialProperty emission;
|
uniform MaterialProperty emission;
|
||||||
uniform MaterialProperty height;
|
uniform MaterialProperty height;
|
||||||
|
|
||||||
|
// Input lighting values
|
||||||
|
uniform Light lights[MAX_LIGHTS];
|
||||||
|
|
||||||
// Input uniform values
|
// Input uniform values
|
||||||
uniform samplerCube irradianceMap;
|
uniform samplerCube irradianceMap;
|
||||||
uniform samplerCube prefilterMap;
|
uniform samplerCube prefilterMap;
|
||||||
uniform sampler2D brdfLUT;
|
uniform sampler2D brdfLUT;
|
||||||
|
|
||||||
// Input lighting values
|
|
||||||
uniform Light lights[MAX_LIGHTS];
|
|
||||||
|
|
||||||
|
|
||||||
// Other uniform values
|
// Other uniform values
|
||||||
uniform int renderMode;
|
uniform int renderMode;
|
||||||
uniform vec3 viewPos;
|
uniform vec3 viewPos;
|
||||||
|
|
@ -66,6 +64,7 @@ const float PI = 3.14159265359;
|
||||||
// Output fragment color
|
// Output fragment color
|
||||||
out vec4 finalColor;
|
out vec4 finalColor;
|
||||||
|
|
||||||
|
vec3 ComputeMaterialProperty(MaterialProperty property);
|
||||||
float DistributionGGX(vec3 N, vec3 H, float roughness);
|
float DistributionGGX(vec3 N, vec3 H, float roughness);
|
||||||
float GeometrySchlickGGX(float NdotV, float roughness);
|
float GeometrySchlickGGX(float NdotV, float roughness);
|
||||||
float GeometrySmith(vec3 N, vec3 V, vec3 L, float roughness);
|
float GeometrySmith(vec3 N, vec3 V, vec3 L, float roughness);
|
||||||
|
|
@ -73,6 +72,12 @@ vec3 fresnelSchlick(float cosTheta, vec3 F0);
|
||||||
vec3 fresnelSchlickRoughness(float cosTheta, vec3 F0, float roughness);
|
vec3 fresnelSchlickRoughness(float cosTheta, vec3 F0, float roughness);
|
||||||
vec2 ParallaxMapping(vec2 texCoords, vec3 viewDir);
|
vec2 ParallaxMapping(vec2 texCoords, vec3 viewDir);
|
||||||
|
|
||||||
|
vec3 ComputeMaterialProperty(MaterialProperty property)
|
||||||
|
{
|
||||||
|
if (property.useSampler == 1) return texture(property.sampler, texCoord).rgb;
|
||||||
|
else return property.color;
|
||||||
|
}
|
||||||
|
|
||||||
float DistributionGGX(vec3 N, vec3 H, float roughness)
|
float DistributionGGX(vec3 N, vec3 H, float roughness)
|
||||||
{
|
{
|
||||||
float a = roughness*roughness;
|
float a = roughness*roughness;
|
||||||
|
|
@ -97,7 +102,6 @@ float GeometrySchlickGGX(float NdotV, float roughness)
|
||||||
|
|
||||||
return nom/denom;
|
return nom/denom;
|
||||||
}
|
}
|
||||||
|
|
||||||
float GeometrySmith(vec3 N, vec3 V, vec3 L, float roughness)
|
float GeometrySmith(vec3 N, vec3 V, vec3 L, float roughness)
|
||||||
{
|
{
|
||||||
float NdotV = max(dot(N, V), 0.0);
|
float NdotV = max(dot(N, V), 0.0);
|
||||||
|
|
@ -169,25 +173,25 @@ void main()
|
||||||
|
|
||||||
// Calculate lighting required attributes
|
// Calculate lighting required attributes
|
||||||
vec3 normal = normalize(fragNormal);
|
vec3 normal = normalize(fragNormal);
|
||||||
vec3 view = normalize(viewPos - fragPosition);
|
vec3 view = normalize(viewPos - fragPos);
|
||||||
vec3 refl = reflect(-view, normal);
|
vec3 refl = reflect(-view, normal);
|
||||||
|
|
||||||
// Check if parallax mapping is enabled and calculate texture coordinates to use based on height map
|
// Check if parallax mapping is enabled and calculate texture coordinates to use based on height map
|
||||||
if (height.enabled == 1) texCoord = ParallaxMapping(fragTexCoord, view);
|
if (height.useSampler == 1) texCoord = ParallaxMapping(fragTexCoord, view);
|
||||||
else texCoord = fragTexCoord; // Use default texture coordinates
|
else texCoord = fragTexCoord; // Use default texture coordinates
|
||||||
|
|
||||||
// Fetch material values from texture sampler or color attributes
|
// Fetch material values from texture sampler or color attributes
|
||||||
vec3 color = pow(texture(albedo.sampler, texCoord).rgb, vec3(2.2));
|
vec3 color = ComputeMaterialProperty(albedo);
|
||||||
vec3 metal = texture(metalness.sampler, texCoord).rgb;
|
vec3 metal = ComputeMaterialProperty(metalness);
|
||||||
vec3 rough = texture(roughness.sampler, texCoord).rgb;
|
vec3 rough = ComputeMaterialProperty(roughness);
|
||||||
vec3 emiss = vec3(0);//texture(emission.sampler, texCoord).rgb;
|
vec3 emiss = ComputeMaterialProperty(emission);
|
||||||
vec3 ao = texture(occlusion.sampler, texCoord).rgb;
|
vec3 ao = ComputeMaterialProperty(occlusion);
|
||||||
|
|
||||||
// Check if normal mapping is enabled
|
// Check if normal mapping is enabled
|
||||||
if (normals.enabled == 1)
|
if (normals.useSampler == 1)
|
||||||
{
|
{
|
||||||
// Fetch normal map color and transform lighting values to tangent space
|
// Fetch normal map color and transform lighting values to tangent space
|
||||||
normal = texture(normals.sampler, texCoord).rgb; //ComputeMaterialProperty(normals);
|
normal = ComputeMaterialProperty(normals);
|
||||||
normal = normalize(normal*2.0 - 1.0);
|
normal = normalize(normal*2.0 - 1.0);
|
||||||
normal = normalize(normal*TBN);
|
normal = normalize(normal*TBN);
|
||||||
|
|
||||||
|
|
@ -203,7 +207,6 @@ void main()
|
||||||
vec3 Lo = vec3(0.0);
|
vec3 Lo = vec3(0.0);
|
||||||
vec3 lightDot = vec3(0.0);
|
vec3 lightDot = vec3(0.0);
|
||||||
|
|
||||||
/*
|
|
||||||
for (int i = 0; i < MAX_LIGHTS; i++)
|
for (int i = 0; i < MAX_LIGHTS; i++)
|
||||||
{
|
{
|
||||||
if (lights[i].enabled == 1)
|
if (lights[i].enabled == 1)
|
||||||
|
|
@ -214,8 +217,8 @@ void main()
|
||||||
if (lights[i].type == LIGHT_DIRECTIONAL) light = -normalize(lights[i].target - lights[i].position);
|
if (lights[i].type == LIGHT_DIRECTIONAL) light = -normalize(lights[i].target - lights[i].position);
|
||||||
else if (lights[i].type == LIGHT_POINT)
|
else if (lights[i].type == LIGHT_POINT)
|
||||||
{
|
{
|
||||||
light = normalize(lights[i].position - fragPosition);
|
light = normalize(lights[i].position - fragPos);
|
||||||
float distance = length(lights[i].position - fragPosition);
|
float distance = length(lights[i].position - fragPos);
|
||||||
float attenuation = 1.0/(distance*distance);
|
float attenuation = 1.0/(distance*distance);
|
||||||
radiance *= attenuation;
|
radiance *= attenuation;
|
||||||
}
|
}
|
||||||
|
|
@ -245,7 +248,6 @@ void main()
|
||||||
lightDot += radiance*NdotL + brdf*lights[i].color.a;
|
lightDot += radiance*NdotL + brdf*lights[i].color.a;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
// Calculate ambient lighting using IBL
|
// Calculate ambient lighting using IBL
|
||||||
vec3 F = fresnelSchlickRoughness(max(dot(normal, view), 0.0), F0, rough.r);
|
vec3 F = fresnelSchlickRoughness(max(dot(normal, view), 0.0), F0, rough.r);
|
||||||
|
|
@ -267,7 +269,6 @@ void main()
|
||||||
|
|
||||||
// Calculate fragment color based on render mode
|
// Calculate fragment color based on render mode
|
||||||
vec3 fragmentColor = ambient + Lo + emiss; // Physically Based Rendering
|
vec3 fragmentColor = ambient + Lo + emiss; // Physically Based Rendering
|
||||||
|
|
||||||
if (renderMode == 1) fragmentColor = color; // Albedo
|
if (renderMode == 1) fragmentColor = color; // Albedo
|
||||||
else if (renderMode == 2) fragmentColor = normal; // Normals
|
else if (renderMode == 2) fragmentColor = normal; // Normals
|
||||||
else if (renderMode == 3) fragmentColor = metal; // Metalness
|
else if (renderMode == 3) fragmentColor = metal; // Metalness
|
||||||
|
|
@ -286,5 +287,5 @@ void main()
|
||||||
fragmentColor = pow(fragmentColor, vec3(1.0/2.2));
|
fragmentColor = pow(fragmentColor, vec3(1.0/2.2));
|
||||||
|
|
||||||
// Calculate final fragment color
|
// Calculate final fragment color
|
||||||
finalColor = vec4(fragmentColor, 1.0); // It works, so texture is correctly binded!
|
finalColor = vec4(fragmentColor, 1.0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user