ulepszenia atmosfery i chmur, dodanie interakcji z chmurami, zmiana tekstury ziemi
This commit is contained in:
parent
6423dfc220
commit
998c91bd1f
@ -19,11 +19,11 @@ uniform vec3 lightColor;
|
||||
|
||||
uniform bool atmosphereCheck;
|
||||
|
||||
uniform float u_time;
|
||||
uniform float cloudLight;
|
||||
uniform float time;
|
||||
|
||||
uniform float cloudIntensity;
|
||||
uniform float cloudSpeed;
|
||||
uniform float cloudLightness;
|
||||
uniform float cloudMotion;
|
||||
uniform float cloudBrightness;
|
||||
|
||||
in vec3 vecNormal;
|
||||
in vec3 worldPos;
|
||||
@ -109,13 +109,15 @@ vec3 toneMapping(vec3 color)
|
||||
return mapped;
|
||||
}
|
||||
|
||||
float random (in vec2 st) {
|
||||
float random (in vec2 st)
|
||||
{
|
||||
return fract(sin(dot(st.xy,
|
||||
vec2(12.9898,78.233)))*
|
||||
43758.5453123);
|
||||
}
|
||||
|
||||
float noise (in vec2 st) {
|
||||
float noise (in vec2 st)
|
||||
{
|
||||
vec2 i = floor(st);
|
||||
vec2 f = fract(st);
|
||||
|
||||
@ -133,7 +135,8 @@ float noise (in vec2 st) {
|
||||
}
|
||||
|
||||
#define OCTAVES 6
|
||||
float fbm (in vec2 st) {
|
||||
float fbm (in vec2 st)
|
||||
{
|
||||
// Initial values
|
||||
float value = 0.0;
|
||||
float amplitude = .5;
|
||||
@ -148,11 +151,12 @@ float fbm (in vec2 st) {
|
||||
return value;
|
||||
}
|
||||
|
||||
vec4 noiseColor() {
|
||||
vec3 noiseColor()
|
||||
{
|
||||
vec2 st = vtc.xy;
|
||||
vec2 mirroredSt = vec2(1.0 - st.x, st.y);
|
||||
|
||||
float timeOffset = u_time * cloudSpeed;
|
||||
float timeOffset = time * cloudMotion;
|
||||
st.x -= timeOffset;
|
||||
mirroredSt.x += timeOffset; // Inverse direction for mirrored effect
|
||||
|
||||
@ -164,45 +168,47 @@ vec4 noiseColor() {
|
||||
|
||||
float blend = smoothstep(0.45, 0.55, st.x);
|
||||
|
||||
vec3 finalColor = mix(color, mirroredColor, blend);
|
||||
|
||||
vec4 noiseColor = vec4(finalColor, 1.0);
|
||||
vec3 noiseColor = mix(color, mirroredColor, blend);
|
||||
|
||||
return noiseColor;
|
||||
}
|
||||
|
||||
void main() {
|
||||
void main()
|
||||
{
|
||||
vec3 normal = normalize(vecNormal);
|
||||
vec3 viewDir = normalize(cameraPos - worldPos);
|
||||
vec3 lightDir = normalize(lightPos - worldPos);
|
||||
|
||||
vec4 textureColor = texture2D(colorTexture, vtc);
|
||||
|
||||
float atmosphereDot = dot(normal, viewDir);
|
||||
vec3 atmosphereColor = vec3(0.04, 0.2, 1.0);
|
||||
vec3 textureColor = texture2D(colorTexture, vtc).rgb;
|
||||
|
||||
if (atmosphereCheck)
|
||||
textureColor = mix(textureColor, vec4(atmosphereColor / atmosphereDot, 1.0), 0.1);
|
||||
{
|
||||
float atmosphereDot = dot(normal, viewDir);
|
||||
vec3 atmosphereColor = vec3(0.0, 0.44, 1.0);
|
||||
textureColor = mix(textureColor, atmosphereColor, pow(1 - atmosphereDot, 3));
|
||||
}
|
||||
|
||||
float diffuse = max(0, dot(normal, lightDir));
|
||||
vec3 distance = lightColor / pow(length(lightPos - worldPos), 2.0) * 10;
|
||||
vec3 toneMappedColor = toneMapping(vec3(textureColor) * distance);
|
||||
vec3 toneMappedColor = toneMapping(textureColor * distance);
|
||||
//gamma correction
|
||||
toneMappedColor = pow(toneMappedColor, vec3(1.0/2.2));
|
||||
|
||||
vec3 ambient = AMBIENT * toneMappedColor;
|
||||
vec3 attenuatedLightColor = lightColor / pow(length(lightPos - worldPos), 2);
|
||||
vec3 illumination;
|
||||
illumination = ambient + PBRLight(lightDir, attenuatedLightColor, normal, viewDir, toneMappedColor);
|
||||
vec3 illumination = ambient + PBRLight(lightDir, attenuatedLightColor, normal, viewDir, toneMappedColor);
|
||||
|
||||
//sun
|
||||
illumination = illumination + PBRLight(sunDir, sunColor, normal, viewDir, toneMappedColor);
|
||||
|
||||
vec3 pbrColor = vec3(1.0) - exp(-illumination * exposition);
|
||||
|
||||
vec4 noiseColor = noiseColor() * min(1, AMBIENT + cloudLightness * diffuse) * vec4(lightColor, 0.0) / cloudLight;
|
||||
vec3 finalColor = pbrColor;
|
||||
|
||||
vec3 mixedColor = mix(pbrColor.rgb, noiseColor.rgb, noiseColor.r);
|
||||
|
||||
outColor = vec4(mixedColor, 1.0);
|
||||
if (atmosphereCheck)
|
||||
{
|
||||
vec3 noiseColor = noiseColor() * min(1, 20.0 * max(0.02, dot(normal, lightDir))) * lightColor * cloudBrightness;
|
||||
finalColor = mix(pbrColor, noiseColor, noiseColor.r);
|
||||
}
|
||||
|
||||
outColor = vec4(finalColor, 1.0);
|
||||
}
|
||||
|
@ -27,16 +27,17 @@ void main()
|
||||
vec3 normal = normalize(vecNormal);
|
||||
vec3 viewDir = normalize(cameraPos - worldPos);
|
||||
|
||||
vec4 textureColor = texture2D(colorTexture, vtc);
|
||||
|
||||
float atmosphereDot = dot(normal, viewDir);
|
||||
vec3 atmosphereColor = vec3(1.0, 0.04, 0.01);
|
||||
vec3 textureColor = texture2D(colorTexture, vtc).rgb;
|
||||
|
||||
if (atmosphereCheck)
|
||||
textureColor = mix(textureColor, vec4(atmosphereColor / atmosphereDot, 1.0), 0.25);
|
||||
{
|
||||
float atmosphereDot = dot(normal, viewDir);
|
||||
vec3 atmosphereColor = vec3(1.0, 0.08, 0.02);
|
||||
textureColor = mix(textureColor, atmosphereColor, pow(1 - atmosphereDot, 3));
|
||||
}
|
||||
|
||||
vec3 distance = lightColor / pow(length(lightPos - worldPos), 2.0) * 25;
|
||||
vec3 toneMappedColor = toneMapping(vec3(textureColor) * distance);
|
||||
vec3 toneMappedColor = toneMapping(textureColor * distance);
|
||||
//gamma correction
|
||||
toneMappedColor = pow(toneMappedColor, vec3(1.0/2.2));
|
||||
|
||||
|
@ -13,11 +13,11 @@ uniform vec3 cameraPos;
|
||||
|
||||
uniform bool atmosphereCheck;
|
||||
|
||||
uniform float u_time;
|
||||
uniform float cloudLight;
|
||||
uniform float time;
|
||||
|
||||
uniform float cloudIntensity;
|
||||
uniform float cloudSpeed;
|
||||
uniform float cloudLightness;
|
||||
uniform float cloudMotion;
|
||||
uniform float cloudBrightness;
|
||||
|
||||
in vec3 vecNormal;
|
||||
in vec3 worldPos;
|
||||
@ -71,11 +71,11 @@ float fbm (in vec2 st) {
|
||||
return value;
|
||||
}
|
||||
|
||||
vec4 noiseColor() {
|
||||
vec3 noiseColor() {
|
||||
vec2 st = vtc.xy;
|
||||
vec2 mirroredSt = vec2(1.0 - st.x, st.y);
|
||||
|
||||
float timeOffset = u_time * cloudSpeed;
|
||||
float timeOffset = time * cloudMotion;
|
||||
st.x -= timeOffset;
|
||||
mirroredSt.x += timeOffset; // Inverse direction for mirrored effect
|
||||
|
||||
@ -87,9 +87,7 @@ vec4 noiseColor() {
|
||||
|
||||
float blend = smoothstep(0.45, 0.55, st.x);
|
||||
|
||||
vec3 finalColor = mix(color, mirroredColor, blend);
|
||||
|
||||
vec4 noiseColor = vec4(finalColor, 1.0);
|
||||
vec3 noiseColor = mix(color, mirroredColor, blend);
|
||||
|
||||
return noiseColor;
|
||||
}
|
||||
@ -102,22 +100,29 @@ void main()
|
||||
|
||||
float diffuse = max(0, dot(normal, lightDir));
|
||||
|
||||
vec4 textureColor = texture2D(colorTexture, vtc);
|
||||
|
||||
float atmosphereDot = dot(normal, viewDir);
|
||||
vec3 atmosphereColor = vec3(0.04, 0.2, 1.0);
|
||||
vec3 textureColor = texture2D(colorTexture, vtc).rgb;
|
||||
|
||||
if (atmosphereCheck)
|
||||
textureColor = mix(textureColor, vec4(atmosphereColor / atmosphereDot, 1.0), 0.05);
|
||||
|
||||
vec3 distance = lightColor / pow(length(lightPos - worldPos), 2.0) * 10000;
|
||||
vec3 toneMappedColor = toneMapping(vec3(textureColor) * min(1, AMBIENT + diffuse) * distance);
|
||||
//gamma correction
|
||||
//toneMappedColor = pow(toneMappedColor, vec3(1.0/2.2));
|
||||
|
||||
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);
|
||||
{
|
||||
float atmosphereDot = dot(normal, viewDir);
|
||||
vec3 atmosphereColor = vec3(0.0, 0.44, 1.0);
|
||||
textureColor = mix(textureColor, atmosphereColor, pow(1 - atmosphereDot, 3));
|
||||
}
|
||||
|
||||
vec3 diffuseColor = textureColor * min(1, AMBIENT + diffuse);
|
||||
|
||||
vec3 distance = lightColor / pow(length(lightPos - worldPos), 2.0) * 1000;
|
||||
vec3 toneMappedColor = toneMapping(diffuseColor * distance);
|
||||
//gamma correction
|
||||
toneMappedColor = pow(toneMappedColor, vec3(1.0/2.2));
|
||||
|
||||
vec3 finalColor = toneMappedColor;
|
||||
|
||||
if (atmosphereCheck)
|
||||
{
|
||||
vec3 noiseColor = noiseColor() * min(1, 20.0 * max(0.02, dot(normal, lightDir))) * lightColor * cloudBrightness;
|
||||
finalColor = mix(toneMappedColor, noiseColor, noiseColor.r);
|
||||
}
|
||||
|
||||
outColor = vec4(finalColor, 1.0);
|
||||
}
|
@ -24,7 +24,7 @@ Core::Shader_Loader shaderLoader;
|
||||
Core::RenderContext sphereContext;
|
||||
Core::RenderContext cubeContext;
|
||||
|
||||
const char* const planetTexPaths[] = { "./textures/planets/earth.png", "./textures/planets/mercury.png", "./textures/planets/venus.jpg", "./textures/planets/mars.jpg",
|
||||
const char* const planetTexPaths[] = { "./textures/planets/earth.jpg", "./textures/planets/mercury.png", "./textures/planets/venus.jpg", "./textures/planets/mars.jpg",
|
||||
"./textures/planets/jupiter.jpg", "./textures/planets/saturn.jpg", "./textures/planets/uranus.jpg", "./textures/planets/neptune.jpg", "./textures/planets/icy.png",
|
||||
"./textures/planets/volcanic.png", "./textures/planets/desert.png", "./textures/planets/tropical.png", "./textures/planets/toxic.jpg", "./textures/planets/swamp.png",
|
||||
"./textures/planets/savannah.png", "./textures/planets/alpine.png", "./textures/planets/ceres.jpg", "./textures/planets/eris.jpg", "./textures/planets/haumea.jpg",
|
||||
@ -74,10 +74,9 @@ int HDR_HEIGHT = 1024;
|
||||
float lightPower = 8.f;
|
||||
glm::vec3 lightColor = glm::vec3(lightPower, lightPower, lightPower);
|
||||
|
||||
float cloudLight = 20.f;
|
||||
float cloudIntensity = 15.f;
|
||||
float cloudSpeed = 0.07f;
|
||||
float cloudLightness = 30.f;
|
||||
float cloudMotion = 0.f;
|
||||
float cloudBrightness = 0.08f;
|
||||
|
||||
glm::mat4 createCameraMatrix() {
|
||||
glm::vec3 cameraSide = glm::normalize(glm::cross(cameraDir, glm::vec3(0.f, 1.f, 0.f)));
|
||||
@ -102,7 +101,7 @@ glm::mat4 createPerspectiveMatrix() {
|
||||
float n = 0.01f;
|
||||
float f = 200.f;
|
||||
float fov = 105.f;
|
||||
float PI = 3.14159265359f;
|
||||
float PI = 3.14159f;
|
||||
float S = 1 / (tan((fov / 2) * (PI / 180)));
|
||||
|
||||
perspectiveMatrix = glm::mat4({
|
||||
@ -170,12 +169,12 @@ void drawPlanetTex(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint t
|
||||
|
||||
glUniform3f(glGetUniformLocation(programTex, "cameraPos"), cameraPos.x, cameraPos.y, cameraPos.z);
|
||||
|
||||
float time = glfwGetTime();
|
||||
glUniform1f(glGetUniformLocation(programTex, "u_time"), time);
|
||||
glUniform1f(glGetUniformLocation(programTex, "cloudLight"), cloudLight);
|
||||
glUniform1f(glGetUniformLocation(programTex, "time"), glfwGetTime());
|
||||
|
||||
glUniform1f(glGetUniformLocation(programTex, "cloudIntensity"), cloudIntensity);
|
||||
glUniform1f(glGetUniformLocation(programTex, "cloudSpeed"), cloudSpeed);
|
||||
glUniform1f(glGetUniformLocation(programTex, "cloudLightness"), cloudLightness);
|
||||
glUniform1f(glGetUniformLocation(programTex, "cloudMotion"), cloudMotion);
|
||||
glUniform1f(glGetUniformLocation(programTex, "cloudBrightness"), cloudBrightness);
|
||||
|
||||
glUniform1i(glGetUniformLocation(programTex, "atmosphereCheck"), atmosphereCheck);
|
||||
|
||||
Core::DrawContext(context);
|
||||
@ -202,12 +201,11 @@ void drawPlanetPbr(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint t
|
||||
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, "time"), glfwGetTime());
|
||||
|
||||
glUniform1f(glGetUniformLocation(programPbr, "cloudIntensity"), cloudIntensity);
|
||||
glUniform1f(glGetUniformLocation(programPbr, "cloudSpeed"), cloudSpeed);
|
||||
glUniform1f(glGetUniformLocation(programPbr, "cloudLightness"), cloudLightness);
|
||||
glUniform1f(glGetUniformLocation(programPbr, "cloudMotion"), cloudMotion);
|
||||
glUniform1f(glGetUniformLocation(programPbr, "cloudBrightness"), cloudBrightness);
|
||||
|
||||
glUniform1i(glGetUniformLocation(programPbr, "atmosphereCheck"), atmosphereCheck);
|
||||
|
||||
@ -346,15 +344,15 @@ void processInput(GLFWwindow* window)
|
||||
|
||||
if (glfwGetKey(window, GLFW_KEY_UP) == GLFW_PRESS && planetSize < 0.01f)
|
||||
planetSize += sizeSpeed;
|
||||
if (glfwGetKey(window, GLFW_KEY_DOWN) == GLFW_PRESS && planetSize > 0.001f)
|
||||
else if (glfwGetKey(window, GLFW_KEY_DOWN) == GLFW_PRESS && planetSize > 0.001f)
|
||||
planetSize -= sizeSpeed;
|
||||
|
||||
//obrót planety
|
||||
float rotationSpeed = 0.0025f;
|
||||
|
||||
if (glfwGetKey(window, GLFW_KEY_RIGHT) == GLFW_PRESS && planetRot < 1.f)
|
||||
if (glfwGetKey(window, GLFW_KEY_RIGHT) == GLFW_PRESS && planetRot < 1.5f)
|
||||
planetRot += rotationSpeed;
|
||||
if (glfwGetKey(window, GLFW_KEY_LEFT) == GLFW_PRESS && planetRot > -1.f)
|
||||
else if (glfwGetKey(window, GLFW_KEY_LEFT) == GLFW_PRESS && planetRot > -1.5f)
|
||||
planetRot -= rotationSpeed;
|
||||
|
||||
//jasność
|
||||
@ -362,7 +360,7 @@ void processInput(GLFWwindow* window)
|
||||
|
||||
if (glfwGetKey(window, GLFW_KEY_1) == GLFW_PRESS && lightPower < 16.f)
|
||||
lightPower += powerSpeed;
|
||||
if (glfwGetKey(window, GLFW_KEY_2) == GLFW_PRESS && lightPower > 2.f)
|
||||
else if (glfwGetKey(window, GLFW_KEY_2) == GLFW_PRESS && lightPower > 2.f)
|
||||
lightPower -= powerSpeed;
|
||||
|
||||
lightColor = glm::vec3(lightPower, lightPower, lightPower);
|
||||
@ -372,7 +370,7 @@ void processInput(GLFWwindow* window)
|
||||
|
||||
if (glfwGetKey(window, GLFW_KEY_3) == GLFW_PRESS && planetRough < 1.f)
|
||||
planetRough += roughSpeed;
|
||||
if (glfwGetKey(window, GLFW_KEY_4) == GLFW_PRESS && planetRough > 0.f)
|
||||
else if (glfwGetKey(window, GLFW_KEY_4) == GLFW_PRESS && planetRough > 0.f)
|
||||
planetRough -= roughSpeed;
|
||||
|
||||
//metaliczność
|
||||
@ -380,8 +378,32 @@ void processInput(GLFWwindow* window)
|
||||
|
||||
if (glfwGetKey(window, GLFW_KEY_5) == GLFW_PRESS && planetMetal < 1.f)
|
||||
planetMetal += metalSpeed;
|
||||
if (glfwGetKey(window, GLFW_KEY_6) == GLFW_PRESS && planetMetal > 0.f)
|
||||
else if (glfwGetKey(window, GLFW_KEY_6) == GLFW_PRESS && planetMetal > 0.f)
|
||||
planetMetal -= metalSpeed;
|
||||
|
||||
//natężenie chmur
|
||||
float intensitySpeed = 0.1f;
|
||||
|
||||
if (glfwGetKey(window, GLFW_KEY_Z) == GLFW_PRESS && cloudIntensity < 100.f)
|
||||
cloudIntensity += intensitySpeed;
|
||||
else if (glfwGetKey(window, GLFW_KEY_X) == GLFW_PRESS && cloudIntensity > 0.f)
|
||||
cloudIntensity -= intensitySpeed;
|
||||
|
||||
//ruch chmur
|
||||
float motionSpeed = 0.0025f;
|
||||
|
||||
if (glfwGetKey(window, GLFW_KEY_V) == GLFW_PRESS && cloudMotion < 1.5f)
|
||||
cloudMotion += motionSpeed;
|
||||
else if (glfwGetKey(window, GLFW_KEY_C) == GLFW_PRESS && cloudMotion > -1.5f)
|
||||
cloudMotion -= motionSpeed;
|
||||
|
||||
//jasność chmur
|
||||
float brightnessSpeed = 0.0005f;
|
||||
|
||||
if (glfwGetKey(window, GLFW_KEY_N) == GLFW_PRESS && cloudBrightness < 0.16f)
|
||||
cloudBrightness += brightnessSpeed;
|
||||
else if (glfwGetKey(window, GLFW_KEY_B) == GLFW_PRESS && cloudBrightness > 0.02f)
|
||||
cloudBrightness -= brightnessSpeed;
|
||||
}
|
||||
|
||||
void init(GLFWwindow* window) {
|
||||
|
BIN
grk/cw 6/textures/planets/earth.jpg
Normal file
BIN
grk/cw 6/textures/planets/earth.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 452 KiB |
Binary file not shown.
Before Width: | Height: | Size: 4.4 MiB |
Loading…
Reference in New Issue
Block a user