bubble is not upside down

This commit is contained in:
Thyme1 2022-01-02 01:26:44 +01:00
parent 21615e0296
commit fb55f586f5
2 changed files with 13 additions and 80 deletions

View File

@ -1,53 +1,13 @@
#version 330 core
#version 430 compatibility
in vec3 v_refraction;
in vec3 v_reflection;
in float v_fresnel;
in vec3 fragPos;
in vec3 fragPos;
in vec3 interpNormal;
in vec3 incident;
in float deep;
uniform samplerCube skybox;
uniform vec3 lightPos;
uniform vec3 cameraPos;
uniform vec3 lightColor;
uniform vec3 objectColor;
const float etaR = 1.14;
const float etaG = 1.12;
const float etaB = 1.10;
const float F = ((1.0 - etaG) * (1.0 - etaG)) / ((1.0 + etaG) * (1.0 + etaG));
uniform samplerCube skybox;
layout (binding = 0) uniform samplerCube tex_map;
void main()
{
vec3 n = normalize(interpNormal);
vec3 l = normalize(lightPos-fragPos);
vec3 e = normalize(cameraPos-fragPos);
vec3 h = (e+l) / length(e+l);
float ratio = 1.01/1.0;
//
vec3 i = incident;
//float ratio = F + (1.0 - F) * pow(1.0 - dot(-i, n), 2);
vec3 refractR = vec3(vec4(refract(i, n, etaR), 1.0));
vec3 refractG = vec3(vec4(refract(i, n, etaG), 1.0));
vec3 refractB = vec3(vec4(refract(i, n, etaB), 1.0));
vec3 reflectDir = vec3(vec4(reflect(i, n), 1.0));
vec3 I = normalize(fragPos - cameraPos);
// vec3 R = refract(I, normalize(interpNormal),ratio);
vec3 R = reflect(I, normalize(interpNormal));
vec4 refractionColor = texture( skybox, normalize( v_refraction ) );
vec4 reflectionColor = texture( skybox, normalize( v_reflection ) );
gl_FragColor = vec4(mix( refractionColor, reflectionColor, v_fresnel ).rgba);
vec3 r = reflect(normalize(-fragPos), normalize(interpNormal));
gl_FragColor = texture(tex_map, r);
}

View File

@ -1,45 +1,18 @@
#version 330 core
#version 430 compatibility
layout(location = 0) in vec3 vertexPosition;
layout(location = 1) in vec3 vertexNormal;
out vec3 interpNormal;
out vec3 fragPos;
out vec3 incident;
out float deep;
out vec3 v_reflection;
out vec3 v_refraction;
out float v_fresnel;
out vec3 TexCoords;
uniform mat4 modelMatrix;
uniform mat4 modelViewProjectionMatrix;
uniform vec3 viewPos;
// Indices of refraction
const float Air = 1.0;
const float Glass = 4; //1.51714;//4
// Air to glass ratio of the indices of refraction (Eta)
const float Eta = Air / Glass;
// see http://en.wikipedia.org/wiki/Refractive_index Reflectivity
const float R0 = ((Air - Glass) * (Air - Glass)) / ((Air + Glass) * (Air + Glass));
layout (binding = 0) uniform samplerCube tex_map;
void main()
{
vec4 vertex = modelMatrix * vec4( vertexPosition, 1.0 );
vec4 camera = vec4( viewPos, 1.0 );
incident = normalize( vec3( vertex - camera ) );
vec3 norm = mat3(transpose(inverse(modelMatrix))) * vertexNormal;
v_refraction = refract( incident, norm, Eta );
v_reflection = reflect( incident, norm );
v_fresnel = R0 + (1.0 - R0) * pow( (1.0 - dot( -incident, vertexNormal ) ), 5.0);
interpNormal = vertexNormal;
fragPos = vec3(modelMatrix * vec4(vertexPosition, 1.0));
interpNormal = mat3(transpose(inverse(modelMatrix))) * vertexNormal;
fragPos = (modelMatrix * vec4(vertexPosition, 1.0)).xyz;
gl_Position = modelViewProjectionMatrix * vec4(vertexPosition, 1.0);
deep = vertexPosition.y;
}