gg/shader.go

70 lines
1.1 KiB
Go
Raw Permalink Normal View History

2023-10-23 15:45:18 +03:00
package gg
2023-05-22 23:39:01 +03:00
import (
"github.com/hajimehoshi/ebiten/v2"
//"fmt"
)
type Shader = ebiten.Shader
2023-05-25 00:42:48 +03:00
type ShaderOptions struct {
2023-05-27 18:00:27 +03:00
Shader *Shader
2023-05-25 00:42:48 +03:00
Uniforms map[string] any
Images [4]*Image
}
2023-05-22 23:39:01 +03:00
var (
2023-05-23 22:42:35 +03:00
// The shader is for example only.
SolidWhiteColorShader = MustNewShader([]byte(`
2023-05-22 23:39:01 +03:00
package main
2023-05-27 18:00:27 +03:00
var Random float
2023-05-23 22:42:35 +03:00
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
//ts := imageSrcTextureSize()
2023-05-25 00:42:48 +03:00
//_, size := imageSrcRegionOnTexture()
2023-05-23 22:42:35 +03:00
/*return vec4(
position.y/size.y,
position.y/size.y,
position.y/size.y,
position.y/size.y,
)*/
2023-05-25 00:42:48 +03:00
/*py := int(position.y / size.y) % 5
2023-05-23 22:42:35 +03:00
px := int(position.x / size.x) % 5
if py >= 1 && px >= 1 {
return vec4(
1,
0,
0,
1,
)
2023-05-25 00:42:48 +03:00
}*/
2023-05-23 22:42:35 +03:00
2023-05-27 18:00:27 +03:00
/*ret := vec4(
2023-05-23 22:42:35 +03:00
0,
2023-05-25 00:42:48 +03:00
sin(position.x),
sin(position.y),
2023-05-23 22:42:35 +03:00
1,
)
2023-05-25 00:42:48 +03:00
2023-05-27 18:00:27 +03:00
return imageSrc0UnsafeAt(texCoord) * (ret)*/
return imageSrc0UnsafeAt(texCoord) *
vec4(1, 1, Random, Random)
2023-05-22 23:39:01 +03:00
}
`))
)
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)
}