chmury na obu wersjach planety #9

Merged
s473581 merged 1 commits from clouds into master 2024-02-04 13:32:27 +01:00
3 changed files with 89 additions and 6 deletions

View File

@ -23,6 +23,7 @@ uniform float u_time;
uniform float cloudLight; uniform float cloudLight;
uniform float cloudIntensity; uniform float cloudIntensity;
uniform float cloudSpeed; uniform float cloudSpeed;
uniform float cloudLightness;
in vec3 vecNormal; in vec3 vecNormal;
in vec3 worldPos; in vec3 worldPos;
@ -183,6 +184,7 @@ void main() {
if (atmosphereCheck) if (atmosphereCheck)
textureColor = mix(textureColor, vec4(atmosphereColor / atmosphereDot, 1.0), 0.1); textureColor = mix(textureColor, vec4(atmosphereColor / atmosphereDot, 1.0), 0.1);
float diffuse = max(0, dot(normal, lightDir));
vec3 distance = lightColor / pow(length(lightPos - worldPos), 2.0) * 10; vec3 distance = lightColor / pow(length(lightPos - worldPos), 2.0) * 10;
vec3 toneMappedColor = toneMapping(vec3(textureColor) * distance); vec3 toneMappedColor = toneMapping(vec3(textureColor) * distance);
//gamma correction //gamma correction
@ -198,7 +200,7 @@ void main() {
vec3 pbrColor = vec3(1.0) - exp(-illumination * exposition); vec3 pbrColor = vec3(1.0) - exp(-illumination * exposition);
vec4 noiseColor = noiseColor() * min(1, AMBIENT + diffuse) * vec4(lightColor, 0.0) / cloudLight; vec4 noiseColor = noiseColor() * min(1, AMBIENT + cloudLightness * diffuse) * vec4(lightColor, 0.0) / cloudLight;
vec3 mixedColor = mix(pbrColor.rgb, noiseColor.rgb, noiseColor.r); vec3 mixedColor = mix(pbrColor.rgb, noiseColor.rgb, noiseColor.r);

View File

@ -1,6 +1,7 @@
#version 430 core #version 430 core
float AMBIENT = 0.05; float AMBIENT = 0.05;
float PI = 3.14159;
uniform sampler2D colorTexture; uniform sampler2D colorTexture;
@ -12,6 +13,12 @@ uniform vec3 cameraPos;
uniform bool atmosphereCheck; uniform bool atmosphereCheck;
uniform float u_time;
uniform float cloudLight;
uniform float cloudIntensity;
uniform float cloudSpeed;
uniform float cloudLightness;
in vec3 vecNormal; in vec3 vecNormal;
in vec3 worldPos; in vec3 worldPos;
in vec2 vtc; in vec2 vtc;
@ -25,6 +32,68 @@ vec3 toneMapping(vec3 color)
return mapped; return mapped;
} }
float random (in vec2 st) {
return fract(sin(dot(st.xy,
vec2(12.9898,78.233)))*
43758.5453123);
}
float noise (in vec2 st) {
vec2 i = floor(st);
vec2 f = fract(st);
// Four corners in 2D of a tile
float a = random(i);
float b = random(i + vec2(1.0, 0.0));
float c = random(i + vec2(0.0, 1.0));
float d = random(i + vec2(1.0, 1.0));
vec2 u = f * f * (3.0 - 2.0 * f);
return mix(a, b, u.x) +
(c - a)* u.y * (1.0 - u.x) +
(d - b) * u.x * u.y;
}
#define OCTAVES 6
float fbm (in vec2 st) {
// Initial values
float value = 0.0;
float amplitude = .5;
float frequency = 0.;
//
// Loop of octaves
for (int i = 0; i < OCTAVES; i++) {
value += amplitude * noise(st);
st *= 2.;
amplitude *= .5;
}
return value;
}
vec4 noiseColor() {
vec2 st = vtc.xy;
vec2 mirroredSt = vec2(1.0 - st.x, st.y);
float timeOffset = u_time * cloudSpeed;
st.x -= timeOffset;
mirroredSt.x += timeOffset; // Inverse direction for mirrored effect
st.x = fract(st.x);
mirroredSt.x = fract(mirroredSt.x);
vec3 color = vec3(fbm(st * cloudIntensity));
vec3 mirroredColor = vec3(fbm(mirroredSt * cloudIntensity));
float blend = smoothstep(0.45, 0.55, st.x);
vec3 finalColor = mix(color, mirroredColor, blend);
vec4 noiseColor = vec4(finalColor, 1.0);
return noiseColor;
}
void main() void main()
{ {
vec3 normal = normalize(vecNormal); vec3 normal = normalize(vecNormal);
@ -46,5 +115,9 @@ void main()
//gamma correction //gamma correction
//toneMappedColor = pow(toneMappedColor, vec3(1.0/2.2)); //toneMappedColor = pow(toneMappedColor, vec3(1.0/2.2));
outColor = vec4(toneMappedColor, 1); vec4 noiseColor = noiseColor() * min(1, AMBIENT + cloudLightness) * vec4(lightColor, 0.0) / cloudLight;
vec3 mixedColor = mix(toneMappedColor.rgb, noiseColor.rgb, noiseColor.r);
outColor = vec4(mixedColor, 1.0);
} }

