mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
parent
5e5e3c64ac
commit
2453f8f0df
56
examples/shader/crt.go
Normal file
56
examples/shader/crt.go
Normal file
@ -0,0 +1,56 @@
|
||||
// Copyright 2022 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.
|
||||
|
||||
//go:build ignore
|
||||
// +build ignore
|
||||
|
||||
package main
|
||||
|
||||
var Time float
|
||||
var Cursor vec2
|
||||
var ScreenSize vec2
|
||||
|
||||
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||
const (
|
||||
BLURSCALEX = 0.45
|
||||
LOWLUMSCAN = 5.0
|
||||
HILUMSCAN = 10.0
|
||||
BRIGHTBOOST = 1.25
|
||||
MASK_DARK = 0.25
|
||||
MASK_FADE = 0.8
|
||||
)
|
||||
|
||||
pos := texCoord
|
||||
origin, size := imageDstRegionOnTexture()
|
||||
pos -= origin
|
||||
pos /= size
|
||||
|
||||
maskFade := 0.3333 * MASK_FADE
|
||||
invDims := 1.0 / imageDstTextureSize().xy
|
||||
p := pos * imageDstTextureSize()
|
||||
i := floor(p) + 0.50
|
||||
f := p - i
|
||||
p = (i + 4.0*f*f*f) * invDims
|
||||
p.x = mix(p.x, pos.x, BLURSCALEX)
|
||||
Y := f.y * f.y
|
||||
YY := Y * Y
|
||||
whichmask := fract(pos.x * -0.4999)
|
||||
mask := 1.0 + float(whichmask < 0.5)*-MASK_DARK
|
||||
|
||||
clr := imageSrc2At(p*size + origin).rgb
|
||||
scanLineWeight := (BRIGHTBOOST - LOWLUMSCAN*(Y-2.05*YY))
|
||||
scanLineWeightB := 1.0 - HILUMSCAN*(YY-2.8*YY*Y)
|
||||
|
||||
return vec4(clr.rgb*mix(scanLineWeight*mask, scanLineWeightB, dot(clr.rgb, vec3(maskFade))), 1.0)
|
||||
}
|
5
examples/shader/crt_go.go
Normal file
5
examples/shader/crt_go.go
Normal file
@ -0,0 +1,5 @@
|
||||
// Code generated by file2byteslice. DO NOT EDIT.
|
||||
|
||||
package main
|
||||
|
||||
var crt_go = []byte("// Copyright 2022 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//go:build ignore\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\tconst (\r\n\t\tBLURSCALEX = 0.45\r\n\t\tLOWLUMSCAN = 5.0\r\n\t\tHILUMSCAN = 10.0\r\n\t\tBRIGHTBOOST = 1.25\r\n\t\tMASK_DARK = 0.25\r\n\t\tMASK_FADE = 0.8\r\n\t)\r\n\r\n\tpos := texCoord\r\n\torigin, size := imageDstRegionOnTexture()\r\n\tpos -= origin\r\n\tpos /= size\r\n\r\n\tmaskFade := 0.3333 * MASK_FADE\r\n\tinvDims := 1.0 / imageDstTextureSize().xy\r\n\tp := pos * imageDstTextureSize()\r\n\ti := floor(p) + 0.50\r\n\tf := p - i\r\n\tp = (i + 4.0*f*f*f) * invDims\r\n\tp.x = mix(p.x, pos.x, BLURSCALEX)\r\n\tY := f.y * f.y\r\n\tYY := Y * Y\r\n\twhichmask := fract(pos.x * -0.4999)\r\n\tmask := 1.0 + float(whichmask < 0.5)*-MASK_DARK\r\n\r\n\tclr := imageSrc2At(p*size + origin).rgb\r\n\tscanLineWeight := (BRIGHTBOOST - LOWLUMSCAN*(Y-2.05*YY))\r\n\tscanLineWeightB := 1.0 - HILUMSCAN*(YY-2.8*YY*Y)\r\n\r\n\treturn vec4(clr.rgb*mix(scanLineWeight*mask, scanLineWeightB, dot(clr.rgb, vec3(maskFade))), 1.0)\r\n}\r\n")
|
@ -85,6 +85,7 @@ var shaderSrcs = [][]byte{
|
||||
chromaticaberration_go,
|
||||
dissolve_go,
|
||||
water_go,
|
||||
crt_go,
|
||||
}
|
||||
|
||||
type Game struct {
|
||||
|
Loading…
Reference in New Issue
Block a user