From fda254b25ee033afc2324f8cd1199d94eba9939b Mon Sep 17 00:00:00 2001 From: sasankasa Date: Wed, 7 Feb 2024 20:06:08 +0100 Subject: [PATCH 1/3] =?UTF-8?q?szum=20s=C5=82o=C5=84ca?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- grk/cw 6/shaders/shader_sun.frag | 86 ++++++++++++++++++++++++++++++-- grk/cw 6/src/Planet.hpp | 6 ++- 2 files changed, 87 insertions(+), 5 deletions(-) diff --git a/grk/cw 6/shaders/shader_sun.frag b/grk/cw 6/shaders/shader_sun.frag index eb72528..009034f 100644 --- a/grk/cw 6/shaders/shader_sun.frag +++ b/grk/cw 6/shaders/shader_sun.frag @@ -7,6 +7,8 @@ uniform vec3 cameraPos; uniform bool atmosphereCheck; +uniform float time; + in vec3 vecNormal; in vec3 worldPos; in vec2 vtc; @@ -15,6 +17,8 @@ out vec4 outColor; uniform sampler2D colorTexture; +vec4 noiseColor; + vec3 toneMapping(vec3 color) { float exposure = 0.06; @@ -22,6 +26,76 @@ vec3 toneMapping(vec3 color) return mapped; } +float random (in vec2 _st) { + return fract(sin(dot(_st.xy, + vec2(-0.550,0.430)))* + 43758.5453123); +} + +float noise (in vec2 _st) { + vec2 i = floor(_st); + vec2 f = fract(_st); + + 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 NUM_OCTAVES 5 + +float fbm ( in vec2 _st) { + float v = 0.0; + float a = 0.5; + vec2 shift = vec2(100.0); + + mat2 rot = mat2(cos(0.5), sin(0.5), + -sin(0.5), cos(0.5)); + for (int i = 0; i < NUM_OCTAVES; ++i) { + v += a * noise(_st); + _st = rot * _st * 2.0 + shift; + a *= 0.9; + } + return v; +} + +vec4 noiseTexture(float time) { + vec2 st = vtc.xy * 9.; + vec3 color = vec3(0.0); + + vec2 q = vec2(0.); + q.x = fbm(st + 0.0 * time); + q.y = fbm(st + vec2(1.0)); + + vec2 r = vec2(0.); + r.x = fbm(st + 1.0 * q + vec2(1.7, 9.2) + 0.15 * time); + r.y = fbm(st + 1.0 * q + vec2(8.3, 2.8) + 0.12 * time); + + float f = fbm(st+r); + + color = mix(vec3(0.667,0.640,0.088), + vec3(0.667,0.520,0.134), + clamp((f*f)*4.640,0.712,0.056)); + + color = mix(color, + vec3(0.165,0.006,0.023), + clamp(length(q),0.072,0.408)); + + color = mix(color, + vec3(1.000,0.069,0.060), + clamp(length(r.x),0.0,1.0)); + + noiseColor = vec4((f*f*f+1.384*f*f+1.044*f)*color,1.); + + return noiseColor; +} + void main() { vec3 normal = normalize(vecNormal); @@ -36,10 +110,16 @@ void main() textureColor = mix(textureColor, atmosphereColor, pow(1 - atmosphereDot, 3)); } - vec3 distance = lightColor / pow(length(lightPos - worldPos), 2.0) * 25; - vec3 toneMappedColor = toneMapping(textureColor * distance); + vec3 distance = lightColor / pow(length(lightPos - worldPos), 2.0) * 15; + + vec4 textureNoise = noiseTexture(time); + //vec3 mixedTexture = mix(textureColor, textureNoise, textureNoise.r); + //vec3 toneMappedColor = toneMapping(mixedTexture * distance); + vec3 toneMappedColor = toneMapping(textureNoise.rgb * distance); //gamma correction toneMappedColor = pow(toneMappedColor, vec3(1.0/2.2)); - outColor = vec4(toneMappedColor * lightColor * 0.2f, 1.0); + vec3 textureToned = toneMappedColor * lightColor * 0.2f; + + outColor = vec4(textureToned, 1.0); } \ No newline at end of file diff --git a/grk/cw 6/src/Planet.hpp b/grk/cw 6/src/Planet.hpp index 4a514b2..18031fb 100644 --- a/grk/cw 6/src/Planet.hpp +++ b/grk/cw 6/src/Planet.hpp @@ -38,7 +38,7 @@ float planetRot = 0.f; float planetRough = 0.5f; float planetMetal = 0.5f; -const char* const sunTexPaths[] = { "./textures/suns/sol.jpg", "./textures/suns/orange.jpg", "./textures/suns/lava.png", "./textures/suns/star.png", "./textures/suns/sun.jpg" }; +const char* const sunTexPaths[] = { "./textures/suns/lava.png", "./textures/suns/sol.jpg", "./textures/suns/orange.jpg", "./textures/suns/star.png", "./textures/suns/sun.jpg" }; int sunTexIndex = 20; GLuint sunTex; @@ -227,6 +227,7 @@ void drawSun(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint texture glUniform3f(glGetUniformLocation(programSun, "cameraPos"), cameraPos.x, cameraPos.y, cameraPos.z); glUniform1i(glGetUniformLocation(programSun, "atmosphereCheck"), atmosphereCheck); + glUniform1f(glGetUniformLocation(programSun, "time"), glfwGetTime()); Core::DrawContext(context); glUseProgram(0); @@ -264,8 +265,9 @@ void renderScene(GLFWwindow* window) { //rysowanie słońca glm::mat4 sunScale = glm::scale(glm::vec3(sunSize)); glm::mat4 sunTranslate = glm::translate(sunPos); + glm::mat4 sunRotate = glm::rotate(180.f, glm::vec3(0, 1, 0)); - drawSun(sphereContext, sunTranslate * sunScale, sunTex); + drawSun(sphereContext, sunTranslate * sunRotate * sunScale, sunTex); //rysowanie skyboxa skyBoxPos = cameraPos; -- 2.20.1 From ab39c86f0aff25f2d8761b1b59b15814b51ff400 Mon Sep 17 00:00:00 2001 From: sasankasa Date: Wed, 7 Feb 2024 20:19:25 +0100 Subject: [PATCH 2/3] =?UTF-8?q?poprawka=20s=C5=82o=C5=84ca?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- grk/cw 6/shaders/shader_pbr.frag | 2 +- grk/cw 6/shaders/shader_sun.frag | 14 +++++++------- grk/cw 6/src/Planet.hpp | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/grk/cw 6/shaders/shader_pbr.frag b/grk/cw 6/shaders/shader_pbr.frag index 4f4e842..25f8d65 100644 --- a/grk/cw 6/shaders/shader_pbr.frag +++ b/grk/cw 6/shaders/shader_pbr.frag @@ -112,7 +112,7 @@ vec3 toneMapping(vec3 color) float random (in vec2 st) { return fract(sin(dot(st.xy, - vec2(12.9898,78.233)))* + vec2(32.9898,128.233)))* 43758.5453123); } diff --git a/grk/cw 6/shaders/shader_sun.frag b/grk/cw 6/shaders/shader_sun.frag index 009034f..5c7b048 100644 --- a/grk/cw 6/shaders/shader_sun.frag +++ b/grk/cw 6/shaders/shader_sun.frag @@ -60,7 +60,7 @@ float fbm ( in vec2 _st) { for (int i = 0; i < NUM_OCTAVES; ++i) { v += a * noise(_st); _st = rot * _st * 2.0 + shift; - a *= 0.9; + a *= 0.75; } return v; } @@ -84,11 +84,11 @@ vec4 noiseTexture(float time) { clamp((f*f)*4.640,0.712,0.056)); color = mix(color, - vec3(0.165,0.006,0.023), + vec3(0.165,0.111,0.036), clamp(length(q),0.072,0.408)); color = mix(color, - vec3(1.000,0.069,0.060), + vec3(1.000,0.306,0.143), clamp(length(r.x),0.0,1.0)); noiseColor = vec4((f*f*f+1.384*f*f+1.044*f)*color,1.); @@ -107,15 +107,15 @@ void main() { float atmosphereDot = dot(normal, viewDir); vec3 atmosphereColor = vec3(1.0, 0.08, 0.02); - textureColor = mix(textureColor, atmosphereColor, pow(1 - atmosphereDot, 3)); + textureColor = mix(textureColor, atmosphereColor, pow(1 - atmosphereDot, 2)); } vec3 distance = lightColor / pow(length(lightPos - worldPos), 2.0) * 15; vec4 textureNoise = noiseTexture(time); - //vec3 mixedTexture = mix(textureColor, textureNoise, textureNoise.r); - //vec3 toneMappedColor = toneMapping(mixedTexture * distance); - vec3 toneMappedColor = toneMapping(textureNoise.rgb * distance); + vec3 mixedTexture = mix(textureColor, textureNoise.rgb, 0.45f); + + vec3 toneMappedColor = toneMapping(mixedTexture * distance); //gamma correction toneMappedColor = pow(toneMappedColor, vec3(1.0/2.2)); diff --git a/grk/cw 6/src/Planet.hpp b/grk/cw 6/src/Planet.hpp index 18031fb..59e2e6d 100644 --- a/grk/cw 6/src/Planet.hpp +++ b/grk/cw 6/src/Planet.hpp @@ -24,7 +24,7 @@ Core::Shader_Loader shaderLoader; Core::RenderContext sphereContext; Core::RenderContext cubeContext; -const char* const planetTexPaths[] = { "./textures/planets/earth.jpg", "./textures/planets/mercury.png", "./textures/planets/venus.jpg", "./textures/planets/mars.jpg", +const char* const planetTexPaths[] = { "./textures/planets/mercury.png", "./textures/planets/venus.jpg", "./textures/planets/earth.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", -- 2.20.1 From 7cf2fd8cf44abe6d7af41d657a6f03d959ed0676 Mon Sep 17 00:00:00 2001 From: sasankasa Date: Wed, 7 Feb 2024 20:21:42 +0100 Subject: [PATCH 3/3] name change --- grk/grk-planet-editor.sln | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 grk/grk-planet-editor.sln diff --git a/grk/grk-planet-editor.sln b/grk/grk-planet-editor.sln new file mode 100644 index 0000000..5d8f122 --- /dev/null +++ b/grk/grk-planet-editor.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.4.33213.308 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Planeta", "cw 6\grk-cw6.vcxproj", "{3952C396-B1C6-44CD-96DD-C1AC15D32978}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x86 = Debug|x86 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {3952C396-B1C6-44CD-96DD-C1AC15D32978}.Debug|x86.ActiveCfg = Debug|Win32 + {3952C396-B1C6-44CD-96DD-C1AC15D32978}.Debug|x86.Build.0 = Debug|Win32 + {3952C396-B1C6-44CD-96DD-C1AC15D32978}.Release|x86.ActiveCfg = Release|Win32 + {3952C396-B1C6-44CD-96DD-C1AC15D32978}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {AED787C0-0952-4701-A56F-36AB5A5F246A} + EndGlobalSection +EndGlobal -- 2.20.1