From bc930ed0ecccad8452e3bd5ea1cf24fcff940e0c Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Tue, 11 Aug 2020 02:16:16 +0900 Subject: [PATCH] Revert "examples/shader: Rename ScreenSize -> ImageSize" This reverts commit 3893f9cdbe0697142514773127cc541dadb09d24. Reason: The screen size and the image size can be different. --- examples/shader/chromaticaberration.go | 4 ++-- examples/shader/chromaticaberration_go.go | 2 +- examples/shader/default.go | 2 +- examples/shader/default_go.go | 2 +- examples/shader/lighting.go | 2 +- examples/shader/lighting_go.go | 2 +- examples/shader/main.go | 3 +-- examples/shader/radialblur.go | 2 +- examples/shader/radialblur_go.go | 2 +- 9 files changed, 10 insertions(+), 11 deletions(-) diff --git a/examples/shader/chromaticaberration.go b/examples/shader/chromaticaberration.go index cb791aff8..48e3e1f5c 100644 --- a/examples/shader/chromaticaberration.go +++ b/examples/shader/chromaticaberration.go @@ -18,10 +18,10 @@ package main var Time float var Cursor vec2 -var ImageSize vec2 +var ScreenSize vec2 func Fragment(position vec4, texCoord vec2, color vec4) vec4 { - center := ImageSize / 2 + center := ScreenSize / 2 amount := (center - Cursor) / image2TextureSize() / 10 var clr vec3 clr.r = image2TextureAt(vec2(texCoord.x+amount.x, texCoord.y)).r diff --git a/examples/shader/chromaticaberration_go.go b/examples/shader/chromaticaberration_go.go index 330620e54..926c8da23 100644 --- a/examples/shader/chromaticaberration_go.go +++ b/examples/shader/chromaticaberration_go.go @@ -3,4 +3,4 @@ package main -var chromaticaberration_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\nvar ImageSize vec2\n\nfunc Fragment(position vec4, texCoord vec2, color vec4) vec4 {\n\tcenter := ImageSize / 2\n\tamount := (center - Cursor) / image2TextureSize() / 10\n\tvar clr vec3\n\tclr.r = image2TextureAt(vec2(texCoord.x+amount.x, texCoord.y)).r\n\tclr.g = image2TextureAt(texCoord).g\n\tclr.b = image2TextureAt(vec2(texCoord.x-amount.x, texCoord.y)).b\n\treturn vec4(clr, 1.0)\n}\n") +var chromaticaberration_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\nvar ScreenSize vec2\n\nfunc Fragment(position vec4, texCoord vec2, color vec4) vec4 {\n\tcenter := ScreenSize / 2\n\tamount := (center - Cursor) / image2TextureSize() / 10\n\tvar clr vec3\n\tclr.r = image2TextureAt(vec2(texCoord.x+amount.x, texCoord.y)).r\n\tclr.g = image2TextureAt(texCoord).g\n\tclr.b = image2TextureAt(vec2(texCoord.x-amount.x, texCoord.y)).b\n\treturn vec4(clr, 1.0)\n}\n") diff --git a/examples/shader/default.go b/examples/shader/default.go index b726bf4e0..38b7f6189 100644 --- a/examples/shader/default.go +++ b/examples/shader/default.go @@ -18,7 +18,7 @@ package main var Time float var Cursor vec2 -var ImageSize vec2 +var ScreenSize vec2 func Fragment(position vec4, texCoord vec2, color vec4) vec4 { pos := position.xy/imageDstTextureSize() + Cursor/imageDstTextureSize()/4 diff --git a/examples/shader/default_go.go b/examples/shader/default_go.go index 669a1b06c..bff3eca8f 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\nvar ImageSize vec2\n\nfunc Fragment(position vec4, texCoord vec2, color vec4) vec4 {\n\tpos := position.xy/imageDstTextureSize() + Cursor/imageDstTextureSize()/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\nvar ScreenSize vec2\n\nfunc Fragment(position vec4, texCoord vec2, color vec4) vec4 {\n\tpos := position.xy/imageDstTextureSize() + Cursor/imageDstTextureSize()/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/examples/shader/lighting.go b/examples/shader/lighting.go index 1bfaba87b..063c9409a 100644 --- a/examples/shader/lighting.go +++ b/examples/shader/lighting.go @@ -18,7 +18,7 @@ package main var Time float var Cursor vec2 -var ImageSize vec2 +var ScreenSize vec2 func Fragment(position vec4, texCoord vec2, color vec4) vec4 { lightpos := vec3(Cursor, 50) diff --git a/examples/shader/lighting_go.go b/examples/shader/lighting_go.go index ce8b66601..8d733eb42 100644 --- a/examples/shader/lighting_go.go +++ b/examples/shader/lighting_go.go @@ -3,4 +3,4 @@ package main -var lighting_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\nvar ImageSize vec2\n\nfunc Fragment(position vec4, texCoord vec2, color vec4) vec4 {\n\tlightpos := vec3(Cursor, 50)\n\tlightdir := normalize(lightpos - position.xyz)\n\tnormal := normalize(image1TextureAt(texCoord) - 0.5)\n\tambient := 0.25\n\tdiffuse := 0.75 * max(0.0, dot(normal.xyz, lightdir))\n\treturn image0TextureAt(texCoord) * (ambient + diffuse)\n}\n") +var lighting_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\nvar ScreenSize vec2\n\nfunc Fragment(position vec4, texCoord vec2, color vec4) vec4 {\n\tlightpos := vec3(Cursor, 50)\n\tlightdir := normalize(lightpos - position.xyz)\n\tnormal := normalize(image1TextureAt(texCoord) - 0.5)\n\tambient := 0.25\n\tdiffuse := 0.75 * max(0.0, dot(normal.xyz, lightdir))\n\treturn image0TextureAt(texCoord) * (ambient + diffuse)\n}\n") diff --git a/examples/shader/main.go b/examples/shader/main.go index e86c22d4a..0cdd58ad7 100644 --- a/examples/shader/main.go +++ b/examples/shader/main.go @@ -122,9 +122,8 @@ func (g *Game) Draw(screen *ebiten.Image) { op.Uniforms = []interface{}{ float32(g.time) / 60, // Time []float32{float32(cx), float32(cy)}, // Cursor - []float32{float32(w), float32(h)}, // ImageSize + []float32{float32(w), float32(h)}, // ScreenSize } - // All the image sizes are (w, h). op.Images[0] = gopherImage op.Images[1] = normalImage op.Images[2] = gopherBgImage diff --git a/examples/shader/radialblur.go b/examples/shader/radialblur.go index 6b1e59da0..0b683bcfb 100644 --- a/examples/shader/radialblur.go +++ b/examples/shader/radialblur.go @@ -18,7 +18,7 @@ package main var Time float var Cursor vec2 -var ImageSize vec2 +var ScreenSize vec2 func Fragment(position vec4, texCoord vec2, color vec4) vec4 { dir := normalize(position.xy - Cursor) diff --git a/examples/shader/radialblur_go.go b/examples/shader/radialblur_go.go index 070899539..aae2afbef 100644 --- a/examples/shader/radialblur_go.go +++ b/examples/shader/radialblur_go.go @@ -3,4 +3,4 @@ package main -var radialblur_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\nvar ImageSize vec2\n\nfunc Fragment(position vec4, texCoord vec2, color vec4) vec4 {\n\tdir := normalize(position.xy - Cursor)\n\tclr := image2TextureAt(texCoord)\n\n\tsamples := [10]float{\n\t\t-22, -14, -8, -4, -2, 2, 4, 8, 14, 22,\n\t}\n\t// TODO: Add len(samples)\n\tsum := clr\n\tfor i := 0; i < 10; i++ {\n\t\t// TODO: Consider the source region not to violate the region.\n\t\tsum += image2TextureAt(texCoord + dir*samples[i]/image2TextureSize())\n\t}\n\tsum /= 10 + 1\n\n\tdist := distance(position.xy, Cursor)\n\tt := clamp(dist/256, 0, 1)\n\treturn mix(clr, sum, t)\n}\n") +var radialblur_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\nvar ScreenSize vec2\n\nfunc Fragment(position vec4, texCoord vec2, color vec4) vec4 {\n\tdir := normalize(position.xy - Cursor)\n\tclr := image2TextureAt(texCoord)\n\n\tsamples := [10]float{\n\t\t-22, -14, -8, -4, -2, 2, 4, 8, 14, 22,\n\t}\n\t// TODO: Add len(samples)\n\tsum := clr\n\tfor i := 0; i < 10; i++ {\n\t\t// TODO: Consider the source region not to violate the region.\n\t\tsum += image2TextureAt(texCoord + dir*samples[i]/image2TextureSize())\n\t}\n\tsum /= 10 + 1\n\n\tdist := distance(position.xy, Cursor)\n\tt := clamp(dist/256, 0, 1)\n\treturn mix(clr, sum, t)\n}\n")