Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.

public final class Shading

  1. Object
  2. Shading
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.

Methods

public static ShaderNode fresnel(float power)Schlick style edge factor: 0 facing the camera, 1 at grazing angles.
public static ShaderNode rim(ShaderNode color, float power)A coloured glow along the silhouette.
public static ShaderNode heightFade(float from, float to)1 below from and 0 above to along world height, smoothly between.
public static ShaderNode distanceFade(float from, float to)1 near the camera and 0 beyond to, for fading detail out with distance.
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.
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.
public static ShaderNode scroll(ShaderNode uv, float u, float v)A texture coordinate that scrolls with time.
public static ShaderNode sdCircle(ShaderNode p, ShaderNode center, float radius)The signed distance to a circle: negative inside.
public static ShaderNode sdBox(ShaderNode p, ShaderNode center, ShaderNode halfSize)The signed distance to an axis aligned box: negative inside.
public static ShaderNode sdSegment(ShaderNode p, ShaderNode a, ShaderNode b)The distance to a line segment.
public static ShaderNode fill(ShaderNode distance, float softness)Turns a signed distance into coverage with a soft edge: 1 inside, 0 outside.
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.
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.
public static ShaderNode opaque(ShaderNode rgb)Opaque VEC4 from a VEC3 colour.

Inherited methods

Method details

fresnel

public static ShaderNode fresnel(float power)
Schlick style edge factor: 0 facing the camera, 1 at grazing angles.

Parameters

power float
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 ShaderNode
a VEC3
power float
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 float
the height where the fade starts
to float
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 float
the distance where the fade starts
to float
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 float
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 float
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 ShaderNode
a VEC2
u float
units per second along u
v float
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 ShaderNode
a VEC2 point
center ShaderNode
a VEC2
radius float
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 ShaderNode
a VEC2 point
center ShaderNode
a VEC2
halfSize ShaderNode
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 ShaderNode
a VEC2 point
a ShaderNode
a VEC2 end
b ShaderNode
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 ShaderNode
a signed distance
softness float
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 ShaderNode
a signed distance
width float
the band width
softness float
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 ShaderNode
a FLOAT
a ShaderNode
a VEC3
b ShaderNode
a VEC3
c ShaderNode
a VEC3

Returns

a VEC3

opaque

public static ShaderNode opaque(ShaderNode rgb)
Opaque VEC4 from a VEC3 colour.

Parameters

rgb ShaderNode
a VEC3

Returns

a VEC4 with alpha 1