mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 11:18:54 +01:00
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:
parent
b95195ab71
commit
70acb9c1f6
@ -22,9 +22,7 @@ var ScreenSize vec2
|
|||||||
|
|
||||||
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||||
center := ScreenSize / 2
|
center := ScreenSize / 2
|
||||||
// As texel coodinates should be image0's texture texels, image0TextureSize should be used.
|
amount := (center - Cursor) / 10 / imageSrcTextureSize()
|
||||||
// TODO: This seems too tricky. Improve the API.
|
|
||||||
amount := (center - Cursor) / image0TextureSize() / 10
|
|
||||||
var clr vec3
|
var clr vec3
|
||||||
clr.r = image2TextureBoundsAt(texCoord + amount).r
|
clr.r = image2TextureBoundsAt(texCoord + amount).r
|
||||||
clr.g = image2TextureAt(texCoord).g
|
clr.g = image2TextureAt(texCoord).g
|
||||||
|
@ -3,4 +3,4 @@
|
|||||||
|
|
||||||
package main
|
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")
|
||||||
|
@ -30,9 +30,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
// TODO: Add len(samples)
|
// TODO: Add len(samples)
|
||||||
sum := clr
|
sum := clr
|
||||||
for i := 0; i < 10; i++ {
|
for i := 0; i < 10; i++ {
|
||||||
// As texCoord is image0's texture texels, use image0TextureSize.
|
pos := texCoord + dir*samples[i]/imageSrcTextureSize()
|
||||||
// TODO: This seems too tricky. Improve the API.
|
|
||||||
pos := texCoord + dir*samples[i]/image0TextureSize()
|
|
||||||
sum += image2TextureBoundsAt(pos)
|
sum += image2TextureBoundsAt(pos)
|
||||||
}
|
}
|
||||||
sum /= 10 + 1
|
sum /= 10 + 1
|
||||||
|
@ -3,4 +3,4 @@
|
|||||||
|
|
||||||
package main
|
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")
|
||||||
|
16
shader.go
16
shader.go
@ -37,27 +37,21 @@ func imageDstTextureSize() vec2 {
|
|||||||
`
|
`
|
||||||
|
|
||||||
shaderSuffix += fmt.Sprintf(`
|
shaderSuffix += fmt.Sprintf(`
|
||||||
var __textureSizes [%d]vec2
|
var __textureSizes [%[1]d]vec2
|
||||||
`, graphics.ShaderImageNum)
|
|
||||||
|
|
||||||
for i := 0; i < graphics.ShaderImageNum; i++ {
|
func imageSrcTextureSize() vec2 {
|
||||||
shaderSuffix += fmt.Sprintf(`
|
return __textureSizes[0]
|
||||||
func image%[1]dTextureSize() vec2 {
|
|
||||||
return __textureSizes[%[1]d]
|
|
||||||
}
|
}
|
||||||
`, i)
|
|
||||||
}
|
|
||||||
|
|
||||||
shaderSuffix += fmt.Sprintf(`
|
|
||||||
// The unit is texture0's texels.
|
// The unit is texture0's texels.
|
||||||
var __textureSourceOffsets [%[1]d]vec2
|
var __textureSourceOffsets [%[2]d]vec2
|
||||||
|
|
||||||
// The unit is texture0's texels.
|
// The unit is texture0's texels.
|
||||||
var __textureSourceOrigin vec2
|
var __textureSourceOrigin vec2
|
||||||
|
|
||||||
// The unit is texture0's texels.
|
// The unit is texture0's texels.
|
||||||
var __textureSourceSize vec2
|
var __textureSourceSize vec2
|
||||||
`, graphics.ShaderImageNum-1, graphics.ShaderImageNum)
|
`, graphics.ShaderImageNum, graphics.ShaderImageNum-1)
|
||||||
|
|
||||||
for i := 0; i < graphics.ShaderImageNum; i++ {
|
for i := 0; i < graphics.ShaderImageNum; i++ {
|
||||||
pos := "pos"
|
pos := "pos"
|
||||||
|
Loading…
Reference in New Issue
Block a user