45 lines
1022 B
GLSL
45 lines
1022 B
GLSL
#version 440
|
|
|
|
layout(location=0) in vec3 coord3d;
|
|
layout(location=1) in vec3 v_normal;
|
|
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;
|
|
|
|
uniform vec3 RefractionIndex;
|
|
uniform mat4 ModelMatrix;
|
|
uniform mat4 mvp;
|
|
uniform bool DrawSkyBox;
|
|
|
|
uniform vec3 WorldCamPos;
|
|
|
|
void main(void)
|
|
{
|
|
|
|
//For drawing a mesh with reflected skybox
|
|
if (DrawSkyBox == true)
|
|
reflectDir = coord3d;
|
|
else
|
|
{
|
|
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);
|
|
refractDir_B = refract(-V, N, RefractionIndex.b);
|
|
}
|
|
|
|
gl_Position = mvp * vec4(coord3d, 1.0f);
|
|
}
|