From fec9cae66a7e2f5d8d016ad2e94b99a1ac38b62e Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Mon, 10 Aug 2020 21:12:34 +0900 Subject: [PATCH] examples/shader: Merge generate.go and main.go --- examples/shader/chromaticaberration_go.go | 2 +- examples/shader/default_go.go | 2 +- examples/shader/generate.go | 20 -------------------- examples/shader/lighting_go.go | 2 +- examples/shader/main.go | 5 +++++ examples/shader/radialblur_go.go | 2 +- 6 files changed, 9 insertions(+), 24 deletions(-) delete mode 100644 examples/shader/generate.go diff --git a/examples/shader/chromaticaberration_go.go b/examples/shader/chromaticaberration_go.go index 6371e800c..d16bff2e4 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\r\n//\r\n// Licensed under the Apache License, Version 2.0 (the \"License\");\r\n// you may not use this file except in compliance with the License.\r\n// You may obtain a copy of the License at\r\n//\r\n// http://www.apache.org/licenses/LICENSE-2.0\r\n//\r\n// Unless required by applicable law or agreed to in writing, software\r\n// distributed under the License is distributed on an \"AS IS\" BASIS,\r\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n// See the License for the specific language governing permissions and\r\n// limitations under the License.\r\n\r\n// +build ignore\r\n\r\npackage main\r\n\r\nvar Time float\r\nvar Cursor vec2\r\nvar ScreenSize vec2\r\n\r\nfunc Fragment(position vec4, texCoord vec2, color vec4) vec4 {\r\n\tcenter := ScreenSize / 2\r\n\tamount := normalize(center-Cursor).x / 100\r\n\tvar clr vec3\r\n\tclr.r = texture2At(vec2(texCoord.x+amount, texCoord.y)).r\r\n\tclr.g = texture2At(texCoord).g\r\n\tclr.b = texture2At(vec2(texCoord.x-amount, texCoord.y)).b\r\n\treturn vec4(clr, 1.0)\r\n}\r\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 := normalize(center-Cursor).x / 100\n\tvar clr vec3\n\tclr.r = texture2At(vec2(texCoord.x+amount, texCoord.y)).r\n\tclr.g = texture2At(texCoord).g\n\tclr.b = texture2At(vec2(texCoord.x-amount, texCoord.y)).b\n\treturn vec4(clr, 1.0)\n}\n") diff --git a/examples/shader/default_go.go b/examples/shader/default_go.go index b53cec238..6cff3b593 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\r\n//\r\n// Licensed under the Apache License, Version 2.0 (the \"License\");\r\n// you may not use this file except in compliance with the License.\r\n// You may obtain a copy of the License at\r\n//\r\n// http://www.apache.org/licenses/LICENSE-2.0\r\n//\r\n// Unless required by applicable law or agreed to in writing, software\r\n// distributed under the License is distributed on an \"AS IS\" BASIS,\r\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n// See the License for the specific language governing permissions and\r\n// limitations under the License.\r\n\r\n// +build ignore\r\n\r\npackage main\r\n\r\nvar Time float\r\nvar Cursor vec2\r\nvar ScreenSize vec2\r\n\r\nfunc Fragment(position vec4, texCoord vec2, color vec4) vec4 {\r\n\tpos := position.xy/textureDstSize() + Cursor/textureDstSize()/4\r\n\tclr := 0.0\r\n\tclr += sin(pos.x*cos(Time/15)*80) + cos(pos.y*cos(Time/15)*10)\r\n\tclr += sin(pos.y*sin(Time/10)*40) + cos(pos.x*sin(Time/25)*40)\r\n\tclr += sin(pos.x*sin(Time/5)*10) + sin(pos.y*sin(Time/35)*80)\r\n\tclr *= sin(Time/10) * 0.5\r\n\treturn vec4(clr, clr*0.5, sin(clr+Time/3)*0.75, 1)\r\n}\r\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/textureDstSize() + Cursor/textureDstSize()/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/generate.go b/examples/shader/generate.go deleted file mode 100644 index 51f02f360..000000000 --- a/examples/shader/generate.go +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright 2020 The Ebiten Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package main - -//go:generate file2byteslice -package=main -input=default.go -output=default_go.go -var=default_go -//go:generate file2byteslice -package=main -input=lighting.go -output=lighting_go.go -var=lighting_go -//go:generate file2byteslice -package=main -input=radialblur.go -output=radialblur_go.go -var=radialblur_go -//go:generate file2byteslice -package=main -input=chromaticaberration.go -output=chromaticaberration_go.go -var=chromaticaberration_go diff --git a/examples/shader/lighting_go.go b/examples/shader/lighting_go.go index b7b4c051f..894489a3c 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\r\n//\r\n// Licensed under the Apache License, Version 2.0 (the \"License\");\r\n// you may not use this file except in compliance with the License.\r\n// You may obtain a copy of the License at\r\n//\r\n// http://www.apache.org/licenses/LICENSE-2.0\r\n//\r\n// Unless required by applicable law or agreed to in writing, software\r\n// distributed under the License is distributed on an \"AS IS\" BASIS,\r\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n// See the License for the specific language governing permissions and\r\n// limitations under the License.\r\n\r\n// +build ignore\r\n\r\npackage main\r\n\r\nvar Time float\r\nvar Cursor vec2\r\nvar ScreenSize vec2\r\n\r\nfunc Fragment(position vec4, texCoord vec2, color vec4) vec4 {\r\n\tlightpos := vec3(Cursor, 50)\r\n\tlightdir := normalize(lightpos - position.xyz)\r\n\tnormal := normalize(texture1At(texCoord) - 0.5)\r\n\tambient := 0.25\r\n\tdiffuse := 0.75 * max(0.0, dot(normal.xyz, lightdir))\r\n\treturn texture0At(texCoord) * (ambient + diffuse)\r\n}\r\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(texture1At(texCoord) - 0.5)\n\tambient := 0.25\n\tdiffuse := 0.75 * max(0.0, dot(normal.xyz, lightdir))\n\treturn texture0At(texCoord) * (ambient + diffuse)\n}\n") diff --git a/examples/shader/main.go b/examples/shader/main.go index 0cdd58ad7..b18f2beed 100644 --- a/examples/shader/main.go +++ b/examples/shader/main.go @@ -14,6 +14,11 @@ // +build example jsgo +//go:generate file2byteslice -package=main -input=default.go -output=default_go.go -var=default_go +//go:generate file2byteslice -package=main -input=lighting.go -output=lighting_go.go -var=lighting_go +//go:generate file2byteslice -package=main -input=radialblur.go -output=radialblur_go.go -var=radialblur_go +//go:generate file2byteslice -package=main -input=chromaticaberration.go -output=chromaticaberration_go.go -var=chromaticaberration_go + package main import ( diff --git a/examples/shader/radialblur_go.go b/examples/shader/radialblur_go.go index c4c3c21c4..414a1ec9d 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\r\n//\r\n// Licensed under the Apache License, Version 2.0 (the \"License\");\r\n// you may not use this file except in compliance with the License.\r\n// You may obtain a copy of the License at\r\n//\r\n// http://www.apache.org/licenses/LICENSE-2.0\r\n//\r\n// Unless required by applicable law or agreed to in writing, software\r\n// distributed under the License is distributed on an \"AS IS\" BASIS,\r\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n// See the License for the specific language governing permissions and\r\n// limitations under the License.\r\n\r\n// +build ignore\r\n\r\npackage main\r\n\r\nvar Time float\r\nvar Cursor vec2\r\nvar ScreenSize vec2\r\n\r\nfunc Fragment(position vec4, texCoord vec2, color vec4) vec4 {\r\n\tdir := normalize(position.xy - Cursor)\r\n\tclr := texture2At(texCoord)\r\n\r\n\tsamples := [10]float{\r\n\t\t-22, -14, -8, -4, -2, 2, 4, 8, 14, 22,\r\n\t}\r\n\t// TODO: Add len(samples)\r\n\tsum := clr\r\n\tfor i := 0; i < 10; i++ {\r\n\t\t// TODO: Consider the source region not to violate the region.\r\n\t\tsum += texture2At(texCoord + dir*samples[i]/texture2Size())\r\n\t}\r\n\tsum /= 10 + 1\r\n\r\n\tdist := distance(position.xy, Cursor)\r\n\tt := clamp(dist/256, 0, 1)\r\n\treturn mix(clr, sum, t)\r\n}\r\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 := texture2At(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 += texture2At(texCoord + dir*samples[i]/texture2Size())\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")