Support FresnelSchlick factor.
This commit is contained in:
parent
858c8c7605
commit
e00ce85d7c
@ -13,6 +13,7 @@ out vec4 Diffuse;
|
||||
out vec4 Specular;
|
||||
|
||||
vec3 DecodeNormal(vec2 n);
|
||||
vec3 getSpecular(vec3 normal, vec3 eyedir, vec3 lightdir, vec3 color, float roughness);
|
||||
|
||||
void main()
|
||||
{
|
||||
@ -36,13 +37,9 @@ void main()
|
||||
|
||||
// Light Direction
|
||||
vec3 L = -normalize(xpos.xyz - light_pos);
|
||||
// Half Light View direction
|
||||
vec3 H = normalize(eyedir + L);
|
||||
|
||||
float NdotL = max(0., dot(norm, L));
|
||||
float NdotH = max(0., dot(norm, H));
|
||||
float normalisationFactor = (roughness + 2.) / 8.;
|
||||
|
||||
Diffuse = vec4(NdotL * light_col * att, 1.);
|
||||
Specular = vec4(pow(NdotH, roughness) * light_col * NdotL * spec_att * normalisationFactor, 1.);
|
||||
Specular = vec4(getSpecular(norm, eyedir, L, light_col, roughness) * NdotL * spec_att, 1.);
|
||||
}
|
||||
|
@ -20,6 +20,7 @@ varying vec2 uv;
|
||||
|
||||
|
||||
vec3 DecodeNormal(vec2 n);
|
||||
vec3 getSpecular(vec3 normal, vec3 eyedir, vec3 lightdir, vec3 color, float roughness);
|
||||
|
||||
void main() {
|
||||
float z = texture(dtex, uv).x;
|
||||
@ -41,14 +42,10 @@ void main() {
|
||||
|
||||
// Normalized on the cpu
|
||||
vec3 L = direction;
|
||||
// Half Light View direction
|
||||
vec3 H = normalize(eyedir + L);
|
||||
|
||||
float NdotL = max(0., dot(norm, L));
|
||||
float NdotH = max(0., dot(norm, H));
|
||||
|
||||
float normalisationFactor = (roughness + 2.) / 8.;
|
||||
float Specular = pow(NdotH, roughness) * NdotL * normalisationFactor;
|
||||
vec3 Specular = getSpecular(norm, eyedir, L, col, roughness) * NdotL;
|
||||
|
||||
vec3 outcol = NdotL * col;
|
||||
|
||||
@ -62,5 +59,5 @@ void main() {
|
||||
}*/
|
||||
|
||||
Diff = vec4(NdotL * col, 1.);
|
||||
Spec = vec4(Specular * col, 1.);
|
||||
Spec = vec4(Specular, 1.);
|
||||
}
|
||||
|
@ -24,6 +24,7 @@ varying vec2 uv;
|
||||
|
||||
|
||||
vec3 DecodeNormal(vec2 n);
|
||||
vec3 getSpecular(vec3 normal, vec3 eyedir, vec3 lightdir, vec3 color, float roughness);
|
||||
|
||||
float getShadowFactor(vec3 pos, float bias, int index)
|
||||
{
|
||||
@ -69,14 +70,10 @@ void main() {
|
||||
|
||||
// Normalized on the cpu
|
||||
vec3 L = direction;
|
||||
// Half Light View direction
|
||||
vec3 H = normalize(eyedir + L);
|
||||
|
||||
float NdotL = max(0., dot(norm, L));
|
||||
float NdotH = max(0., dot(norm, H));
|
||||
|
||||
float normalisationFactor = (roughness + 2.) / 8.;
|
||||
float Specular = pow(NdotH, roughness) * NdotL * normalisationFactor;
|
||||
vec3 Specular = getSpecular(norm, eyedir, L, col, roughness) * NdotL;
|
||||
|
||||
|
||||
vec3 outcol = NdotL * col;
|
||||
@ -118,7 +115,7 @@ void main() {
|
||||
else
|
||||
factor = getShadowFactor(xpos.xyz, bias, 3);
|
||||
Diff = vec4(factor * NdotL * col, 1.);
|
||||
Spec = vec4(factor * Specular * col, 1.);
|
||||
Spec = vec4(factor * Specular, 1.);
|
||||
return;
|
||||
|
||||
// float moved = (abs(dx) + abs(dy)) * 0.5;
|
||||
|
11
data/shaders/utils/getSpecular.frag
Normal file
11
data/shaders/utils/getSpecular.frag
Normal file
@ -0,0 +1,11 @@
|
||||
|
||||
|
||||
vec3 getSpecular(vec3 normal, vec3 eyedir, vec3 lightdir, vec3 color, float roughness)
|
||||
{
|
||||
// Half Light View direction
|
||||
vec3 H = normalize(eyedir + lightdir);
|
||||
float NdotH = max(0., dot(normal, H));
|
||||
float normalisationFactor = (roughness + 2.) / 8.;
|
||||
vec3 FresnelSchlick = color + (1.0f - color) * pow(1.0f - max(0., (dot(eyedir, H))), 5);
|
||||
return max(pow(NdotH, roughness) * FresnelSchlick * normalisationFactor, vec3(0.));
|
||||
}
|
@ -1707,6 +1707,7 @@ namespace LightShader
|
||||
Program = LoadProgram(
|
||||
GL_VERTEX_SHADER, file_manager->getAsset("shaders/pointlight.vert").c_str(),
|
||||
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/decodeNormal.frag").c_str(),
|
||||
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getSpecular.frag").c_str(),
|
||||
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/pointlight.frag").c_str());
|
||||
attrib_Position = glGetAttribLocation(Program, "Position");
|
||||
attrib_Color = glGetAttribLocation(Program, "Color");
|
||||
@ -2042,6 +2043,7 @@ namespace FullScreenShader
|
||||
Program = LoadProgram(
|
||||
GL_VERTEX_SHADER, file_manager->getAsset("shaders/screenquad.vert").c_str(),
|
||||
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/decodeNormal.frag").c_str(),
|
||||
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getSpecular.frag").c_str(),
|
||||
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/sunlight.frag").c_str());
|
||||
uniform_ntex = glGetUniformLocation(Program, "ntex");
|
||||
uniform_dtex = glGetUniformLocation(Program, "dtex");
|
||||
@ -2106,6 +2108,7 @@ namespace FullScreenShader
|
||||
Program = LoadProgram(
|
||||
GL_VERTEX_SHADER, file_manager->getAsset("shaders/screenquad.vert").c_str(),
|
||||
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/decodeNormal.frag").c_str(),
|
||||
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getSpecular.frag").c_str(),
|
||||
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/sunlightshadow.frag").c_str());
|
||||
uniform_ntex = glGetUniformLocation(Program, "ntex");
|
||||
uniform_dtex = glGetUniformLocation(Program, "dtex");
|
||||
|
Loading…
Reference in New Issue
Block a user