mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 19:28:57 +01:00
ebiten: Rename shader builtin functions
* imageSrcTextureSourceRegion -> imageSrcTextureRegion * image[N]TextureAt -> imageSrc[N]At * image[N]TextureBoundsAt -> imageSrc[N]BoundsAt Updates #1325
This commit is contained in:
parent
20a01ed328
commit
dd7b0d81ae
@ -24,8 +24,8 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
center := ScreenSize / 2
|
center := ScreenSize / 2
|
||||||
amount := (center - Cursor) / 10 / imageSrcTextureSize()
|
amount := (center - Cursor) / 10 / imageSrcTextureSize()
|
||||||
var clr vec3
|
var clr vec3
|
||||||
clr.r = image2TextureBoundsAt(texCoord + amount).r
|
clr.r = imageSrc2BoundsAt(texCoord + amount).r
|
||||||
clr.g = image2TextureAt(texCoord).g
|
clr.g = imageSrc2At(texCoord).g
|
||||||
clr.b = image2TextureBoundsAt(texCoord - amount).b
|
clr.b = imageSrc2BoundsAt(texCoord - amount).b
|
||||||
return vec4(clr, 1.0)
|
return vec4(clr, 1.0)
|
||||||
}
|
}
|
||||||
|
@ -2,4 +2,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\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")
|
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 = imageSrc2BoundsAt(texCoord + amount).r\n\tclr.g = imageSrc2At(texCoord).g\n\tclr.b = imageSrc2BoundsAt(texCoord - amount).b\n\treturn vec4(clr, 1.0)\n}\n")
|
||||||
|
@ -23,13 +23,13 @@ var ScreenImage vec2
|
|||||||
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||||
// Triangle wave to go 0-->1-->0...
|
// Triangle wave to go 0-->1-->0...
|
||||||
limit := abs(2*fract(Time/3) - 1)
|
limit := abs(2*fract(Time/3) - 1)
|
||||||
level := image3TextureAt(texCoord).x
|
level := imageSrc3At(texCoord).x
|
||||||
|
|
||||||
// Add a white border
|
// Add a white border
|
||||||
if limit-0.1 < level && level < limit {
|
if limit-0.1 < level && level < limit {
|
||||||
alpha := image0TextureAt(texCoord).w
|
alpha := imageSrc0At(texCoord).w
|
||||||
return vec4(alpha)
|
return vec4(alpha)
|
||||||
}
|
}
|
||||||
|
|
||||||
return step(limit, level) * image0TextureAt(texCoord)
|
return step(limit, level) * imageSrc0At(texCoord)
|
||||||
}
|
}
|
||||||
|
@ -2,4 +2,4 @@
|
|||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
var dissolve_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 ScreenImage vec2\n\nfunc Fragment(position vec4, texCoord vec2, color vec4) vec4 {\n\t// Triangle wave to go 0-->1-->0...\n\tlimit := abs(2*fract(Time/3) - 1)\n\tlevel := image3TextureAt(texCoord).x\n\n\t// Add a white border\n\tif limit-0.1 < level && level < limit {\n\t\talpha := image0TextureAt(texCoord).w\n\t\treturn vec4(alpha)\n\t}\n\n\treturn step(limit, level) * image0TextureAt(texCoord)\n}\n")
|
var dissolve_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 ScreenImage vec2\n\nfunc Fragment(position vec4, texCoord vec2, color vec4) vec4 {\n\t// Triangle wave to go 0-->1-->0...\n\tlimit := abs(2*fract(Time/3) - 1)\n\tlevel := imageSrc3At(texCoord).x\n\n\t// Add a white border\n\tif limit-0.1 < level && level < limit {\n\t\talpha := imageSrc0At(texCoord).w\n\t\treturn vec4(alpha)\n\t}\n\n\treturn step(limit, level) * imageSrc0At(texCoord)\n}\n")
|
||||||
|
@ -23,8 +23,8 @@ var ScreenSize vec2
|
|||||||
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||||
lightpos := vec3(Cursor, 50)
|
lightpos := vec3(Cursor, 50)
|
||||||
lightdir := normalize(lightpos - position.xyz)
|
lightdir := normalize(lightpos - position.xyz)
|
||||||
normal := normalize(image1TextureAt(texCoord) - 0.5)
|
normal := normalize(imageSrc1At(texCoord) - 0.5)
|
||||||
ambient := 0.25
|
ambient := 0.25
|
||||||
diffuse := 0.75 * max(0.0, dot(normal.xyz, lightdir))
|
diffuse := 0.75 * max(0.0, dot(normal.xyz, lightdir))
|
||||||
return image0TextureAt(texCoord) * (ambient + diffuse)
|
return imageSrc0At(texCoord) * (ambient + diffuse)
|
||||||
}
|
}
|
||||||
|
@ -2,4 +2,4 @@
|
|||||||
|
|
||||||
package main
|
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 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")
|
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(imageSrc1At(texCoord) - 0.5)\n\tambient := 0.25\n\tdiffuse := 0.75 * max(0.0, dot(normal.xyz, lightdir))\n\treturn imageSrc0At(texCoord) * (ambient + diffuse)\n}\n")
|
||||||
|
@ -22,7 +22,7 @@ var ScreenSize vec2
|
|||||||
|
|
||||||
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||||
dir := normalize(position.xy - Cursor)
|
dir := normalize(position.xy - Cursor)
|
||||||
clr := image2TextureAt(texCoord)
|
clr := imageSrc2At(texCoord)
|
||||||
|
|
||||||
samples := [...]float{
|
samples := [...]float{
|
||||||
-22, -14, -8, -4, -2, 2, 4, 8, 14, 22,
|
-22, -14, -8, -4, -2, 2, 4, 8, 14, 22,
|
||||||
@ -30,7 +30,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
|||||||
sum := clr
|
sum := clr
|
||||||
for i := 0; i < len(samples); i++ {
|
for i := 0; i < len(samples); i++ {
|
||||||
pos := texCoord + dir*samples[i]/imageSrcTextureSize()
|
pos := texCoord + dir*samples[i]/imageSrcTextureSize()
|
||||||
sum += image2TextureBoundsAt(pos)
|
sum += imageSrc2BoundsAt(pos)
|
||||||
}
|
}
|
||||||
sum /= 10 + 1
|
sum /= 10 + 1
|
||||||
|
|
||||||
|
@ -2,4 +2,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 := [...]float{\n\t\t-22, -14, -8, -4, -2, 2, 4, 8, 14, 22,\n\t}\n\tsum := clr\n\tfor i := 0; i < len(samples); 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")
|
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 := imageSrc2At(texCoord)\n\n\tsamples := [...]float{\n\t\t-22, -14, -8, -4, -2, 2, 4, 8, 14, 22,\n\t}\n\tsum := clr\n\tfor i := 0; i < len(samples); i++ {\n\t\tpos := texCoord + dir*samples[i]/imageSrcTextureSize()\n\t\tsum += imageSrc2BoundsAt(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")
|
||||||
|
@ -23,16 +23,16 @@ var ScreenSize vec2
|
|||||||
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||||
border := ScreenSize.y*0.6 + 4*cos(Time*3+texCoord.y*200)
|
border := ScreenSize.y*0.6 + 4*cos(Time*3+texCoord.y*200)
|
||||||
if position.y < border {
|
if position.y < border {
|
||||||
return image2TextureAt(texCoord)
|
return imageSrc2At(texCoord)
|
||||||
}
|
}
|
||||||
|
|
||||||
srcsize := imageSrcTextureSize()
|
srcsize := imageSrcTextureSize()
|
||||||
rorigin, rsize := imageSrcTextureSourceRegion()
|
rorigin, rsize := imageSrcTextureRegion()
|
||||||
|
|
||||||
xoffset := (4 / srcsize.x) * cos(Time*3+texCoord.y*200)
|
xoffset := (4 / srcsize.x) * cos(Time*3+texCoord.y*200)
|
||||||
yoffset := (20 / srcsize.y) * (1.0 + cos(Time*3+texCoord.y*50))
|
yoffset := (20 / srcsize.y) * (1.0 + cos(Time*3+texCoord.y*50))
|
||||||
bordertex := border / srcsize.y
|
bordertex := border / srcsize.y
|
||||||
clr := image2TextureBoundsAt(vec2(
|
clr := imageSrc2BoundsAt(vec2(
|
||||||
texCoord.x+xoffset,
|
texCoord.x+xoffset,
|
||||||
-(texCoord.y+yoffset-rorigin.y)+bordertex*2+rorigin.y,
|
-(texCoord.y+yoffset-rorigin.y)+bordertex*2+rorigin.y,
|
||||||
)).rgb
|
)).rgb
|
||||||
|
@ -2,4 +2,4 @@
|
|||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
var water_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\tborder := ScreenSize.y*0.6 + 4*cos(Time*3+texCoord.y*200)\n\tif position.y < border {\n\t\treturn image2TextureAt(texCoord)\n\t}\n\n\tsrcsize := imageSrcTextureSize()\n\trorigin, rsize := imageSrcTextureSourceRegion()\n\n\txoffset := (4 / srcsize.x) * cos(Time*3+texCoord.y*200)\n\tyoffset := (20 / srcsize.y) * (1.0 + cos(Time*3+texCoord.y*50))\n\tbordertex := border / srcsize.y\n\tclr := image2TextureBoundsAt(vec2(\n\t\ttexCoord.x+xoffset,\n\t\t-(texCoord.y+yoffset-rorigin.y)+bordertex*2+rorigin.y,\n\t)).rgb\n\n\toverlay := vec3(0.5, 1, 1)\n\treturn vec4(mix(clr, overlay, 0.25), 1)\n}\n")
|
var water_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\tborder := ScreenSize.y*0.6 + 4*cos(Time*3+texCoord.y*200)\n\tif position.y < border {\n\t\treturn imageSrc2At(texCoord)\n\t}\n\n\tsrcsize := imageSrcTextureSize()\n\trorigin, rsize := imageSrcTextureRegion()\n\n\txoffset := (4 / srcsize.x) * cos(Time*3+texCoord.y*200)\n\tyoffset := (20 / srcsize.y) * (1.0 + cos(Time*3+texCoord.y*50))\n\tbordertex := border / srcsize.y\n\tclr := imageSrc2BoundsAt(vec2(\n\t\ttexCoord.x+xoffset,\n\t\t-(texCoord.y+yoffset-rorigin.y)+bordertex*2+rorigin.y,\n\t)).rgb\n\n\toverlay := vec3(0.5, 1, 1)\n\treturn vec4(mix(clr, overlay, 0.25), 1)\n}\n")
|
||||||
|
@ -56,11 +56,11 @@ var __textureSourceRegionOrigin vec2
|
|||||||
// The unit is the source texture's texel.
|
// The unit is the source texture's texel.
|
||||||
var __textureSourceRegionSize vec2
|
var __textureSourceRegionSize vec2
|
||||||
|
|
||||||
// imageSrcTextureSourceRegion returns the source image's region (the origin and the size) on its texture.
|
// imageSrcTextureRegion returns the source image's region (the origin and the size) on its texture.
|
||||||
// The unit is the source texture's texel.
|
// The unit is the source texture's texel.
|
||||||
//
|
//
|
||||||
// As an image is a part of internal texture, the image can be located at an arbitrary position on the texture.
|
// As an image is a part of internal texture, the image can be located at an arbitrary position on the texture.
|
||||||
func imageSrcTextureSourceRegion() (vec2, vec2) {
|
func imageSrcTextureRegion() (vec2, vec2) {
|
||||||
return __textureSourceRegionOrigin, __textureSourceRegionSize
|
return __textureSourceRegionOrigin, __textureSourceRegionSize
|
||||||
}
|
}
|
||||||
`, graphics.ShaderImageNum, graphics.ShaderImageNum-1)
|
`, graphics.ShaderImageNum, graphics.ShaderImageNum-1)
|
||||||
@ -73,12 +73,12 @@ func imageSrcTextureSourceRegion() (vec2, vec2) {
|
|||||||
}
|
}
|
||||||
// __t%d is a special variable for a texture variable.
|
// __t%d is a special variable for a texture variable.
|
||||||
shaderSuffix += fmt.Sprintf(`
|
shaderSuffix += fmt.Sprintf(`
|
||||||
func image%[1]dTextureAt(pos vec2) vec4 {
|
func imageSrc%[1]dAt(pos vec2) vec4 {
|
||||||
// pos is the position in texels of the source texture (= 0th image's texture).
|
// pos is the position in texels of the source texture (= 0th image's texture).
|
||||||
return texture2D(__t%[1]d, %[2]s)
|
return texture2D(__t%[1]d, %[2]s)
|
||||||
}
|
}
|
||||||
|
|
||||||
func image%[1]dTextureBoundsAt(pos vec2) vec4 {
|
func imageSrc%[1]dBoundsAt(pos vec2) vec4 {
|
||||||
// pos is the position in texels of the source texture (= 0th image's texture).
|
// pos is the position in texels of the source texture (= 0th image's texture).
|
||||||
return texture2D(__t%[1]d, %[2]s) *
|
return texture2D(__t%[1]d, %[2]s) *
|
||||||
step(__textureSourceRegionOrigin.x, pos.x) *
|
step(__textureSourceRegionOrigin.x, pos.x) *
|
||||||
|
Loading…
Reference in New Issue
Block a user