Dynamic ReflectFactor through Shilick's approximation of Fresnel's equation
This commit is contained in:
parent
1978e466dd
commit
76f320e956
@ -111,7 +111,6 @@ void MyGlWindow::shaderSetup()
|
||||
|
||||
shaders["Skybox"] = new Shader("skybox.vert", "skybox.frag");
|
||||
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));
|
||||
|
||||
}
|
||||
|
||||
@ -8,19 +8,21 @@ in vec3 refractDir_R;
|
||||
in vec3 refractDir_G;
|
||||
in vec3 refractDir_B;
|
||||
|
||||
uniform float ReflectFactor;
|
||||
in float reflectFactor;
|
||||
uniform bool DrawSkyBox;
|
||||
uniform samplerCube CubeMapTex;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 reflectColor = texture(CubeMapTex, reflectDir);
|
||||
if (DrawSkyBox == true)
|
||||
FragColors = reflectColor;
|
||||
else
|
||||
{
|
||||
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)
|
||||
FragColors = reflectColor;
|
||||
else
|
||||
FragColors = vec4(mix(refractColor, reflectColor, ReflectFactor));
|
||||
FragColors = vec4(mix(refractColor, reflectColor, reflectFactor));
|
||||
}
|
||||
}
|
||||
|
||||
@ -6,6 +6,8 @@ layout(location=2) in vec3 v_color;
|
||||
layout(location=3) in vec2 v_texmap;
|
||||
|
||||
out vec3 reflectDir;
|
||||
out float reflectFactor;
|
||||
|
||||
out vec3 refractDir_R;
|
||||
out vec3 refractDir_G;
|
||||
out vec3 refractDir_B;
|
||||
@ -28,6 +30,10 @@ void main(void)
|
||||
vec3 P = (ModelMatrix * vec4(coord3d, 1)).xyz;
|
||||
vec3 N = normalize(ModelMatrix * vec4(v_normal, 1)).xyz;
|
||||
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);
|
||||
refractDir_R = refract(-V, N, RefractionIndex.r);
|
||||
refractDir_G = refract(-V, N, RefractionIndex.g);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user