From f409eb3e860c563e3814e936d1f221d81a62ef5c Mon Sep 17 00:00:00 2001 From: Bassel Mabsout <7851037+bmabsout@users.noreply.github.com> Date: Thu, 8 Feb 2024 17:54:39 -0500 Subject: [PATCH 1/2] Created the smooth_cheese.fsh shader smoooooth cheeeese --- app/src/main/assets/Shaders/smooth_cheese.fsh | 102 ++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 app/src/main/assets/Shaders/smooth_cheese.fsh diff --git a/app/src/main/assets/Shaders/smooth_cheese.fsh b/app/src/main/assets/Shaders/smooth_cheese.fsh new file mode 100644 index 00000000..19ed1715 --- /dev/null +++ b/app/src/main/assets/Shaders/smooth_cheese.fsh @@ -0,0 +1,102 @@ + + +/* + * Title: Smooth Cheese + * Author: Bassel EL Mabsout + * SIMPLEX noise implementation taken from: + * https://www.shadertoy.com/view/XsX3zB + * + * The MIT License + * Copyright © 2013 Nikita Miropolskiy + * + * ( license has been changed from CCA-NC-SA 3.0 to MIT + * + * but thanks for attributing your source code when deriving from this sample + * with a following link: https://www.shadertoy.com/view/XsX3zB ) + */ + +#version 300 es + +precision highp float; + +uniform float iTime; +uniform vec3 iResolution; + +in vec2 textureCoord; +out vec4 fragColor; + +/* discontinuous pseudorandom uniformly distributed in [-0.5, +0.5]^3 */ +vec3 random3(vec3 c) { + float j = 4096.0*sin(dot(c,vec3(17.0, 59.4, 15.0))); + vec3 r; + r.z = fract(512.0*j); + j *= .125; + r.x = fract(512.0*j); + j *= .125; + r.y = fract(512.0*j); + return r-0.5; +} + +/* skew constants for 3d simplex functions */ +const float F3 = 0.3333333; +const float G3 = 0.1666667; + +/* 3d simplex noise */ +float simplex3d(vec3 p) { + /* 1. find current tetrahedron T and it's four vertices */ + /* s, s+i1, s+i2, s+1.0 - absolute skewed (integer) coordinates of T vertices */ + /* x, x1, x2, x3 - unskewed coordinates of p relative to each of T vertices*/ + /* calculate s and x */ + vec3 s = floor(p + dot(p, vec3(F3))); + vec3 x = p - s + dot(s, vec3(G3)); + + /* calculate i1 and i2 */ + vec3 e = step(vec3(0.0), x - x.yzx); + vec3 i1 = e*(1.0 - e.zxy); + vec3 i2 = 1.0 - e.zxy*(1.0 - e); + + /* x1, x2, x3 */ + vec3 x1 = x - i1 + G3; + vec3 x2 = x - i2 + 2.0*G3; + vec3 x3 = x - 1.0 + 3.0*G3; + + /* 2. find four surflets and store them in d */ + vec4 w, d; + + /* calculate surflet weights */ + w.x = dot(x, x); + w.y = dot(x1, x1); + w.z = dot(x2, x2); + w.w = dot(x3, x3); + + /* w fades from 0.6 at the center of the surflet to 0.0 at the margin */ + w = max(0.6 - w, 0.0); + + /* calculate surflet components */ + d.x = dot(random3(s), x); + d.y = dot(random3(s + i1), x1); + d.z = dot(random3(s + i2), x2); + d.w = dot(random3(s + 1.0), x3); + + /* multiply d by w^4 */ + w *= w; + w *= w; + d *= w; + + /* 3. return the sum of the four surflets */ + return dot(d, vec4(52.0)); +} + +void mainImage( out vec4 fragColor, in vec2 fragCoord ) +{ + vec2 p = fragCoord.xy/iResolution.x; + vec3 p3 = vec3(p, iTime*0.015)+vec3(iTime*0.015,0.0,0.0); + + float value = pow(abs(simplex3d(p3*2.0)),1.5); + float red = 0.5 + 0.5*simplex3d(p3*2.0 + 38274.9); + float green = abs(0.2+0.5*simplex3d(p3*2.0 + 3824.9)); + float blue = abs(simplex3d(p3*2.0 + 98274.9)); + + fragColor = vec4(sqrt(value*vec3(red, green, blue)), 1.0); + return; +} From 78ac85a2018b4d10b6d91d5add1caca93ac9534a Mon Sep 17 00:00:00 2001 From: Bassel Mabsout <7851037+bmabsout@users.noreply.github.com> Date: Thu, 8 Feb 2024 18:54:46 -0500 Subject: [PATCH 2/2] Addressed pull request comments smooth_cheese.fsh --- app/src/main/assets/Shaders/smooth_cheese.fsh | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/app/src/main/assets/Shaders/smooth_cheese.fsh b/app/src/main/assets/Shaders/smooth_cheese.fsh index 19ed1715..d402d9be 100644 --- a/app/src/main/assets/Shaders/smooth_cheese.fsh +++ b/app/src/main/assets/Shaders/smooth_cheese.fsh @@ -1,4 +1,4 @@ - +#version 300 es /* * Title: Smooth Cheese @@ -15,8 +15,6 @@ * with a following link: https://www.shadertoy.com/view/XsX3zB ) */ -#version 300 es - precision highp float; uniform float iTime; @@ -87,16 +85,15 @@ float simplex3d(vec3 p) { return dot(d, vec4(52.0)); } -void mainImage( out vec4 fragColor, in vec2 fragCoord ) +void main() { - vec2 p = fragCoord.xy/iResolution.x; + vec2 p = textureCoord; vec3 p3 = vec3(p, iTime*0.015)+vec3(iTime*0.015,0.0,0.0); float value = pow(abs(simplex3d(p3*2.0)),1.5); - float red = 0.5 + 0.5*simplex3d(p3*2.0 + 38274.9); - float green = abs(0.2+0.5*simplex3d(p3*2.0 + 3824.9)); - float blue = abs(simplex3d(p3*2.0 + 98274.9)); + float red = 0.5 + 0.5*simplex3d(p3*2.0 + 38274.9); + float green = abs(0.2+0.5*simplex3d(p3*2.0 + 3824.9)); + float blue = abs(simplex3d(p3*2.0 + 98274.9)); fragColor = vec4(sqrt(value*vec3(red, green, blue)), 1.0); - return; }