mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-26 03:38:55 +01:00
parent
d7a8f73a37
commit
20ef839e03
@ -31,11 +31,11 @@ func Warp(pos vec2) vec2 {
|
|||||||
return pos/2 + 0.5
|
return pos/2 + 0.5
|
||||||
}
|
}
|
||||||
|
|
||||||
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
func Fragment(dstPos vec4, srcPos vec2, color vec4) vec4 {
|
||||||
// Adjust the texture position to [0, 1].
|
// Adjust the texture position to [0, 1].
|
||||||
origin := imageSrc0Origin()
|
origin := imageSrc0Origin()
|
||||||
size := imageSrc0Size()
|
size := imageSrc0Size()
|
||||||
pos := texCoord
|
pos := srcPos
|
||||||
pos -= origin
|
pos -= origin
|
||||||
pos /= size
|
pos /= size
|
||||||
|
|
||||||
|
@ -21,12 +21,12 @@ package main
|
|||||||
var Time float
|
var Time float
|
||||||
var Cursor vec2
|
var Cursor vec2
|
||||||
|
|
||||||
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
func Fragment(dstPos vec4, srcPos vec2, color vec4) vec4 {
|
||||||
center := imageDstSize() / 2
|
center := imageDstSize() / 2
|
||||||
amount := (center - Cursor) / 10
|
amount := (center - Cursor) / 10
|
||||||
var clr vec3
|
var clr vec3
|
||||||
clr.r = imageSrc2At(texCoord + amount).r
|
clr.r = imageSrc2At(srcPos + amount).r
|
||||||
clr.g = imageSrc2UnsafeAt(texCoord).g
|
clr.g = imageSrc2UnsafeAt(srcPos).g
|
||||||
clr.b = imageSrc2At(texCoord - amount).b
|
clr.b = imageSrc2At(srcPos - amount).b
|
||||||
return vec4(clr, 1)
|
return vec4(clr, 1)
|
||||||
}
|
}
|
||||||
|
@ -21,8 +21,8 @@ package main
|
|||||||
var Time float
|
var Time float
|
||||||
var Cursor vec2
|
var Cursor vec2
|
||||||
|
|
||||||
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
func Fragment(dstPos vec4, srcPos vec2, color vec4) vec4 {
|
||||||
pos := (position.xy - imageDstOrigin()) / imageDstSize()
|
pos := (dstPos.xy - imageDstOrigin()) / imageDstSize()
|
||||||
pos += Cursor / imageDstSize() / 4
|
pos += Cursor / imageDstSize() / 4
|
||||||
clr := 0.0
|
clr := 0.0
|
||||||
clr += sin(pos.x*cos(Time/15)*80) + cos(pos.y*cos(Time/15)*10)
|
clr += sin(pos.x*cos(Time/15)*80) + cos(pos.y*cos(Time/15)*10)
|
||||||
|
@ -21,16 +21,16 @@ package main
|
|||||||
var Time float
|
var Time float
|
||||||
var Cursor vec2
|
var Cursor vec2
|
||||||
|
|
||||||
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
func Fragment(dstPos vec4, srcPos 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 := imageSrc3UnsafeAt(texCoord).x
|
level := imageSrc3UnsafeAt(srcPos).x
|
||||||
|
|
||||||
// Add a white border
|
// Add a white border
|
||||||
if limit-0.1 < level && level < limit {
|
if limit-0.1 < level && level < limit {
|
||||||
alpha := imageSrc0UnsafeAt(texCoord).w
|
alpha := imageSrc0UnsafeAt(srcPos).w
|
||||||
return vec4(alpha)
|
return vec4(alpha)
|
||||||
}
|
}
|
||||||
|
|
||||||
return step(limit, level) * imageSrc0UnsafeAt(texCoord)
|
return step(limit, level) * imageSrc0UnsafeAt(srcPos)
|
||||||
}
|
}
|
||||||
|
@ -21,13 +21,13 @@ package main
|
|||||||
var Time float
|
var Time float
|
||||||
var Cursor vec2
|
var Cursor vec2
|
||||||
|
|
||||||
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
func Fragment(dstPos vec4, srcPos vec2, color vec4) vec4 {
|
||||||
pos := position.xy - imageDstOrigin()
|
pos := dstPos.xy - imageDstOrigin()
|
||||||
|
|
||||||
lightpos := vec3(Cursor, 50)
|
lightpos := vec3(Cursor, 50)
|
||||||
lightdir := normalize(lightpos - vec3(pos, 0))
|
lightdir := normalize(lightpos - vec3(pos, 0))
|
||||||
normal := normalize(imageSrc1UnsafeAt(texCoord) - 0.5)
|
normal := normalize(imageSrc1UnsafeAt(srcPos) - 0.5)
|
||||||
const ambient = 0.25
|
const ambient = 0.25
|
||||||
diffuse := 0.75 * max(0.0, dot(normal.xyz, lightdir))
|
diffuse := 0.75 * max(0.0, dot(normal.xyz, lightdir))
|
||||||
return imageSrc0UnsafeAt(texCoord) * (ambient + diffuse)
|
return imageSrc0UnsafeAt(srcPos) * (ambient + diffuse)
|
||||||
}
|
}
|
||||||
|
@ -21,18 +21,18 @@ package main
|
|||||||
var Time float
|
var Time float
|
||||||
var Cursor vec2
|
var Cursor vec2
|
||||||
|
|
||||||
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
func Fragment(dstPos vec4, srcPos vec2, color vec4) vec4 {
|
||||||
pos := position.xy - imageDstOrigin()
|
pos := dstPos.xy - imageDstOrigin()
|
||||||
|
|
||||||
dir := normalize(pos - Cursor)
|
dir := normalize(pos - Cursor)
|
||||||
clr := imageSrc2UnsafeAt(texCoord)
|
clr := imageSrc2UnsafeAt(srcPos)
|
||||||
|
|
||||||
samples := [...]float{
|
samples := [...]float{
|
||||||
-22, -14, -8, -4, -2, 2, 4, 8, 14, 22,
|
-22, -14, -8, -4, -2, 2, 4, 8, 14, 22,
|
||||||
}
|
}
|
||||||
sum := clr
|
sum := clr
|
||||||
for i := 0; i < len(samples); i++ {
|
for i := 0; i < len(samples); i++ {
|
||||||
sum += imageSrc2At(texCoord + dir*samples[i])
|
sum += imageSrc2At(srcPos + dir*samples[i])
|
||||||
}
|
}
|
||||||
sum /= 10 + 1
|
sum /= 10 + 1
|
||||||
|
|
||||||
|
@ -18,8 +18,8 @@
|
|||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
func Fragment(dstPos vec4, srcPos vec2, color vec4) vec4 {
|
||||||
pos := position.xy
|
pos := dstPos.xy
|
||||||
pos -= imageDstOrigin()
|
pos -= imageDstOrigin()
|
||||||
pos /= imageDstSize()
|
pos /= imageDstSize()
|
||||||
return vec4(pos.x, pos.y, 0, 1)
|
return vec4(pos.x, pos.y, 0, 1)
|
||||||
|
@ -21,20 +21,20 @@ package main
|
|||||||
var Time float
|
var Time float
|
||||||
var Cursor vec2
|
var Cursor vec2
|
||||||
|
|
||||||
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
func Fragment(dstPos vec4, srcPos vec2, color vec4) vec4 {
|
||||||
pos := position.xy - imageDstOrigin()
|
pos := dstPos.xy - imageDstOrigin()
|
||||||
|
|
||||||
border := imageDstSize().y*0.6 + 4*cos(Time*3+pos.y/10)
|
border := imageDstSize().y*0.6 + 4*cos(Time*3+pos.y/10)
|
||||||
if pos.y < border {
|
if pos.y < border {
|
||||||
return imageSrc2UnsafeAt(texCoord)
|
return imageSrc2UnsafeAt(srcPos)
|
||||||
}
|
}
|
||||||
|
|
||||||
xoffset := 4 * cos(Time*3+pos.y/10)
|
xoffset := 4 * cos(Time*3+pos.y/10)
|
||||||
yoffset := 20 * (1 + cos(Time*3+pos.y/40))
|
yoffset := 20 * (1 + cos(Time*3+pos.y/40))
|
||||||
srcOrigin := imageSrc0Origin()
|
srcOrigin := imageSrc0Origin()
|
||||||
clr := imageSrc2At(vec2(
|
clr := imageSrc2At(vec2(
|
||||||
texCoord.x+xoffset,
|
srcPos.x+xoffset,
|
||||||
-(texCoord.y+yoffset-srcOrigin.y)+border*2+srcOrigin.y,
|
-(srcPos.y+yoffset-srcOrigin.y)+border*2+srcOrigin.y,
|
||||||
)).rgb
|
)).rgb
|
||||||
|
|
||||||
overlay := vec3(0.5, 1, 1)
|
overlay := vec3(0.5, 1, 1)
|
||||||
|
@ -28,10 +28,10 @@ const screenShaderSrc = `//kage:unit pixels
|
|||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
func Fragment(dstPos vec4, srcPos vec2, color vec4) vec4 {
|
||||||
// Blend source colors in a square region, which size is 1/scale.
|
// Blend source colors in a square region, which size is 1/scale.
|
||||||
scale := imageDstSize()/imageSrc0Size()
|
scale := imageDstSize()/imageSrc0Size()
|
||||||
pos := texCoord
|
pos := srcPos
|
||||||
p0 := pos - 1/2.0/scale
|
p0 := pos - 1/2.0/scale
|
||||||
p1 := pos + 1/2.0/scale
|
p1 := pos + 1/2.0/scale
|
||||||
|
|
||||||
|
@ -67,18 +67,18 @@ func adjustTexelForAddressRepeat(p vec2) vec2 {
|
|||||||
}
|
}
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
func Fragment(dstPos vec4, srcPos vec2, color vec4) vec4 {
|
||||||
{{if eq .Filter .FilterNearest}}
|
{{if eq .Filter .FilterNearest}}
|
||||||
{{if eq .Address .AddressUnsafe}}
|
{{if eq .Address .AddressUnsafe}}
|
||||||
clr := imageSrc0UnsafeAt(texCoord)
|
clr := imageSrc0UnsafeAt(srcPos)
|
||||||
{{else if eq .Address .AddressClampToZero}}
|
{{else if eq .Address .AddressClampToZero}}
|
||||||
clr := imageSrc0At(texCoord)
|
clr := imageSrc0At(srcPos)
|
||||||
{{else if eq .Address .AddressRepeat}}
|
{{else if eq .Address .AddressRepeat}}
|
||||||
clr := imageSrc0At(adjustTexelForAddressRepeat(texCoord))
|
clr := imageSrc0At(adjustTexelForAddressRepeat(srcPos))
|
||||||
{{end}}
|
{{end}}
|
||||||
{{else if eq .Filter .FilterLinear}}
|
{{else if eq .Filter .FilterLinear}}
|
||||||
p0 := texCoord - 1/2.0
|
p0 := srcPos - 1/2.0
|
||||||
p1 := texCoord + 1/2.0
|
p1 := srcPos + 1/2.0
|
||||||
|
|
||||||
{{if eq .Address .AddressRepeat}}
|
{{if eq .Address .AddressRepeat}}
|
||||||
p0 = adjustTexelForAddressRepeat(p0)
|
p0 = adjustTexelForAddressRepeat(p0)
|
||||||
|
@ -154,8 +154,8 @@ func imageSrc%[1]dAt(pos vec2) vec4 {
|
|||||||
shaderSuffix += `
|
shaderSuffix += `
|
||||||
var __projectionMatrix mat4
|
var __projectionMatrix mat4
|
||||||
|
|
||||||
func __vertex(position vec2, texCoord vec2, color vec4) (vec4, vec2, vec4) {
|
func __vertex(dstPos vec2, srcPos vec2, color vec4) (vec4, vec2, vec4) {
|
||||||
return __projectionMatrix * vec4(position, 0, 1), texCoord, color
|
return __projectionMatrix * vec4(dstPos, 0, 1), srcPos, color
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
return shaderSuffix, nil
|
return shaderSuffix, nil
|
||||||
|
@ -84,7 +84,7 @@ func init() {
|
|||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
func Fragment(dstPos vec4, srcPos vec2, color vec4) vec4 {
|
||||||
return vec4(0)
|
return vec4(0)
|
||||||
}`))
|
}`))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user