shader: Rename shader bultin functions

Renamed image0TextureSize to imageSrcTextureSize, and removed the
other texture-size functions.

As texture-coordinates are always in image0's texture texels,
calculations with texels are always done with image0's texture texels.
Then, other texture-size functions are useless. To avoid confusion,
let's remove the functions and leave the necessary funciton.
This commit is contained in:
Hajime Hoshi 2020-08-11 05:02:22 +09:00
parent b95195ab71
commit 70acb9c1f6
5 changed files with 9 additions and 19 deletions

View File

@ -22,9 +22,7 @@ var ScreenSize vec2
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
center := ScreenSize / 2
// As texel coodinates should be image0's texture texels, image0TextureSize should be used.
// TODO: This seems too tricky. Improve the API.
amount := (center - Cursor) / image0TextureSize() / 10
amount := (center - Cursor) / 10 / imageSrcTextureSize()
var clr vec3
clr.r = image2TextureBoundsAt(texCoord + amount).r
clr.g = image2TextureAt(texCoord).g

View File

@ -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 ScreenSize vec2\n\nfunc Fragment(position vec4, texCoord vec2, color vec4) vec4 {\n\tcenter := ScreenSize / 2\n\t// As texel coodinates should be image0's texture texels, image0TextureSize should be used.\n\t// TODO: This seems too tricky. Improve the API.\n\tamount := (center - Cursor) / image0TextureSize() / 10\n\tvar clr vec3\n\tclr.r = image2TextureBoundsAt(texCoord + amount).r\n\tclr.g = image2TextureAt(texCoord).g\n\tclr.b = image2TextureBoundsAt(texCoord - amount).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) / 10 / imageSrcTextureSize()\n\tvar clr vec3\n\tclr.r = image2TextureBoundsAt(texCoord + amount).r\n\tclr.g = image2TextureAt(texCoord).g\n\tclr.b = image2TextureBoundsAt(texCoord - amount).b\n\treturn vec4(clr, 1.0)\n}\n")

View File

@ -30,9 +30,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
// TODO: Add len(samples)
sum := clr
for i := 0; i < 10; i++ {
// As texCoord is image0's texture texels, use image0TextureSize.
// TODO: This seems too tricky. Improve the API.
pos := texCoord + dir*samples[i]/image0TextureSize()
pos := texCoord + dir*samples[i]/imageSrcTextureSize()
sum += image2TextureBoundsAt(pos)
}
sum /= 10 + 1

View File

@ -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 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// As texCoord is image0's texture texels, use image0TextureSize.\n\t\t// TODO: This seems too tricky. Improve the API.\n\t\tpos := texCoord + dir*samples[i]/image0TextureSize()\n\t\tsum += image2TextureBoundsAt(pos)\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\tpos := texCoord + dir*samples[i]/imageSrcTextureSize()\n\t\tsum += image2TextureBoundsAt(pos)\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")

View File

@ -37,27 +37,21 @@ func imageDstTextureSize() vec2 {
`
shaderSuffix += fmt.Sprintf(`
var __textureSizes [%d]vec2
`, graphics.ShaderImageNum)
var __textureSizes [%[1]d]vec2
for i := 0; i < graphics.ShaderImageNum; i++ {
shaderSuffix += fmt.Sprintf(`
func image%[1]dTextureSize() vec2 {
return __textureSizes[%[1]d]
}
`, i)
func imageSrcTextureSize() vec2 {
return __textureSizes[0]
}
shaderSuffix += fmt.Sprintf(`
// The unit is texture0's texels.
var __textureSourceOffsets [%[1]d]vec2
var __textureSourceOffsets [%[2]d]vec2
// The unit is texture0's texels.
var __textureSourceOrigin vec2
// The unit is texture0's texels.
var __textureSourceSize vec2
`, graphics.ShaderImageNum-1, graphics.ShaderImageNum)
`, graphics.ShaderImageNum, graphics.ShaderImageNum-1)
for i := 0; i < graphics.ShaderImageNum; i++ {
pos := "pos"