Dynamic ReflectFactor through Shilick's approximation of Fresnel's equation
This commit is contained in:
parent
1978e466dd
commit
76f320e956
@ -110,8 +110,7 @@ void MyGlWindow::shaderSetup()
|
|||||||
shaders["Toon"]->uniformFlags &= ~ShaderFlags::SHINE_FLAG;
|
shaders["Toon"]->uniformFlags &= ~ShaderFlags::SHINE_FLAG;
|
||||||
|
|
||||||
shaders["Skybox"] = new Shader("skybox.vert", "skybox.frag");
|
shaders["Skybox"] = new Shader("skybox.vert", "skybox.frag");
|
||||||
shaders["Skybox"]->uniformFlags = MVP_FLAG | MODEL_MATRIX_FLAG | SKYBOX_TEX_FLAG;
|
shaders["Skybox"]->uniformFlags = MVP_FLAG | MODEL_MATRIX_FLAG | SKYBOX_TEX_FLAG;
|
||||||
shaders["Skybox"]->addUniform("ReflectFactor", (float)0.1);
|
|
||||||
shaders["Skybox"]->addUniform("RefractionIndex", glm::vec3(0.65, 0.67, 0.69));
|
shaders["Skybox"]->addUniform("RefractionIndex", glm::vec3(0.65, 0.67, 0.69));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,19 +8,21 @@ in vec3 refractDir_R;
|
|||||||
in vec3 refractDir_G;
|
in vec3 refractDir_G;
|
||||||
in vec3 refractDir_B;
|
in vec3 refractDir_B;
|
||||||
|
|
||||||
uniform float ReflectFactor;
|
in float reflectFactor;
|
||||||
uniform bool DrawSkyBox;
|
uniform bool DrawSkyBox;
|
||||||
uniform samplerCube CubeMapTex;
|
uniform samplerCube CubeMapTex;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec4 reflectColor = texture(CubeMapTex, reflectDir);
|
vec4 reflectColor = texture(CubeMapTex, reflectDir);
|
||||||
float refractColor_R = texture(CubeMapTex, refractDir_R).r;
|
|
||||||
float refractColor_G = texture(CubeMapTex, refractDir_G).g;
|
|
||||||
float refractColor_B = texture(CubeMapTex, refractDir_B).b;
|
|
||||||
vec4 refractColor = vec4(refractColor_R, refractColor_G, refractColor_B, 1);
|
|
||||||
if (DrawSkyBox == true)
|
if (DrawSkyBox == true)
|
||||||
FragColors = reflectColor;
|
FragColors = reflectColor;
|
||||||
else
|
else
|
||||||
FragColors = vec4(mix(refractColor, reflectColor, ReflectFactor));
|
{
|
||||||
|
float refractColor_R = texture(CubeMapTex, refractDir_R).r;
|
||||||
|
float refractColor_G = texture(CubeMapTex, refractDir_G).g;
|
||||||
|
float refractColor_B = texture(CubeMapTex, refractDir_B).b;
|
||||||
|
vec4 refractColor = vec4(refractColor_R, refractColor_G, refractColor_B, 1);
|
||||||
|
FragColors = vec4(mix(refractColor, reflectColor, reflectFactor));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,6 +6,8 @@ layout(location=2) in vec3 v_color;
|
|||||||
layout(location=3) in vec2 v_texmap;
|
layout(location=3) in vec2 v_texmap;
|
||||||
|
|
||||||
out vec3 reflectDir;
|
out vec3 reflectDir;
|
||||||
|
out float reflectFactor;
|
||||||
|
|
||||||
out vec3 refractDir_R;
|
out vec3 refractDir_R;
|
||||||
out vec3 refractDir_G;
|
out vec3 refractDir_G;
|
||||||
out vec3 refractDir_B;
|
out vec3 refractDir_B;
|
||||||
@ -28,6 +30,10 @@ void main(void)
|
|||||||
vec3 P = (ModelMatrix * vec4(coord3d, 1)).xyz;
|
vec3 P = (ModelMatrix * vec4(coord3d, 1)).xyz;
|
||||||
vec3 N = normalize(ModelMatrix * vec4(v_normal, 1)).xyz;
|
vec3 N = normalize(ModelMatrix * vec4(v_normal, 1)).xyz;
|
||||||
vec3 V = normalize(WorldCamPos - coord3d);
|
vec3 V = normalize(WorldCamPos - coord3d);
|
||||||
|
|
||||||
|
float R0 = pow(1 - 1.5,2) / pow(1 + 1.5, 2);
|
||||||
|
reflectFactor = R0 + (1 - R0) * pow(1 - dot(V, N), 5);
|
||||||
|
|
||||||
reflectDir = reflect(-V, N);
|
reflectDir = reflect(-V, N);
|
||||||
refractDir_R = refract(-V, N, RefractionIndex.r);
|
refractDir_R = refract(-V, N, RefractionIndex.r);
|
||||||
refractDir_G = refract(-V, N, RefractionIndex.g);
|
refractDir_G = refract(-V, N, RefractionIndex.g);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user