From ede16afd30bf9364fc0084450d4c4361612b5f62 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Wed, 9 Dec 2020 23:33:59 +0900 Subject: [PATCH] examples/shader: Add a new example 'texel' --- examples/shader/generate.go | 1 + examples/shader/main.go | 1 + examples/shader/texel.go | 25 +++++++++++++++++++++++++ examples/shader/texel_go.go | 7 +++++++ 4 files changed, 34 insertions(+) create mode 100644 examples/shader/texel.go create mode 100644 examples/shader/texel_go.go diff --git a/examples/shader/generate.go b/examples/shader/generate.go index d1bfd74b2..e1fdbb21d 100644 --- a/examples/shader/generate.go +++ b/examples/shader/generate.go @@ -17,6 +17,7 @@ package main //go:generate file2byteslice -package=main -input=default.go -output=default_go.go -var=default_go -buildtags=example +//go:generate file2byteslice -package=main -input=texel.go -output=texel_go.go -var=texel_go -buildtags=example //go:generate file2byteslice -package=main -input=lighting.go -output=lighting_go.go -var=lighting_go -buildtags=example //go:generate file2byteslice -package=main -input=radialblur.go -output=radialblur_go.go -var=radialblur_go -buildtags=example //go:generate file2byteslice -package=main -input=chromaticaberration.go -output=chromaticaberration_go.go -var=chromaticaberration_go -buildtags=example diff --git a/examples/shader/main.go b/examples/shader/main.go index ffcc605d4..23ec41317 100644 --- a/examples/shader/main.go +++ b/examples/shader/main.go @@ -83,6 +83,7 @@ func init() { var shaderSrcs = [][]byte{ default_go, + texel_go, lighting_go, radialblur_go, chromaticaberration_go, diff --git a/examples/shader/texel.go b/examples/shader/texel.go new file mode 100644 index 000000000..af122e01a --- /dev/null +++ b/examples/shader/texel.go @@ -0,0 +1,25 @@ +// 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. + +// +build ignore + +package main + +func Fragment(position vec4, texCoord vec2, color vec4) vec4 { + pos := position.xy / imageDstTextureSize() + origin, size := imageDstRegionOnTexture() + pos -= origin + pos /= size + return vec4(pos.x, pos.y, 0, 1) +} diff --git a/examples/shader/texel_go.go b/examples/shader/texel_go.go new file mode 100644 index 000000000..814e4202d --- /dev/null +++ b/examples/shader/texel_go.go @@ -0,0 +1,7 @@ +// Code generated by file2byteslice. DO NOT EDIT. + +// +build example + +package main + +var texel_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\nfunc Fragment(position vec4, texCoord vec2, color vec4) vec4 {\n\tpos := position.xy / imageDstTextureSize()\n\torigin, size := imageDstRegionOnTexture()\n\tpos -= origin\n\tpos /= size\n\treturn vec4(pos.x, pos.y, 0, 1)\n}\n")