change bubble shaders

This commit is contained in:
Thyme1 2022-01-02 00:03:53 +01:00
parent 78dbab04f5
commit 21615e0296
9 changed files with 72 additions and 9 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 304 KiB

After

Width:  |  Height:  |  Size: 723 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 251 KiB

After

Width:  |  Height:  |  Size: 274 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 275 KiB

After

Width:  |  Height:  |  Size: 462 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 288 KiB

After

Width:  |  Height:  |  Size: 588 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 311 KiB

After

Width:  |  Height:  |  Size: 525 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 346 KiB

After

Width:  |  Height:  |  Size: 338 KiB

View File

@ -1,17 +1,53 @@
#version 330 core
in vec3 fragPos;
in vec3 v_refraction;
in vec3 v_reflection;
in float v_fresnel;
in vec3 fragPos;
in vec3 interpNormal;
in vec3 TexCoords;
uniform vec3 cameraPos;
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));
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));
gl_FragColor = vec4(texture(skybox, R).rgb,1.0);
vec4 refractionColor = texture( skybox, normalize( v_refraction ) );
vec4 reflectionColor = texture( skybox, normalize( v_reflection ) );
gl_FragColor = vec4(mix( refractionColor, reflectionColor, v_fresnel ).rgba);
}

View File

@ -4,15 +4,42 @@ layout(location = 1) in vec3 vertexNormal;
out vec3 interpNormal;
out vec3 fragPos;
out vec3 TexCoords;
out vec3 incident;
out float deep;
out vec3 v_reflection;
out vec3 v_refraction;
out float v_fresnel;
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));
void main()
{
interpNormal = mat3(transpose(inverse(modelMatrix))) * vertexNormal;
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));
gl_Position = modelViewProjectionMatrix * vec4(vertexPosition, 1.0);
TexCoords = fragPos;
deep = vertexPosition.y;
}

View File

@ -379,7 +379,7 @@ void renderScene()
glm::mat4 bubbleInitialTransformation = glm::translate(glm::vec3(0, -0.5, -0.4)) * glm::rotate(glm::radians(180.0f), glm::vec3(0, 1, 0)) * glm::scale(glm::vec3(0.5f));
//drawObjectTexture(bubbleContext, bubbleInitialTransformation, textureBubble, cubeProgram);
drawObjectTexture(bubbleContext, bubbleInitialTransformation, cubemapTexture, cubeProgram);
glm::vec3 change1 = glm::vec3(0, 3, 0);