examples/shader: add comments

Updates ebitengine/ebitengine.org#29
This commit is contained in:
Hajime Hoshi 2024-03-23 15:45:53 +09:00
parent ea6fce45ff
commit 0651803c40

View File

@ -14,14 +14,19 @@
//go:build ignore
// Specify the 'pixel' mode.
//kage:unit pixels
package main
// Uniform variables.
var Time float
var Cursor vec2
// Fragment is the entry point of the fragment shader.
// Fragment returns the color value for the current position.
func Fragment(dstPos vec4, srcPos vec2, color vec4) vec4 {
// You can define variables with a short variable declaration like Go.
pos := dstPos.xy - imageDstOrigin()
lightpos := vec3(Cursor, 50)
@ -29,5 +34,8 @@ func Fragment(dstPos vec4, srcPos vec2, color vec4) vec4 {
normal := normalize(imageSrc1UnsafeAt(srcPos) - 0.5)
const ambient = 0.25
diffuse := 0.75 * max(0.0, dot(normal.xyz, lightdir))
// You can treat multiple source images by
// imageSrc[N]At or imageSrc[N]UnsafeAt.
return imageSrc0UnsafeAt(srcPos) * (ambient + diffuse)
}