szum kolorkowy

This commit is contained in:
sasankasa 2024-01-29 19:41:22 +01:00
parent d363d89620
commit 27eb43b140
2 changed files with 151 additions and 4 deletions

View File

@ -1,6 +1,6 @@
#version 430 core
float PI = 3.14159f;
/*float PI = 3.14159f;
uniform sampler2D colorTexture;
@ -71,10 +71,152 @@ void main()
vec2 st = vtc;
vec2 pos = vec2(st*3.776);
pos.x -= u_time * 0.07;
// Use the noise function
float n = 1.836 * 0.676*noise(pos*2.576);
n = smoothstep(-0.096, 1.176, n);
outColor = vec4(vec3(n), 1);
}
*/
out vec4 outColor;
uniform float u_time;
in vec2 vtc;
float random (in vec2 _st) {
return fract(sin(dot(_st.xy,
vec2(12.9898,78.233)))*
43758.5453123);
}
// Based on Morgan McGuire @morgan3d
// https://www.shadertoy.com/view/4dS3Wd
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 NUM_OCTAVES 5
float fbm ( in vec2 _st) {
float v = 0.0;
float a = 0.5;
vec2 shift = vec2(100.0);
// Rotate to reduce axial bias
mat2 rot = mat2(cos(0.5), sin(0.5),
-sin(0.5), cos(0.50));
for (int i = 0; i < NUM_OCTAVES; ++i) {
v += a * noise(_st);
_st = rot * _st * 3.0 + shift;
a *= 0.6;
}
return v;
}
void main() {
vec2 st = vtc;
// st += st * abs(sin(u_time*0.1)*3.0);
vec3 color = vec3(0.0);
vec2 q = vec2(0.);
q.x = fbm( st + 0.00*u_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*u_time );
r.y = fbm( st + 1.0*q + vec2(8.3,2.8)+ 0.126*u_time);
float f = fbm(st+r);
color = mix(vec3(0.101961,0.619608,0.666667),
vec3(0.666667,0.666667,0.498039),
clamp((f*f)*4.0,0.0,1.0));
color = mix(color,
vec3(0.995,0.077,0.220),
clamp(length(q),0.0,1.0));
color = mix(color,
vec3(1.000,0.925,0.132),
clamp(length(r.x),0.0,1.0));
outColor = vec4((f*f*f+.9*f*f+.9*f)*color,1.);
}
/*
uniform float u_time;
out vec4 outColor;
in vec2 vtc;
in vec3 worldPos;
vec2 u_resolution = vec2(1024, 1024);
float random (in vec2 st) {
return fract(sin(dot(st.xy,
vec2(12.9898,78.233)))*
43758.5453123);
}
// Based on Morgan McGuire @morgan3d
// https://www.shadertoy.com/view/4dS3Wd
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;
}
void main() {
vec2 st = vtc;
//vec2 st = vtc.xy/worldPos.xy;
//st += st * abs(sin(u_time*0.1)*10.0);
//st.x *= worldPos.x/worldPos.y;
vec3 color = vec3(0.0);
color += fbm(st*3.0);
vec3 mixedColor = mix(vec3(0.4), color, color.r);
//color = mix(vec3(1.0), fbm(st*3.0), 0.1);
outColor = vec4(mixedColor,1.0);
}*/

View File

@ -257,12 +257,15 @@ void drawObjectPBR(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint t
glUseProgram(0);
}
void drawObjectNoise(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint texture, float roughness, float metallic) {
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);
@ -279,9 +282,11 @@ void renderScene(GLFWwindow* window) {
glm::mat4 planetRotate = glm::rotate(time * planetRot, glm::vec3(0, 1, 0));
glm::mat4 planetTranslate = glm::translate(planetPos);
glm::mat4 cloudScale = glm::scale(glm::vec3(planetSize * 1.05f));
//drawPlanet(sphereContext, planetTranslate * planetRotate * planetScale, planetTex);
drawObjectPBR(sphereContext, planetTranslate * planetRotate * planetScale, planetTex, planetRough, planetMetal);
drawObjectNoise(sphereContext, planetTranslate * planetRotate * planetScale, planetTex, planetRough, planetMetal);
drawObjectNoise(sphereContext, planetTranslate * planetRotate * cloudScale, time);
//rysowanie słońca
glm::mat4 sunScale = glm::scale(glm::vec3(sunSize));