From 2fb5108bbeb92c900e8ceed65fe426f5bb78be65 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sun, 26 Jul 2020 00:03:52 +0900 Subject: [PATCH] shader: Rename viewportSize to textureDstSize Updates #1239 --- examples/shader/default.go | 4 +--- examples/shader/default_go.go | 2 +- shader.go | 10 +++++----- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/examples/shader/default.go b/examples/shader/default.go index 3ecd38dbe..6c2625e86 100644 --- a/examples/shader/default.go +++ b/examples/shader/default.go @@ -19,10 +19,8 @@ package main var Time float var Cursor vec2 -// viewportSize is a predefined function. - func Fragment(position vec4, texCoord vec2, color vec4) vec4 { - pos := position.xy/viewportSize() + Cursor/viewportSize()/4 + pos := position.xy/textureDstSize() + Cursor/textureDstSize()/4 clr := 0.0 clr += sin(pos.x*cos(Time/15)*80) + cos(pos.y*cos(Time/15)*10) clr += sin(pos.y*sin(Time/10)*40) + cos(pos.x*sin(Time/25)*40) diff --git a/examples/shader/default_go.go b/examples/shader/default_go.go index 4317b3c54..97b7dda0a 100644 --- a/examples/shader/default_go.go +++ b/examples/shader/default_go.go @@ -3,4 +3,4 @@ package main -var default_go = []byte("// Copyright 2020 The Ebiten Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n// +build ignore\n\npackage main\n\nvar Time float\nvar Cursor vec2\n\n// viewportSize is a predefined function.\n\nfunc Fragment(position vec4, texCoord vec2, color vec4) vec4 {\n\tpos := position.xy/viewportSize() + Cursor/viewportSize()/4\n\tclr := 0.0\n\tclr += sin(pos.x*cos(Time/15)*80) + cos(pos.y*cos(Time/15)*10)\n\tclr += sin(pos.y*sin(Time/10)*40) + cos(pos.x*sin(Time/25)*40)\n\tclr += sin(pos.x*sin(Time/5)*10) + sin(pos.y*sin(Time/35)*80)\n\tclr *= sin(Time/10) * 0.5\n\treturn vec4(clr, clr*0.5, sin(clr+Time/3)*0.75, 1)\n}\n") +var default_go = []byte("// Copyright 2020 The Ebiten Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n// +build ignore\n\npackage main\n\nvar Time float\nvar Cursor vec2\n\nfunc Fragment(position vec4, texCoord vec2, color vec4) vec4 {\n\tpos := position.xy/textureDstSize() + Cursor/textureDstSize()/4\n\tclr := 0.0\n\tclr += sin(pos.x*cos(Time/15)*80) + cos(pos.y*cos(Time/15)*10)\n\tclr += sin(pos.y*sin(Time/10)*40) + cos(pos.x*sin(Time/25)*40)\n\tclr += sin(pos.x*sin(Time/5)*10) + sin(pos.y*sin(Time/35)*80)\n\tclr *= sin(Time/10) * 0.5\n\treturn vec4(clr, clr*0.5, sin(clr+Time/3)*0.75, 1)\n}\n") diff --git a/shader.go b/shader.go index 627b424d8..57de4554b 100644 --- a/shader.go +++ b/shader.go @@ -29,16 +29,16 @@ var shaderSuffix string func init() { shaderSuffix = ` -var __viewportSize vec2 +var __textureDstSize vec2 -func viewportSize() vec2 { - return __viewportSize +func textureDstSize() vec2 { + return __textureDstSize } func __vertex(position vec2, texCoord vec2, color vec4) (vec4, vec2, vec4) { return mat4( - 2/viewportSize().x, 0, 0, 0, - 0, 2/viewportSize().y, 0, 0, + 2/textureDstSize().x, 0, 0, 0, + 0, 2/textureDstSize().y, 0, 0, 0, 0, 1, 0, -1, -1, 0, 1, ) * vec4(position, 0, 1), texCoord, color