From 0611af514122d96cca1bfd969405158830d126cc Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Wed, 17 Jan 2024 21:59:06 +0000 Subject: [PATCH] Removing doughtnut normal --- build.sc | 5 -- .../doughnut-normal/src/DoughnutNormal.scala | 65 ------------------- 2 files changed, 70 deletions(-) delete mode 100644 shaders/shapes/doughnut-normal/src/DoughnutNormal.scala diff --git a/build.sc b/build.sc index 220daa7..b347da7 100644 --- a/build.sc +++ b/build.sc @@ -138,11 +138,6 @@ object shaders extends mill.Module { makeIndigoOptions("Doughnut") } - object `doughnut-normal` extends shadermodule.ShaderModule { - val indigoOptions: IndigoOptions = - makeIndigoOptions("DoughnutNormal") - } - object metaballs extends shadermodule.ShaderModule { val indigoOptions: IndigoOptions = makeIndigoOptions("Metaballs") diff --git a/shaders/shapes/doughnut-normal/src/DoughnutNormal.scala b/shaders/shapes/doughnut-normal/src/DoughnutNormal.scala deleted file mode 100644 index 01edb0b..0000000 --- a/shaders/shapes/doughnut-normal/src/DoughnutNormal.scala +++ /dev/null @@ -1,65 +0,0 @@ -import indigo.* - -import scala.scalajs.js.annotation.* -import generated.* - -/** Make a top down view of a doughnut, where the gray value is essentially a height map of a - * doughtnut shape. Then turn it into a normal map. - */ - -@JSExportTopLevel("IndigoGame") -object DoughnutNormal extends IndigoShader: - - val config: GameConfig = - Config.config.noResize - - val assets: Set[AssetType] = Assets.assets.assetSet - val channel0: Option[AssetPath] = None - val channel1: Option[AssetPath] = None - val channel2: Option[AssetPath] = None - val channel3: Option[AssetPath] = None - - val shader: Shader = - CustomShader.shader - -object CustomShader: - - val shader: Shader = - UltravioletShader.entityFragment( - ShaderId("shader"), - EntityShader.fragment[FragmentEnv](fragment, FragmentEnv.reference) - ) - - import ultraviolet.syntax.* - - /* - GraphToy: - ((cos((x - 0.25) * PI * 4.0) * 0.5) + 0.5) * min(step(-0.5, x), 1.0 - step(0.5, x)) - */ - - inline def fragment: Shader[FragmentEnv, Unit] = - Shader[FragmentEnv] { env => - - def sdCircle(p: vec2, r: Float): Float = - length(p) - r - - def rateOfChange(d: Float, m: Float): Float = - val c = (cos((d - 0.25f) * env.PI * m) * 0.5f) + 0.5f - c * min(step(-2.0f / m, d), 1.0f - step(2.0f / m, d)) - - def fragment(color: vec4): vec4 = - val p = env.UV - 0.5f - val sdf = sdCircle(p, 0.25f) - - val normalised = normalize(p) - var d = if sdf < 0.0f then -normalised else normalised - d = clamp(d, vec2(-1.0f), vec2(1.0f)) - d = (d + 1.0f) * 0.5f - - val curve = clamp(rateOfChange(sdf, 20.0f), 0.0f, 1.0f) - - val normalColor = vec4(d, 1.0f, 1.0f) - val baseColor = vec4(0.5f, 0.5f, 1.0f, 1.0f) - - mix(baseColor, normalColor, curve) - }