mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-02-04 15:04:28 +01:00
parent
ea6fce45ff
commit
0651803c40
@ -14,14 +14,19 @@
|
|||||||
|
|
||||||
//go:build ignore
|
//go:build ignore
|
||||||
|
|
||||||
|
// Specify the 'pixel' mode.
|
||||||
//kage:unit pixels
|
//kage:unit pixels
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
|
// Uniform variables.
|
||||||
var Time float
|
var Time float
|
||||||
var Cursor vec2
|
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 {
|
func Fragment(dstPos vec4, srcPos vec2, color vec4) vec4 {
|
||||||
|
// You can define variables with a short variable declaration like Go.
|
||||||
pos := dstPos.xy - imageDstOrigin()
|
pos := dstPos.xy - imageDstOrigin()
|
||||||
|
|
||||||
lightpos := vec3(Cursor, 50)
|
lightpos := vec3(Cursor, 50)
|
||||||
@ -29,5 +34,8 @@ func Fragment(dstPos vec4, srcPos vec2, color vec4) vec4 {
|
|||||||
normal := normalize(imageSrc1UnsafeAt(srcPos) - 0.5)
|
normal := normalize(imageSrc1UnsafeAt(srcPos) - 0.5)
|
||||||
const ambient = 0.25
|
const ambient = 0.25
|
||||||
diffuse := 0.75 * max(0.0, dot(normal.xyz, lightdir))
|
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)
|
return imageSrc0UnsafeAt(srcPos) * (ambient + diffuse)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user