diff --git a/orx-shade-styles/src/commonMain/kotlin/spatial/HemisphereLight.kt b/orx-shade-styles/src/commonMain/kotlin/spatial/HemisphereLight.kt new file mode 100644 index 00000000..d6f4ed59 --- /dev/null +++ b/orx-shade-styles/src/commonMain/kotlin/spatial/HemisphereLight.kt @@ -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() + } +} \ No newline at end of file diff --git a/orx-shade-styles/src/jvmDemo/kotlin/spatial/DemoHemisphere01.kt b/orx-shade-styles/src/jvmDemo/kotlin/spatial/DemoHemisphere01.kt new file mode 100644 index 00000000..1ff8c0cf --- /dev/null +++ b/orx-shade-styles/src/jvmDemo/kotlin/spatial/DemoHemisphere01.kt @@ -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) + } + } + } +} \ No newline at end of file