gg/shader.go

57 lines
979 B
Go

package gg
import (
"github.com/hajimehoshi/ebiten/v2"
//"fmt"
)
type Shader = ebiten.Shader
type ShaderOptions struct {
Shader *Shader
Uniforms map[string] any
Images [4]*Image
}
var (
// The shader is for example only.
SolidWhiteColorShader = MustNewShader([]byte(`
package main
//var Random float
func Fragment(dst vec4, src vec2, _ vec4) vec4 {
c := imageSrc0UnsafeAt(src)
size := imageSrc0Size()
//ret := vec4(0.1) * src.x/size.x
//ret := c * src.x/size.x
//ret.r = 1
//ret.a = c.a
//c.a = 0
//c.rg = vec2(0)
//c.a = c.b
//ret := vec4(1, 1, 1, 0)
//ret.a /= 5
//ret.a = src.x
//c.a /= 5
//c = vec4(c.a)
orig := imageSrc0Origin()
src -= orig
c.a *= (size.x-src.x)/size.x
return c
}
`))
)
func MustNewShader(src []byte) (*Shader) {
shader, err := NewShader(src)
if err != nil {
panic(err)
}
return shader
}
func NewShader(src []byte) (*Shader, error) {
return ebiten.NewShader(src)
}