mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
ebiten: Rename shader functions to get colors from textures
Updates #1325
This commit is contained in:
parent
b52de27d49
commit
9f7d6962ff
@ -24,8 +24,8 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||
center := ScreenSize / 2
|
||||
amount := (center - Cursor) / 10 / imageSrcTextureSize()
|
||||
var clr vec3
|
||||
clr.r = imageSrc2BoundsAt(texCoord + amount).r
|
||||
clr.g = imageSrc2At(texCoord).g
|
||||
clr.b = imageSrc2BoundsAt(texCoord - amount).b
|
||||
clr.r = imageSrc2At(texCoord + amount).r
|
||||
clr.g = imageSrc2UnsafeAt(texCoord).g
|
||||
clr.b = imageSrc2At(texCoord - amount).b
|
||||
return vec4(clr, 1.0)
|
||||
}
|
||||
|
@ -2,4 +2,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\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")
|
||||
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 = imageSrc2At(texCoord + amount).r\n\tclr.g = imageSrc2UnsafeAt(texCoord).g\n\tclr.b = imageSrc2At(texCoord - amount).b\n\treturn vec4(clr, 1.0)\n}\n")
|
||||
|
@ -23,13 +23,13 @@ var ScreenSize vec2
|
||||
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||
// Triangle wave to go 0-->1-->0...
|
||||
limit := abs(2*fract(Time/3) - 1)
|
||||
level := imageSrc3At(texCoord).x
|
||||
level := imageSrc3UnsafeAt(texCoord).x
|
||||
|
||||
// Add a white border
|
||||
if limit-0.1 < level && level < limit {
|
||||
alpha := imageSrc0At(texCoord).w
|
||||
alpha := imageSrc0UnsafeAt(texCoord).w
|
||||
return vec4(alpha)
|
||||
}
|
||||
|
||||
return step(limit, level) * imageSrc0At(texCoord)
|
||||
return step(limit, level) * imageSrc0UnsafeAt(texCoord)
|
||||
}
|
||||
|
@ -2,4 +2,4 @@
|
||||
|
||||
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 ScreenSize 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")
|
||||
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 ScreenSize 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 := imageSrc3UnsafeAt(texCoord).x\n\n\t// Add a white border\n\tif limit-0.1 < level && level < limit {\n\t\talpha := imageSrc0UnsafeAt(texCoord).w\n\t\treturn vec4(alpha)\n\t}\n\n\treturn step(limit, level) * imageSrc0UnsafeAt(texCoord)\n}\n")
|
||||
|
@ -23,8 +23,8 @@ var ScreenSize vec2
|
||||
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||
lightpos := vec3(Cursor, 50)
|
||||
lightdir := normalize(lightpos - position.xyz)
|
||||
normal := normalize(imageSrc1At(texCoord) - 0.5)
|
||||
normal := normalize(imageSrc1UnsafeAt(texCoord) - 0.5)
|
||||
ambient := 0.25
|
||||
diffuse := 0.75 * max(0.0, dot(normal.xyz, lightdir))
|
||||
return imageSrc0At(texCoord) * (ambient + diffuse)
|
||||
return imageSrc0UnsafeAt(texCoord) * (ambient + diffuse)
|
||||
}
|
||||
|
@ -2,4 +2,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 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")
|
||||
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(imageSrc1UnsafeAt(texCoord) - 0.5)\n\tambient := 0.25\n\tdiffuse := 0.75 * max(0.0, dot(normal.xyz, lightdir))\n\treturn imageSrc0UnsafeAt(texCoord) * (ambient + diffuse)\n}\n")
|
||||
|
@ -22,7 +22,7 @@ var ScreenSize vec2
|
||||
|
||||
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||
dir := normalize(position.xy - Cursor)
|
||||
clr := imageSrc2At(texCoord)
|
||||
clr := imageSrc2UnsafeAt(texCoord)
|
||||
|
||||
samples := [...]float{
|
||||
-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
|
||||
for i := 0; i < len(samples); i++ {
|
||||
pos := texCoord + dir*samples[i]/imageSrcTextureSize()
|
||||
sum += imageSrc2BoundsAt(pos)
|
||||
sum += imageSrc2At(pos)
|
||||
}
|
||||
sum /= 10 + 1
|
||||
|
||||
|
@ -2,4 +2,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 := 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")
|
||||
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 := imageSrc2UnsafeAt(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 += imageSrc2At(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,7 +23,7 @@ var ScreenSize vec2
|
||||
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||
border := ScreenSize.y*0.6 + 4*cos(Time*3+texCoord.y*200)
|
||||
if position.y < border {
|
||||
return imageSrc2At(texCoord)
|
||||
return imageSrc2UnsafeAt(texCoord)
|
||||
}
|
||||
|
||||
srcsize := imageSrcTextureSize()
|
||||
@ -32,7 +32,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||
xoffset := (4 / srcsize.x) * cos(Time*3+texCoord.y*200)
|
||||
yoffset := (20 / srcsize.y) * (1.0 + cos(Time*3+texCoord.y*50))
|
||||
bordertex := border / srcsize.y
|
||||
clr := imageSrc2BoundsAt(vec2(
|
||||
clr := imageSrc2At(vec2(
|
||||
texCoord.x+xoffset,
|
||||
-(texCoord.y+yoffset-rorigin.y)+bordertex*2+rorigin.y,
|
||||
)).rgb
|
||||
|
@ -2,4 +2,4 @@
|
||||
|
||||
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 imageSrc2At(texCoord)\n\t}\n\n\tsrcsize := imageSrcTextureSize()\n\trorigin, _ := 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")
|
||||
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 imageSrc2UnsafeAt(texCoord)\n\t}\n\n\tsrcsize := imageSrcTextureSize()\n\trorigin, _ := 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 := imageSrc2At(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")
|
||||
|
@ -75,12 +75,12 @@ func imageSrcTextureRegion() (vec2, vec2) {
|
||||
}
|
||||
// __t%d is a special variable for a texture variable.
|
||||
shaderSuffix += fmt.Sprintf(`
|
||||
func imageSrc%[1]dAt(pos vec2) vec4 {
|
||||
func imageSrc%[1]dUnsafeAt(pos vec2) vec4 {
|
||||
// pos is the position in texels of the source texture (= 0th image's texture).
|
||||
return texture2D(__t%[1]d, %[2]s)
|
||||
}
|
||||
|
||||
func imageSrc%[1]dBoundsAt(pos vec2) vec4 {
|
||||
func imageSrc%[1]dAt(pos vec2) vec4 {
|
||||
// pos is the position in texels of the source texture (= 0th image's texture).
|
||||
return texture2D(__t%[1]d, %[2]s) *
|
||||
step(__textureSourceRegionOrigin.x, pos.x) *
|
||||
|
Loading…
Reference in New Issue
Block a user