View File

@ -77,6 +77,7 @@ glm::vec3 lightColor = glm::vec3(lightPower, lightPower, lightPower);
float cloudLight = 20.f; float cloudLight = 20.f;
float cloudIntensity = 15.f; float cloudIntensity = 15.f;
float cloudSpeed = 0.07f; float cloudSpeed = 0.07f;
float cloudLightness = 30.f;
glm::mat4 createCameraMatrix() { glm::mat4 createCameraMatrix() {
glm::vec3 cameraSide = glm::normalize(glm::cross(cameraDir, glm::vec3(0.f, 1.f, 0.f))); glm::vec3 cameraSide = glm::normalize(glm::cross(cameraDir, glm::vec3(0.f, 1.f, 0.f)));
@ -167,9 +168,15 @@ void drawPlanetTex(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint t
glUniform3f(glGetUniformLocation(programTex, "lightPos"), sunPos.x, sunPos.y, sunPos.z); glUniform3f(glGetUniformLocation(programTex, "lightPos"), sunPos.x, sunPos.y, sunPos.z);
glUniform3f(glGetUniformLocation(programTex, "lightColor"), lightColor.x, lightColor.y, lightColor.z); glUniform3f(glGetUniformLocation(programTex, "lightColor"), lightColor.x, lightColor.y, lightColor.z);
glUniform3f(glGetUniformLocation(programPbr, "cameraPos"), cameraPos.x, cameraPos.y, cameraPos.z); glUniform3f(glGetUniformLocation(programTex, "cameraPos"), cameraPos.x, cameraPos.y, cameraPos.z);
glUniform1i(glGetUniformLocation(programPbr, "atmosphereCheck"), atmosphereCheck); float time = glfwGetTime();
glUniform1f(glGetUniformLocation(programTex, "u_time"), time);
glUniform1f(glGetUniformLocation(programTex, "cloudLight"), cloudLight);
glUniform1f(glGetUniformLocation(programTex, "cloudIntensity"), cloudIntensity);
glUniform1f(glGetUniformLocation(programTex, "cloudSpeed"), cloudSpeed);
glUniform1f(glGetUniformLocation(programTex, "cloudLightness"), cloudLightness);
glUniform1i(glGetUniformLocation(programTex, "atmosphereCheck"), atmosphereCheck);
Core::DrawContext(context); Core::DrawContext(context);
glUseProgram(0); glUseProgram(0);
@ -200,6 +207,7 @@ void drawPlanetPbr(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint t
glUniform1f(glGetUniformLocation(programPbr, "cloudLight"), cloudLight); glUniform1f(glGetUniformLocation(programPbr, "cloudLight"), cloudLight);
glUniform1f(glGetUniformLocation(programPbr, "cloudIntensity"), cloudIntensity); glUniform1f(glGetUniformLocation(programPbr, "cloudIntensity"), cloudIntensity);
glUniform1f(glGetUniformLocation(programPbr, "cloudSpeed"), cloudSpeed); glUniform1f(glGetUniformLocation(programPbr, "cloudSpeed"), cloudSpeed);
glUniform1f(glGetUniformLocation(programPbr, "cloudLightness"), cloudLightness);
glUniform1i(glGetUniformLocation(programPbr, "atmosphereCheck"), atmosphereCheck); glUniform1i(glGetUniformLocation(programPbr, "atmosphereCheck"), atmosphereCheck);
@ -218,9 +226,9 @@ void drawSun(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint texture
glUniform3f(glGetUniformLocation(programSun, "lightPos"), sunPos.x, sunPos.y, sunPos.z); glUniform3f(glGetUniformLocation(programSun, "lightPos"), sunPos.x, sunPos.y, sunPos.z);
glUniform3f(glGetUniformLocation(programSun, "lightColor"), lightColor.x, lightColor.y, lightColor.z); glUniform3f(glGetUniformLocation(programSun, "lightColor"), lightColor.x, lightColor.y, lightColor.z);
glUniform3f(glGetUniformLocation(programPbr, "cameraPos"), cameraPos.x, cameraPos.y, cameraPos.z); glUniform3f(glGetUniformLocation(programSun, "cameraPos"), cameraPos.x, cameraPos.y, cameraPos.z);
glUniform1i(glGetUniformLocation(programPbr, "atmosphereCheck"), atmosphereCheck); glUniform1i(glGetUniformLocation(programSun, "atmosphereCheck"), atmosphereCheck);
Core::DrawContext(context); Core::DrawContext(context);
glUseProgram(0); glUseProgram(0);