mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-12 12:08:58 +01:00
parent
ee049a19ac
commit
8dec91db43
@ -34,6 +34,7 @@
|
||||
//go:generate file2byteslice -package=mascot -input=./images/mascot/out02.png -output=./images/mascot/out02.go -var=Out02_png
|
||||
//go:generate file2byteslice -package=mascot -input=./images/mascot/out03.png -output=./images/mascot/out03.go -var=Out03_png
|
||||
//go:generate file2byteslice -package=shader -input=./images/shader/gopher.png -output=./images/shader/gopher.go -var=Gopher_png
|
||||
//go:generate file2byteslice -package=shader -input=./images/shader/gopherbg.png -output=./images/shader/gopherbg.go -var=GopherBg_png
|
||||
//go:generate file2byteslice -package=shader -input=./images/shader/normal.png -output=./images/shader/normal.go -var=Normal_png
|
||||
//go:generate file2byteslice -package=platformer -input=./images/platformer/background.png -output=./images/platformer/background.go -var=Background_png
|
||||
//go:generate file2byteslice -package=platformer -input=./images/platformer/left.png -output=./images/platformer/left.go -var=Left_png
|
||||
|
@ -99,6 +99,24 @@ Read this article for more details: https://blog.golang.org/gopher
|
||||
https://corvussg.itch.io/2d-game-backgrounds
|
||||
```
|
||||
|
||||
## shader/gopher.png
|
||||
|
||||
```
|
||||
The Go gopher was designed by Renee French. (http://reneefrench.blogspot.com/)
|
||||
The design is licensed under the Creative Commons 3.0 Attributions license.
|
||||
Read this article for more details: https://blog.golang.org/gopher
|
||||
```
|
||||
|
||||
## shader/gopherbg.png
|
||||
|
||||
```
|
||||
https://commons.wikimedia.org/wiki/File:Solna_Brick_wall_vilt_forband.jpg
|
||||
|
||||
By Håkan Svensson Xauxa
|
||||
|
||||
The Creative Commons Attribution-Share Alike 3.0 Unported license
|
||||
```
|
||||
|
||||
## Other image files
|
||||
|
||||
```
|
||||
|
6
examples/resources/images/shader/gopherbg.go
Normal file
6
examples/resources/images/shader/gopherbg.go
Normal file
File diff suppressed because one or more lines are too long
BIN
examples/resources/images/shader/gopherbg.png
Normal file
BIN
examples/resources/images/shader/gopherbg.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 540 KiB |
@ -16,3 +16,4 @@ 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
|
||||
|
@ -34,8 +34,9 @@ const (
|
||||
)
|
||||
|
||||
var (
|
||||
gopherImage *ebiten.Image
|
||||
normalImage *ebiten.Image
|
||||
gopherImage *ebiten.Image
|
||||
gopherBgImage *ebiten.Image
|
||||
normalImage *ebiten.Image
|
||||
)
|
||||
|
||||
func init() {
|
||||
@ -55,6 +56,14 @@ func init() {
|
||||
gopherImage, _ = ebiten.NewImageFromImage(img, ebiten.FilterDefault)
|
||||
}
|
||||
|
||||
func init() {
|
||||
img, _, err := image.Decode(bytes.NewReader(resources.GopherBg_png))
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
gopherBgImage, _ = ebiten.NewImageFromImage(img, ebiten.FilterDefault)
|
||||
}
|
||||
|
||||
func init() {
|
||||
img, _, err := image.Decode(bytes.NewReader(resources.Normal_png))
|
||||
if err != nil {
|
||||
@ -66,6 +75,7 @@ func init() {
|
||||
var shaderSrcs = [][]byte{
|
||||
default_go,
|
||||
lighting_go,
|
||||
radialblur_go,
|
||||
}
|
||||
|
||||
type Game struct {
|
||||
@ -114,6 +124,7 @@ func (g *Game) Draw(screen *ebiten.Image) {
|
||||
}
|
||||
op.Images[0] = gopherImage
|
||||
op.Images[1] = normalImage
|
||||
op.Images[2] = gopherBgImage
|
||||
screen.DrawRectShader(w, h, s, op)
|
||||
|
||||
msg := "Press Up/Down to switch the shader."
|
||||
|
40
examples/shader/radialblur.go
Normal file
40
examples/shader/radialblur.go
Normal file
@ -0,0 +1,40 @@
|
||||
// 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
|
||||
|
||||
var Time float
|
||||
var Cursor vec2
|
||||
|
||||
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||
dir := normalize(position.xy - Cursor)
|
||||
clr := texture2At(texCoord)
|
||||
|
||||
samples := [10]float{
|
||||
-22, -14, -8, -4, -2, 2, 4, 8, 14, 22,
|
||||
}
|
||||
// TODO: Add len(samples)
|
||||
sum := clr
|
||||
for i := 0; i < 10; i++ {
|
||||
// TODO: Consider the source region not to violate the region.
|
||||
sum += texture2At(texCoord + dir*samples[i]/texture2Size())
|
||||
}
|
||||
sum /= 10 + 1
|
||||
|
||||
dist := distance(position.xy, Cursor)
|
||||
t := clamp(dist/256, 0, 1)
|
||||
return mix(clr, sum, t)
|
||||
}
|
6
examples/shader/radialblur_go.go
Normal file
6
examples/shader/radialblur_go.go
Normal file
@ -0,0 +1,6 @@
|
||||
// Code generated by file2byteslice. DO NOT EDIT.
|
||||
// (gofmt is fine after generating)
|
||||
|
||||
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\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")
|
Loading…
Reference in New Issue
Block a user