Added refraction to the skybox shader
This commit is contained in:
parent
91ccda04e4
commit
0ca64e14cc
@ -110,9 +110,9 @@ void MyGlWindow::shaderSetup()
|
||||
shaders["Toon"]->uniformFlags &= ~ShaderFlags::SHINE_FLAG;
|
||||
|
||||
shaders["Skybox"] = new Shader("skybox.vert", "skybox.frag");
|
||||
shaders["Skybox"]->uniformFlags = MVP_FLAG | KA_FLAG | MODEL_MATRIX_FLAG | SKYBOX_TEX_FLAG;
|
||||
shaders["Skybox"]->mat.enabled = true;
|
||||
shaders["Skybox"]->mat.ka = glm::vec3(0.4, 0.4, 0.4);
|
||||
shaders["Skybox"]->uniformFlags = MVP_FLAG | MODEL_MATRIX_FLAG | SKYBOX_TEX_FLAG;
|
||||
shaders["Skybox"]->addUniform("ReflectFactor", (float)0.1);
|
||||
shaders["Skybox"]->addUniform("RefractionIndex", (float)0.95);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -23,7 +23,7 @@ enum ShaderFlags
|
||||
MODELVIEW_FLAG = 64,
|
||||
LIGHTS_FLAG = 128,
|
||||
MODEL_MATRIX_FLAG = 256,
|
||||
SKYBOX_TEX_FLAG = 512
|
||||
SKYBOX_TEX_FLAG = 512,
|
||||
};
|
||||
|
||||
class Shader
|
||||
|
||||
@ -99,7 +99,6 @@ void Skybox::initialize(std::string skybox_dir, Shader *sky)
|
||||
sky->enable();
|
||||
sky->addUniform("DrawSkyBox", (int)GL_FALSE);
|
||||
sky->addUniform("CubeMapTex", (int)0);
|
||||
sky->addUniform("ReflectFactor", (float)0.85);
|
||||
sky->disable();
|
||||
}
|
||||
|
||||
|
||||
@ -46,5 +46,5 @@ Collapsed=0
|
||||
[Window][First Window]
|
||||
Pos=20,20
|
||||
Size=357,188
|
||||
Collapsed=0
|
||||
Collapsed=1
|
||||
|
||||
|
||||
@ -3,21 +3,18 @@
|
||||
out vec4 FragColors;
|
||||
|
||||
in vec3 reflectDir;
|
||||
in vec3 refractDir;
|
||||
|
||||
uniform vec3 Ka;
|
||||
uniform float ReflectFactor;
|
||||
uniform bool DrawSkyBox;
|
||||
uniform samplerCube CubeMapTex;
|
||||
|
||||
float rand(vec2 co){
|
||||
return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 texColor = texture(CubeMapTex, reflectDir);
|
||||
vec4 reflectColor = texture(CubeMapTex, reflectDir);
|
||||
vec4 refractColor = texture(CubeMapTex, refractDir);
|
||||
if (DrawSkyBox == true)
|
||||
FragColors = texColor;
|
||||
FragColors = reflectColor;
|
||||
else
|
||||
FragColors = vec4(mix(Ka, texColor.xyz, ReflectFactor), 1);
|
||||
FragColors = vec4(mix(refractColor, reflectColor, ReflectFactor));
|
||||
}
|
||||
|
||||
@ -6,7 +6,9 @@ layout(location=2) in vec3 v_color;
|
||||
layout(location=3) in vec2 v_texmap;
|
||||
|
||||
out vec3 reflectDir;
|
||||
out vec3 refractDir;
|
||||
|
||||
uniform float RefractionIndex;
|
||||
uniform mat4 ModelMatrix;
|
||||
uniform mat4 mvp;
|
||||
uniform bool DrawSkyBox;
|
||||
@ -25,6 +27,7 @@ void main(void)
|
||||
vec3 N = normalize(ModelMatrix * vec4(v_normal, 1)).xyz;
|
||||
vec3 V = normalize(WorldCamPos - coord3d);
|
||||
reflectDir = reflect(-V, N);
|
||||
refractDir = refract(-V, N, RefractionIndex);
|
||||
}
|
||||
|
||||
gl_Position = mvp * vec4(coord3d, 1.0f);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user