Class Shading

java.lang.Object
com.codename1.gpu.shaders.Shading

public final class Shading extends Object
Small building blocks most surface shaders share: view dependent terms, fades, world space texture coordinates and signed distance shapes. Fragment stage unless a method says otherwise.
  • Method Details

    • fresnel

      public static ShaderNode fresnel(float power)

      Schlick style edge factor: 0 facing the camera, 1 at grazing angles.

      Parameters
      • power: higher keeps it closer to the silhouette; 5 is physical
      Returns

      a FLOAT

    • rim

      public static ShaderNode rim(ShaderNode color, float power)

      A coloured glow along the silhouette.

      Parameters
      • color: a VEC3

      • power: how tight the rim is, 2 to 8

      Returns

      a VEC3, for the EMISSIVE hook

    • heightFade

      public static ShaderNode heightFade(float from, float to)

      1 below from and 0 above to along world height, smoothly between. Both stages.

      Parameters
      • from: the height where the fade starts

      • to: the height where it ends

      Returns

      a FLOAT

    • distanceFade

      public static ShaderNode distanceFade(float from, float to)

      1 near the camera and 0 beyond to, for fading detail out with distance. Both stages.

      Parameters
      • from: the distance where the fade starts

      • to: the distance where it ends

      Returns

      a FLOAT

    • worldUv

      public static ShaderNode worldUv(float scale)

      Texture coordinates from world position seen from above, so a pattern tiles across meshes without seams and ignores their UVs. Both stages.

      Parameters
      • scale: repeats per world unit
      Returns

      a VEC2

    • boxUv

      public static ShaderNode boxUv(float scale)

      Texture coordinates that follow the surface on every face: the world plane the normal faces most, so walls do not smear a pattern seen from above. A cheap one sample stand-in for triplanar blending.

      Parameters
      • scale: repeats per world unit
      Returns

      a VEC2

    • scroll

      public static ShaderNode scroll(ShaderNode uv, float u, float v)

      A texture coordinate that scrolls with time. Both stages.

      Parameters
      • uv: a VEC2

      • u: units per second along u

      • v: units per second along v

      Returns

      a VEC2

    • sdCircle

      public static ShaderNode sdCircle(ShaderNode p, ShaderNode center, float radius)

      The signed distance to a circle: negative inside.

      Parameters
      • p: a VEC2 point

      • center: a VEC2

      • radius: the radius

      Returns

      a FLOAT

    • sdBox

      public static ShaderNode sdBox(ShaderNode p, ShaderNode center, ShaderNode halfSize)

      The signed distance to an axis aligned box: negative inside.

      Parameters
      • p: a VEC2 point

      • center: a VEC2

      • halfSize: a VEC2 of half the width and height

      Returns

      a FLOAT

    • sdSegment

      public static ShaderNode sdSegment(ShaderNode p, ShaderNode a, ShaderNode b)

      The distance to a line segment.

      Parameters
      • p: a VEC2 point

      • a: a VEC2 end

      • b: the other VEC2 end

      Returns

      a FLOAT, never negative

    • fill

      public static ShaderNode fill(ShaderNode distance, float softness)

      Turns a signed distance into coverage with a soft edge: 1 inside, 0 outside.

      Parameters
      • distance: a signed distance

      • softness: the width of the edge

      Returns

      a FLOAT

    • stroke

      public static ShaderNode stroke(ShaderNode distance, float width, float softness)

      A band of width around the zero line of a signed distance: outlines, rings, foam lines along a shore.

      Parameters
      • distance: a signed distance

      • width: the band width

      • softness: the width of its edges

      Returns

      a FLOAT

    • ramp

      public static ShaderNode ramp(ShaderNode t, ShaderNode a, ShaderNode b, ShaderNode c)

      A smooth three colour ramp: a at 0, b at 0.5, c at 1.

      Parameters
      • t: a FLOAT

      • a: a VEC3

      • b: a VEC3

      • c: a VEC3

      Returns

      a VEC3

    • opaque

      public static ShaderNode opaque(ShaderNode rgb)

      Opaque VEC4 from a VEC3 colour.

      Parameters
      • rgb: a VEC3
      Returns

      a VEC4 with alpha 1