From 64617ea2c46d13cd2f72df72fcd426d2fc561bff Mon Sep 17 00:00:00 2001 From: gramanas Date: Sat, 1 Jun 2024 01:47:10 +0300 Subject: multisample --- src/shader.frag | 80 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 40 insertions(+), 40 deletions(-) (limited to 'src/shader.frag') diff --git a/src/shader.frag b/src/shader.frag index 1818cc8..3e80e21 100644 --- a/src/shader.frag +++ b/src/shader.frag @@ -16,50 +16,50 @@ layout(binding = 0) uniform UniformBufferObject { float dt; } ubo; -void main() { - // float pulse = sin(ubo.time * .2) * .5 + .5; - // outColor = vec4(fragColor * texture(texSampler, fragTexCoord).rgb * pulse, 1.0); - //outColor = texture(texSampler, fragTexCoord); - outColor = vec4(fragColor, 1); -// float repeat = 10; -// float f = mod(ubo.time, repeat); -// if (f < repeat / 2) { -// outColor = vec4(fragColor * radians(f) ,1); -// } else { -// outColor = vec4(fragColor * radians(1 - f) ,1); -// } -// //outColor = (vec4(1) * ubo.model + vec4(1)) * vec4(texture(texSampler, fragTexCoord).rgb * fragColor, 1.0); -} - -// float noise(vec2 p) { -// return fract(sin(dot(p, vec2(12.9898, 78.233))) * 43758.5453); +// void main() { +// // float pulse = sin(ubo.time * .2) * .5 + .5; +// // outColor = vec4(fragColor * texture(texSampler, fragTexCoord).rgb * pulse, 1.0); +// //outColor = texture(texSampler, fragTexCoord); +// outColor = vec4(fragColor, 1); +// // float repeat = 10; +// // float f = mod(ubo.time, repeat); +// // if (f < repeat / 2) { +// // outColor = vec4(fragColor * radians(f) ,1); +// // } else { +// // outColor = vec4(fragColor * radians(1 - f) ,1); +// // } +// // //outColor = (vec4(1) * ubo.model + vec4(1)) * vec4(texture(texSampler, fragTexCoord).rgb * fragColor, 1.0); // } -// float smoothNoise(vec2 p) { -// vec2 i = floor(p); -// vec2 f = fract(p); -// vec2 u = f * f * (3.0 - 2.0 * f); -// return mix(mix(noise(i + vec2(0.0, 0.0)), noise(i + vec2(1.0, 0.0)), u.x), -// mix(noise(i + vec2(0.0, 1.0)), noise(i + vec2(1.0, 1.0)), u.x), u.y); -// } +float noise(vec2 p) { + return fract(sin(dot(p, vec2(12.9898, 78.233))) * 43758.5453); +} -// float fbm(vec2 p) { -// float value = 0.0; -// float amplitude = 0.5; -// for (int i = 0; i < 6; i++) { -// value += amplitude * smoothNoise(p); -// p *= 2.0; -// amplitude *= 0.5; -// } -// return value; -// } +float smoothNoise(vec2 p) { + vec2 i = floor(p); + vec2 f = fract(p); + vec2 u = f * f * (3.0 - 2.0 * f); + return mix(mix(noise(i + vec2(0.0, 0.0)), noise(i + vec2(1.0, 0.0)), u.x), + mix(noise(i + vec2(0.0, 1.0)), noise(i + vec2(1.0, 1.0)), u.x), u.y); +} -// void main() { -// vec2 uv = gl_FragCoord.xy / ubo.resolution.xy; -// vec2 p = uv * 2.0 - vec2(1.0); -// float n = fbm(p * 5.0 - vec2(0.0, ubo.time * 2.0)); -// outColor = vec4(n, n * 0.5, 0.0, 1.0) * vec4(texture(texSampler, fragTexCoord).rgb, 1.0); -// } +float fbm(vec2 p) { + float value = 0.0; + float amplitude = 0.5; + for (int i = 0; i < 6; i++) { + value += amplitude * smoothNoise(p); + p *= 2.0; + amplitude *= 0.5; + } + return value; +} + +void main() { + vec2 uv = gl_FragCoord.xy / ubo.resolution.xy; + vec2 p = uv * 2.0 - vec2(1.0); + float n = fbm(p * 5.0 - vec2(0.0, ubo.time * 2.0)); + outColor = vec4(n, n * 0.5, 0.0, 1.0) * vec4(texture(texSampler, fragTexCoord).rgb, 1.0); +} // void main() { -- cgit v1.2.3