[orx-shade-styles] Add HemisphereLight shader and demo example
Introduce the `HemisphereLight` shader for smooth gradient lighting based on surface orientation relative to a light direction. Add a demo featuring the Suzanne model to showcase the shader in action.
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
package org.openrndr.extra.shadestyles.spatial
|
||||
|
||||
import org.openrndr.color.ColorRGBa
|
||||
import org.openrndr.draw.ShadeStyle
|
||||
import org.openrndr.math.Vector3
|
||||
|
||||
class HemisphereLight: ShadeStyle() {
|
||||
var upColor: ColorRGBa by Parameter()
|
||||
var downColor: ColorRGBa by Parameter()
|
||||
var lightDirection: Vector3 by Parameter()
|
||||
|
||||
init {
|
||||
lightDirection = -Vector3.UNIT_Y
|
||||
upColor = ColorRGBa.WHITE
|
||||
downColor = ColorRGBa.BLACK
|
||||
fragmentTransform = """
|
||||
vec3 n = normalize(v_worldNormal);
|
||||
float d = dot(n, p_lightDirection) * 0.5 + 0.5;
|
||||
x_fill = mix(p_upColor, p_downColor, d);
|
||||
""".trimIndent()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package spatial
|
||||
|
||||
import org.openrndr.WindowMultisample
|
||||
import org.openrndr.application
|
||||
import org.openrndr.color.ColorRGBa
|
||||
import org.openrndr.draw.DrawPrimitive
|
||||
import org.openrndr.extra.camera.Orbital
|
||||
import org.openrndr.extra.color.presets.SADDLE_BROWN
|
||||
import org.openrndr.extra.objloader.loadOBJasVertexBuffer
|
||||
import org.openrndr.extra.shadestyles.spatial.HemisphereLight
|
||||
import org.openrndr.math.Vector3
|
||||
|
||||
fun main() {
|
||||
application {
|
||||
configure {
|
||||
width = 720
|
||||
height = 720
|
||||
multisample = WindowMultisample.SampleCount(8)
|
||||
}
|
||||
|
||||
program {
|
||||
val obj = loadOBJasVertexBuffer("demo-data/obj-models/suzanne/Suzanne.obj")
|
||||
|
||||
extend(Orbital()) {
|
||||
eye = Vector3(0.0, 0.0, 2.0)
|
||||
}
|
||||
extend {
|
||||
drawer.shadeStyle = HemisphereLight().apply {
|
||||
downColor = ColorRGBa.SADDLE_BROWN
|
||||
}
|
||||
drawer.vertexBuffer(obj, DrawPrimitive.TRIANGLES)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user