shader: Add a builtin function viewportSize

This commit is contained in:
Hajime Hoshi 2020-06-10 23:07:57 +09:00
parent 92e1c6cf2d
commit b64dc627e9
2 changed files with 9 additions and 6 deletions

View File

@ -29,20 +29,19 @@ const (
const shaderSrc = `package main
// __viewportSize is a predefined uniform variable.
// TODO: Hide this by a function.
// viewportSize is a predefined function.
func Vertex(position vec2, texCoord vec2, color vec4) vec4 {
return mat4(
2.0/__viewportSize.x, 0, 0, 0,
0, 2.0/__viewportSize.y, 0, 0,
2.0/viewportSize().x, 0, 0, 0,
0, 2.0/viewportSize().y, 0, 0,
0, 0, 1, 0,
-1, -1, 0, 1,
) * vec4(position, 0, 1)
}
func Fragment(position vec4) vec4 {
return vec4(position.x/__viewportSize.x, position.y/__viewportSize.y, 0, 1)
return vec4(position.x/viewportSize().x, position.y/viewportSize().y, 0, 1)
}`
type Game struct {

View File

@ -24,7 +24,11 @@ import (
)
const shaderSuffix = `
var __viewportSize vec2`
var __viewportSize vec2
func viewportSize() vec2 {
return __viewportSize
}`
type Shader struct {
shader *buffered.Shader