końcowa wersja chmur wraz z parametrami do zmiany

This commit is contained in:
sasankasa 2024-02-04 12:42:23 +01:00
parent 30d796fe05
commit 8b2749c7e3
3 changed files with 21 additions and 57 deletions

View File

@ -20,13 +20,13 @@ uniform float roughness; //pbr
uniform float exposition; //pbr
uniform float u_time;
uniform float cloudLight;
uniform float cloudIntensity;
uniform float cloudSpeed;
in vec3 vecNormal;
in vec3 worldPos;
in vec3 vecNormalClouds;
in vec3 worldPosClouds;
in vec2 vtc;
in vec2 vtcNoise;
out vec4 outColor;
@ -149,29 +149,22 @@ float fbm (in vec2 st) {
return value;
}
vec4 noiseColor(float time) {
float cloudIntensity = 15.0;
vec4 noiseColor() {
vec2 st = vtc.xy;
vec2 mirroredSt = vec2(1.0 - st.x, st.y);
// Adjust animation to be boundary-aware
float timeOffset = time * 0.07;
float timeOffset = u_time * cloudSpeed;
st.x -= timeOffset;
mirroredSt.x += timeOffset; // Inverse direction for mirrored effect
// Ensure wrapping or clamping based on your texture coordinates' expectations
st.x = fract(st.x);
mirroredSt.x = fract(mirroredSt.x);
// Calculate cloud patterns
vec3 color = vec3(fbm(st * cloudIntensity));
vec3 mirroredColor = vec3(fbm(mirroredSt * cloudIntensity));
// Dynamic gradient based on X coordinate, ensuring smooth transition
float blend = smoothstep(0.45, 0.55, st.x); // Adjust these values as needed
float blend = smoothstep(0.45, 0.55, st.x);
// Blend based on the dynamic gradient
vec3 finalColor = mix(color, mirroredColor, blend);
vec4 noiseColor = vec4(finalColor, 1.0);
@ -182,19 +175,17 @@ vec4 noiseColor(float time) {
void main() {
vec3 normal = normalize(vecNormal);
vec3 normalClouds = normalize(vecNormalClouds);
vec3 viewDir = normalize(cameraPos - worldPos);
vec3 lightDir = normalize(lightPos - worldPos);
vec3 lightDirClouds = normalize(lightPos - worldPosClouds);
vec4 textureColor = texture2D(colorTexture, vtc);
float diffuse = max(0, dot(normal, lightDir));
//float diffuseClouds = max(0, dot(normalClouds, lightDir));
vec3 distance = lightColor / pow(length(lightPos - worldPos), 2.0) * 300;
vec3 toneMappedColor = toneMapping(vec3(textureColor) * min(1, AMBIENT + diffuse) * distance);
//gamma correction
//toneMappedColor = pow(toneMappedColor, vec3(1.0/2.2));
@ -208,11 +199,9 @@ void main() {
textureColor = vec4(vec3(1.0) - exp(-illumination * exposition), 1);
vec4 noiseColor = noiseColor(u_time) * min(1, AMBIENT + diffuse);
vec4 noiseColor = noiseColor() * min(1, AMBIENT + diffuse) * vec4(lightColor, 0.0) / cloudLight;
vec3 mixedColor = mix(textureColor.rgb, noiseColor.rgb, noiseColor.r);
//outColor = vec4(mixedColor, 1.0);
outColor = vec4(mixedColor * min(1, AMBIENT + diffuse), 1.0);
}

View File

@ -9,16 +9,10 @@ layout(location = 4) in vec3 vertexBitangent;
uniform mat4 transformation;
uniform mat4 modelMatrix;
uniform mat4 noiseTransformation;
uniform mat4 noiseMatrix;
out vec3 vecNormal;
out vec3 worldPos;
out vec3 vecNormalClouds;
out vec3 worldPosClouds;
out vec2 vtc;
out vec2 vtcNoise;
uniform vec3 lightPos;
uniform vec3 cameraPos;
@ -33,13 +27,9 @@ void main()
worldPos = (modelMatrix * vec4(vertexPosition, 1)).xyz;
vecNormal = (modelMatrix * vec4(vertexNormal, 0)).xyz;
worldPosClouds = (noiseMatrix * vec4(vertexPosition, 1)).xyz;
vecNormalClouds = (noiseMatrix * vec4(vertexNormal, 0)).xyz;
gl_Position = transformation * vec4(vertexPosition, 1.0);
vtc = vec2(vertexTexCoord.x, 1.0 - vertexTexCoord.y);
vtcNoise = vec2(vertexTexCoord.x, 1.0 - vertexTexCoord.y);
vec3 w_tangent = normalize(mat3(modelMatrix) * vertexTangent);
vec3 w_bitangent = normalize(mat3(modelMatrix) * vertexBitangent);

View File

@ -73,6 +73,10 @@ int HDR_HEIGHT = 1024;
float lightPower = 10.f;
glm::vec3 lightColor = glm::vec3(lightPower, lightPower, lightPower);
float cloudLight = 20.f;
float cloudIntensity = 15.f;
float cloudSpeed = 0.07f;
glm::mat4 createCameraMatrix() {
glm::vec3 cameraSide = glm::normalize(glm::cross(cameraDir, glm::vec3(0.f, 1.f, 0.f)));
glm::vec3 cameraUp = glm::normalize(glm::cross(cameraSide, cameraDir));
@ -189,16 +193,13 @@ void drawSkyBox(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint text
glUseProgram(0);
}
void drawObjectPBR(Core::RenderContext& context, glm::mat4 modelMatrix, glm::mat4 noiseMatrix, GLuint texture, float roughness, float metallic, float time) {
void drawObjectPBR(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint texture, float roughness, float metallic) {
glUseProgram(programPbr);
Core::SetActiveTexture(texture, "colorTexture", programPbr, 0);
glm::mat4 viewProjectionMatrix = createPerspectiveMatrix() * createCameraMatrix();
glm::mat4 transformation = viewProjectionMatrix * modelMatrix;
glm::mat4 noiseTransformation = viewProjectionMatrix * noiseMatrix;
glUniformMatrix4fv(glGetUniformLocation(programPbr, "transformation"), 1, GL_FALSE, (float*)&transformation);
glUniformMatrix4fv(glGetUniformLocation(programPbr, "noiseTransformation"), 1, GL_FALSE, (float*)&transformation);
glUniformMatrix4fv(glGetUniformLocation(programPbr, "modelMatrix"), 1, GL_FALSE, (float*)&modelMatrix);
glUniformMatrix4fv(glGetUniformLocation(programPbr, "noiseMatrix"), 1, GL_FALSE, (float*)&noiseMatrix);
glUniform1f(glGetUniformLocation(programPbr, "exposition"), lightPower);
@ -212,27 +213,17 @@ void drawObjectPBR(Core::RenderContext& context, glm::mat4 modelMatrix, glm::mat
glUniform3f(glGetUniformLocation(programPbr, "lightPos"), sunPos.x, sunPos.y, sunPos.z);
glUniform3f(glGetUniformLocation(programPbr, "lightColor"), lightColor.x, lightColor.y, lightColor.z);
float time = glfwGetTime();
glUniform1f(glGetUniformLocation(programPbr, "u_time"), time);
glUniform1f(glGetUniformLocation(programPbr, "cloudLight"), cloudLight);
glUniform1f(glGetUniformLocation(programPbr, "cloudIntensity"), cloudIntensity);
glUniform1f(glGetUniformLocation(programPbr, "cloudSpeed"), cloudSpeed);
Core::DrawContext(context);
glUseProgram(0);
}
void drawObjectNoise(Core::RenderContext& context, glm::mat4 modelMatrix, float time) {
glUseProgram(programNoise);
glm::mat4 viewProjectionMatrix = createPerspectiveMatrix() * createCameraMatrix();
glm::mat4 transformation = viewProjectionMatrix * modelMatrix;
glUniformMatrix4fv(glGetUniformLocation(programNoise, "transformation"), 1, GL_FALSE, (float*)&transformation);
glUniformMatrix4fv(glGetUniformLocation(programNoise, "modelMatrix"), 1, GL_FALSE, (float*)&modelMatrix);
glUniform1f(glGetUniformLocation(programNoise, "u_time"), time);
Core::DrawContext(context);
glUseProgram(0);
}
void renderScene(GLFWwindow* window) {
glClearColor(0.5f, 0.0f, 0.25f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
@ -244,13 +235,9 @@ void renderScene(GLFWwindow* window) {
glm::mat4 planetTranslate = glm::translate(planetPos);
glm::mat4 planetMatrix = planetTranslate * planetRotate * planetScale;
glm::mat4 noiseMatrix = planetTranslate * planetScale;
glm::mat4 cloudScale = glm::scale(glm::vec3(planetSize * 1.05f));
//drawPlanet(sphereContext, planetTranslate * planetRotate * planetScale, planetTex);
drawObjectPBR(sphereContext, planetMatrix, noiseMatrix, planetTex, planetRough, planetMetal, time);
//drawObjectNoise(sphereContext, planetTranslate * planetRotate * cloudScale, time);
//rysowanie planety
drawObjectPBR(sphereContext, planetMatrix, planetTex, planetRough, planetMetal);
//rysowanie słońca
glm::mat4 sunScale = glm::scale(glm::vec3(sunSize));
@ -299,7 +286,6 @@ void init(GLFWwindow* window) {
programPbr = shaderLoader.CreateProgram("shaders/shader_pbr.vert", "shaders/shader_pbr.frag");
programSun = shaderLoader.CreateProgram("shaders/shader_sun.vert", "shaders/shader_sun.frag");
programSkyBox = shaderLoader.CreateProgram("shaders/shader_skybox.vert", "shaders/shader_skybox.frag");
programNoise = shaderLoader.CreateProgram("shaders/shader_pbr.vert", "shaders/shader_noise.frag");
loadModelToContext("./models/sphere.obj", sphereContext);
loadModelToContext("./models/cube.obj", cubeContext);
@ -316,7 +302,6 @@ void shutdown(GLFWwindow* window) {
shaderLoader.DeleteProgram(programPbr);
shaderLoader.DeleteProgram(programSun);
shaderLoader.DeleteProgram(programSkyBox);
shaderLoader.DeleteProgram(programNoise);
}
//obsluga wejscia