bgfx: crt-geom and crt-geom-deluxe enhancements (#7766)

Added a "brightness boost" feature for the shadow mask that works by making the brightness ratio between bright and dark mask pixels closer to 1 for the brighter parts of the image.

Added clamping to zero so that underscanning produces a black border.

Added a "raster bloom" effect to crt-geom-deluxe that makes the image grow slightly when the average brightness of the screen is high, mimicking a common defect in CRTs.
This commit is contained in:
cgwg 2021-02-21 04:47:28 +01:00 committed by GitHub
parent 0c20cabef6
commit 92b2921754
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
31 changed files with 663 additions and 331 deletions

View File

@ -0,0 +1,33 @@
"""
Assumes the input RGB image subpixels are all either 0 or 255.
Counts the bright subpixels in the whole image. This should be divisible by 3.
Creates a uniform alpha channel containing 255 minus 1/3 of
the number of bright subpixels.
Writes the RGBA image to the output file.
"""
import sys
import numpy
import PIL
import PIL.Image
if len(sys.argv) != 3:
print("usage: add_alpha.py in.png out.png")
sys.exit(1)
img = PIL.Image.open(sys.argv[1])
arr = numpy.asarray(img)
count = (arr==255).sum()
assert count%3 == 0
count //= 3
alpha = arr[:,:,0,None]*0 + (255-count)
arr = numpy.concatenate((arr,alpha),axis=2)
# DEBUG
#print(arr)
out = PIL.Image.fromarray(arr)
out.save(sys.argv[2])

Binary file not shown.

Before

Width:  |  Height:  |  Size: 153 B

After

Width:  |  Height:  |  Size: 74 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 152 B

After

Width:  |  Height:  |  Size: 78 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 159 B

After

Width:  |  Height:  |  Size: 78 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 156 B

After

Width:  |  Height:  |  Size: 82 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 159 B

After

Width:  |  Height:  |  Size: 82 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 159 B

After

Width:  |  Height:  |  Size: 83 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 156 B

After

Width:  |  Height:  |  Size: 87 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 164 B

After

Width:  |  Height:  |  Size: 86 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 168 B

After

Width:  |  Height:  |  Size: 91 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 150 B

After

Width:  |  Height:  |  Size: 70 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 171 B

After

Width:  |  Height:  |  Size: 99 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 176 B

After

Width:  |  Height:  |  Size: 107 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 180 B

After

Width:  |  Height:  |  Size: 109 B

View File

@ -11,6 +11,15 @@
"step" : 0.05,
"format": "%1.2f",
"screen": "raster" },
{ "type": "float",
"name": "aperture_brightboost",
"text": "Shadow mask brightness boost",
"default": 0.4,
"max" : 1.0,
"min" : 0.0,
"step" : 0.05,
"format": "%1.2f",
"screen": "raster" },
{ "type": "float",
"name": "phosphor_power",
"text": "Phosphor decay power",
@ -29,6 +38,24 @@
"step" : 0.01,
"format": "%1.2f",
"screen": "raster" },
{ "type": "float",
"name": "rasterbloom_smooth",
"text": "Raster bloom temporal smoothing",
"default": 0.5,
"max" : 0.99,
"min" : 0.0,
"step" : 0.01,
"format": "%1.2f",
"screen": "raster" },
{ "type": "float",
"name": "rasterbloom",
"text": "Raster bloom amplitude",
"default": 0.01,
"max" : 0.1,
"min" : 0.0,
"step" : 0.001,
"format": "%1.3f",
"screen": "raster" },
{ "type": "float",
"name": "halation",
"text": "Halation amplitude",
@ -74,15 +101,15 @@
"step" : 0.1,
"format": "%1.1f",
"screen": "raster" },
{ "type": "vec2",
"name": "angle",
"text": "Tilt ",
"default": [ 0.0, 0.0 ],
"max" : [ 1.0, 1.0 ],
"min" : [-1.0,-1.0 ],
"step" : 0.01,
"format": "%1.2f",
"screen": "raster" },
{ "type": "vec2",
"name": "angle",
"text": "Tilt ",
"default": [ 0.0, 0.0 ],
"max" : [ 1.0, 1.0 ],
"min" : [-1.0,-1.0 ],
"step" : 0.01,
"format": "%1.2f",
"screen": "raster" },
{ "type": "float",
"name": "cornersize",
"text": "Rounded corner size",
@ -101,15 +128,15 @@
"step" : 100,
"format": "%1.0f",
"screen": "raster" },
{ "type": "vec2",
"name": "overscan",
"text": "Overscan ",
"default": [ 1.0, 1.0 ],
"max" : [ 1.2, 1.2 ],
"min" : [ 0.8, 0.8 ],
"step" : 0.02,
"format": "%1.2f",
"screen": "raster" },
{ "type": "vec2",
"name": "overscan",
"text": "Overscan ",
"default": [ 1.0, 1.0 ],
"max" : [ 1.2, 1.2 ],
"min" : [ 0.8, 0.8 ],
"step" : 0.02,
"format": "%1.2f",
"screen": "raster" },
{ "type": "float",
"name": "CRTgamma",
"text": "Gamma of simulated CRT",
@ -128,112 +155,128 @@
"step" : 0.05,
"format": "%1.2f",
"screen": "raster" },
{ "type": "vec2",
"name": "aspect",
"text": "Aspect ratio ",
"default": [ 1.0, 0.75 ],
"max" : [ 1.0, 1.0 ],
"min" : [ 0.3, 0.3 ],
"step" : 0.01,
"format": "%1.2f",
"screen": "raster" }
{ "type": "vec2",
"name": "aspect",
"text": "Aspect ratio ",
"default": [ 1.0, 0.75 ],
"max" : [ 1.0, 1.0 ],
"min" : [ 0.3, 0.3 ],
"step" : 0.01,
"format": "%1.2f",
"screen": "raster" }
],
"targets": [
{ "name": "internal1",
"mode": "guest"
},
{ "name": "internal2",
"mode": "guest"
},
{ "name": "blur",
"mode": "guest"
},
{ "name": "phosphor",
"mode": "guest"
}
],
"passes": [
{
"effect": "crt-geom/phosphor_apply",
"applytint": true,
"name": "phosphor apply",
"uniforms": [
{ "uniform": "u_phosphor_power", "slider": "phosphor_power" },
{ "uniform": "u_phosphor_amplitude","slider": "phosphor_amplitude" },
{ "uniform": "u_gamma", "slider": "CRTgamma" }
],
"input": [
{ "sampler": "s_screen", "target": "screen" },
{ "sampler": "s_phosphor", "target": "phosphor" }
],
"output": "internal1"
},
{
"effect": "crt-geom/phosphor_update",
"name": "phosphor update",
"uniforms": [
{ "uniform": "u_phosphor_power", "slider": "phosphor_power" },
{ "uniform": "u_phosphor_amplitude","slider": "phosphor_amplitude" },
{ "uniform": "u_gamma", "slider": "CRTgamma" }
],
"input": [
{ "sampler": "s_screen", "target": "screen" },
{ "sampler": "s_phosphor", "target": "phosphor" }
],
"output": "phosphor"
},
{
"effect": "crt-geom/gaussx",
"name": "Gaussian blur x",
"uniforms": [
{ "uniform": "u_width", "slider": "blurwidth" },
{ "uniform": "u_aspect","slider": "aspect" },
{ "uniform": "u_gamma", "slider": "CRTgamma" }
],
"input": [
{ "sampler": "s_tex", "target": "internal1" }
],
"output": "internal2"
},
{
"effect": "crt-geom/gaussy",
"name": "Gaussian blur y",
"uniforms": [
{ "uniform": "u_width", "slider": "blurwidth" },
{ "uniform": "u_aspect","slider": "aspect" },
{ "uniform": "u_gamma", "slider": "CRTgamma" }
],
"input": [
{ "sampler": "s_tex", "target": "internal2" }
],
"output": "blur"
},
{
"effect": "crt-geom/crt-geom-deluxe",
"name": "CRT",
"uniforms": [
{ "uniform": "curvature", "slider": "curvature" },
{ "uniform": "R", "slider": "R" },
{ "uniform": "d", "slider": "d" },
{ "uniform": "angle", "slider": "angle" },
{ "uniform": "cornersize", "slider": "cornersize" },
{ "uniform": "cornersmooth","slider": "cornersmooth" },
{ "uniform": "overscan", "slider": "overscan" },
{ "uniform": "aspect", "slider": "aspect" },
{ "uniform": "CRTgamma", "slider": "CRTgamma" },
{ "uniform": "monitorgamma","slider": "monitorgamma" },
{ "uniform": "aperture_strength","slider": "aperture_strength" },
{ "uniform": "halation", "slider": "halation" }
],
"input": [
{ "sampler": "mpass_texture", "target": "internal1" },
{ "sampler": "mask_texture", "texture": "bgfx/chains/crt-geom/aperture_1_2_bgr.png", "selection": "Shadow mask" },
{ "sampler": "blur_texture", "target": "blur" }
],
"output": "output"
}
]
"targets": [
{ "name": "internal1",
"mode": "guest"
},
{ "name": "internal2",
"mode": "guest"
},
{ "name": "mipmap",
"mode": "guest"
},
{ "name": "blur",
"mode": "guest"
},
{ "name": "phosphor",
"mode": "guest"
}
],
"passes": [
{
"effect": "crt-geom/phosphor_apply",
"applytint": true,
"name": "phosphor apply",
"uniforms": [
{ "uniform": "u_phosphor_power", "slider": "phosphor_power" },
{ "uniform": "u_phosphor_amplitude","slider": "phosphor_amplitude" },
{ "uniform": "u_gamma", "slider": "CRTgamma" }
],
"input": [
{ "sampler": "s_screen", "target": "screen" },
{ "sampler": "s_phosphor", "target": "phosphor" }
],
"output": "internal1"
},
{
"effect": "crt-geom/mipmap8",
"name": "mipmap",
"uniforms": [
{ "uniform": "u_smooth", "slider": "rasterbloom_smooth" }
],
"input": [
{ "sampler": "s_screen", "target": "internal1" },
{ "sampler": "s_mipmap", "target": "mipmap" }
],
"output": "mipmap"
},
{
"effect": "crt-geom/phosphor_update",
"name": "phosphor update",
"uniforms": [
{ "uniform": "u_phosphor_power", "slider": "phosphor_power" },
{ "uniform": "u_phosphor_amplitude","slider": "phosphor_amplitude" },
{ "uniform": "u_gamma", "slider": "CRTgamma" }
],
"input": [
{ "sampler": "s_screen", "target": "screen" },
{ "sampler": "s_phosphor", "target": "phosphor" }
],
"output": "phosphor"
},
{
"effect": "crt-geom/gaussx",
"name": "Gaussian blur x",
"uniforms": [
{ "uniform": "u_width", "slider": "blurwidth" },
{ "uniform": "u_aspect","slider": "aspect" },
{ "uniform": "u_gamma", "slider": "CRTgamma" }
],
"input": [
{ "sampler": "s_tex", "target": "internal1" }
],
"output": "internal2"
},
{
"effect": "crt-geom/gaussy",
"name": "Gaussian blur y",
"uniforms": [
{ "uniform": "u_width", "slider": "blurwidth" },
{ "uniform": "u_aspect","slider": "aspect" },
{ "uniform": "u_gamma", "slider": "CRTgamma" }
],
"input": [
{ "sampler": "s_tex", "target": "internal2" }
],
"output": "blur"
},
{
"effect": "crt-geom/crt-geom-deluxe",
"name": "CRT",
"uniforms": [
{ "uniform": "curvature", "slider": "curvature" },
{ "uniform": "R", "slider": "R" },
{ "uniform": "d", "slider": "d" },
{ "uniform": "angle", "slider": "angle" },
{ "uniform": "cornersize", "slider": "cornersize" },
{ "uniform": "cornersmooth","slider": "cornersmooth" },
{ "uniform": "overscan", "slider": "overscan" },
{ "uniform": "aspect", "slider": "aspect" },
{ "uniform": "CRTgamma", "slider": "CRTgamma" },
{ "uniform": "monitorgamma","slider": "monitorgamma" },
{ "uniform": "aperture_strength","slider": "aperture_strength" },
{ "uniform": "aperture_brightboost","slider": "aperture_brightboost" },
{ "uniform": "halation", "slider": "halation" },
{ "uniform": "blurwidth", "slider": "blurwidth" },
{ "uniform": "rasterbloom", "slider": "rasterbloom" }
],
"input": [
{ "sampler": "mpass_texture", "target": "internal1" },
{ "sampler": "mask_texture", "texture": "bgfx/chains/crt-geom/aperture_1_2_bgr.png", "selection": "Shadow mask" },
{ "sampler": "blur_texture", "target": "blur" },
{ "sampler": "mipmap_texture", "target": "mipmap" }
],
"output": "output"
}
]
}

View File

@ -11,6 +11,15 @@
"step" : 0.05,
"format": "%1.2f",
"screen": "raster" },
{ "type": "float",
"name": "aperture_brightboost",
"text": "Shadow mask brightness boost",
"default": 0.4,
"max" : 1.0,
"min" : 0.0,
"step" : 0.05,
"format": "%1.2f",
"screen": "raster" },
{ "type": "float",
"name": "curvature",
"text": "Enable curvature",
@ -38,15 +47,15 @@
"step" : 0.1,
"format": "%1.1f",
"screen": "raster" },
{ "type": "vec2",
"name": "angle",
"text": "Tilt ",
"default": [ 0.0, 0.0 ],
"max" : [ 1.0, 1.0 ],
"min" : [-1.0,-1.0 ],
"step" : 0.01,
"format": "%1.2f",
"screen": "raster" },
{ "type": "vec2",
"name": "angle",
"text": "Tilt ",
"default": [ 0.0, 0.0 ],
"max" : [ 1.0, 1.0 ],
"min" : [-1.0,-1.0 ],
"step" : 0.01,
"format": "%1.2f",
"screen": "raster" },
{ "type": "float",
"name": "cornersize",
"text": "Rounded corner size",
@ -65,15 +74,15 @@
"step" : 100,
"format": "%1.0f",
"screen": "raster" },
{ "type": "vec2",
"name": "overscan",
"text": "Overscan ",
"default": [ 1.0, 1.0 ],
"max" : [ 1.2, 1.2 ],
"min" : [ 0.8, 0.8 ],
"step" : 0.02,
"format": "%1.2f",
"screen": "raster" },
{ "type": "vec2",
"name": "overscan",
"text": "Overscan ",
"default": [ 1.0, 1.0 ],
"max" : [ 1.2, 1.2 ],
"min" : [ 0.8, 0.8 ],
"step" : 0.02,
"format": "%1.2f",
"screen": "raster" },
{ "type": "float",
"name": "CRTgamma",
"text": "Gamma of simulated CRT",
@ -92,44 +101,42 @@
"step" : 0.05,
"format": "%1.2f",
"screen": "raster" },
{ "type": "vec2",
"name": "aspect",
"text": "Aspect ratio ",
"default": [ 1.0, 0.75 ],
"max" : [ 1.0, 1.0 ],
"min" : [ 0.3, 0.3 ],
"step" : 0.01,
"format": "%1.2f",
"screen": "raster" }
{ "type": "vec2",
"name": "aspect",
"text": "Aspect ratio ",
"default": [ 1.0, 0.75 ],
"max" : [ 1.0, 1.0 ],
"min" : [ 0.3, 0.3 ],
"step" : 0.01,
"format": "%1.2f",
"screen": "raster" }
],
"targets": [
],
"passes": [
{
"effect": "crt-geom/crt-geom",
"applytint": true,
"name": "CRT",
"uniforms": [
{ "uniform": "curvature", "slider": "curvature" },
{ "uniform": "R", "slider": "R" },
{ "uniform": "d", "slider": "d" },
{ "uniform": "angle", "slider": "angle" },
{ "uniform": "cornersize", "slider": "cornersize" },
{ "uniform": "cornersmooth","slider": "cornersmooth" },
{ "uniform": "overscan", "slider": "overscan" },
{ "uniform": "aspect", "slider": "aspect" },
{ "uniform": "CRTgamma", "slider": "CRTgamma" },
{ "uniform": "monitorgamma","slider": "monitorgamma" },
{ "uniform": "aperture_strength", "slider": "aperture_strength" }
],
"input": [
{ "sampler": "mpass_texture", "target": "screen" },
{ "sampler": "mask_texture", "texture": "bgfx/chains/crt-geom/aperture_1_2_bgr.png", "selection": "Shadow mask" }
],
"output": "output"
}
]
"targets": [
],
"passes": [
{
"effect": "crt-geom/crt-geom",
"applytint": true,
"name": "CRT",
"uniforms": [
{ "uniform": "curvature", "slider": "curvature" },
{ "uniform": "R", "slider": "R" },
{ "uniform": "d", "slider": "d" },
{ "uniform": "angle", "slider": "angle" },
{ "uniform": "cornersize", "slider": "cornersize" },
{ "uniform": "cornersmooth","slider": "cornersmooth" },
{ "uniform": "overscan", "slider": "overscan" },
{ "uniform": "aspect", "slider": "aspect" },
{ "uniform": "CRTgamma", "slider": "CRTgamma" },
{ "uniform": "monitorgamma","slider": "monitorgamma" },
{ "uniform": "aperture_strength", "slider": "aperture_strength" },
{ "uniform": "aperture_brightboost","slider": "aperture_brightboost" }
],
"input": [
{ "sampler": "mpass_texture", "target": "screen" },
{ "sampler": "mask_texture", "texture": "bgfx/chains/crt-geom/aperture_1_2_bgr.png", "selection": "Shadow mask" }
],
"output": "output"
}
]
}

View File

@ -1,43 +1,47 @@
{
"blend": {
"equation": "add",
"srcColor": "1",
"dstColor": "0",
"srcAlpha": "1",
"dstAlpha": "0"
"equation": "add",
"srcColor": "1",
"dstColor": "0",
"srcAlpha": "1",
"dstAlpha": "0"
},
"depth": {
"function": "always",
"writeenable": false
"function": "always",
"writeenable": false
},
"cull": {
"mode": "none"
"mode": "none"
},
"write": {
"rgb": true,
"alpha": true
"rgb": true,
"alpha": true
},
"vertex": "chains/crt-geom/vs_crt-geom",
"fragment": "chains/crt-geom/fs_crt-geom-deluxe",
"uniforms": [
{ "name": "u_tex_size0", "type": "vec4", "values": [ 1.0, 1.0, 0.0, 0.0 ] },
{ "name": "u_tex_size1", "type": "vec4", "values": [ 1.0, 1.0, 0.0, 0.0 ] },
{ "name": "u_quad_dims", "type": "vec4", "values": [ 1.0, 1.0, 0.0, 0.0 ] },
{ "name": "u_rotation_type", "type": "vec4", "values": [ 1.0, 0.0, 0.0, 0.0 ] },
{ "name": "mpass_texture", "type": "int", "values": [ 0 ] },
{ "name": "mask_texture", "type": "int", "values": [ 1 ] },
{ "name": "blur_texture", "type": "int", "values": [ 1 ] },
{ "name": "curvature", "type": "vec4", "values": [ 1.0, 0.0, 0.0, 0.0 ] },
{ "name": "CRTgamma", "type": "vec4", "values": [ 2.4, 0.0, 0.0, 0.0 ] },
{ "name": "monitorgamma", "type": "vec4", "values": [ 2.2, 0.0, 0.0, 0.0 ] },
{ "name": "overscan", "type": "vec4", "values": [ 1.0, 1.0, 0.0, 0.0 ] },
{ "name": "aspect", "type": "vec4", "values": [ 1.0, 0.75,0.0, 0.0 ] },
{ "name": "d", "type": "vec4", "values": [ 2.0, 0.0, 0.0, 0.0 ] },
{ "name": "R", "type": "vec4", "values": [ 3.5, 0.0, 0.0, 0.0 ] },
{ "name": "angle", "type": "vec4", "values": [ 0.0,-0.05,0.0, 0.0 ] },
{ "name": "cornersize", "type": "vec4", "values": [ 0.01,0.0, 0.0, 0.0 ] },
{ "name": "cornersmooth", "type": "vec4", "values": [ 1000.0,0.0,0.0,0.0 ] },
{ "name": "aperture_strength", "type": "vec4", "values": [ 0.25,0.0,0.0,0.0 ] },
{ "name": "halation", "type": "vec4", "values": [ 0.1,0.0,0.0,0.0 ] }
{ "name": "u_tex_size0", "type": "vec4", "values": [ 1.0, 1.0, 0.0, 0.0 ] },
{ "name": "u_tex_size1", "type": "vec4", "values": [ 1.0, 1.0, 0.0, 0.0 ] },
{ "name": "u_quad_dims", "type": "vec4", "values": [ 1.0, 1.0, 0.0, 0.0 ] },
{ "name": "u_rotation_type", "type": "vec4", "values": [ 1.0, 0.0, 0.0, 0.0 ] },
{ "name": "mpass_texture", "type": "int", "values": [ 0 ] },
{ "name": "mask_texture", "type": "int", "values": [ 1 ] },
{ "name": "blur_texture", "type": "int", "values": [ 2 ] },
{ "name": "mipmap_texture", "type": "int", "values": [ 3 ] },
{ "name": "curvature", "type": "vec4", "values": [ 1.0, 0.0, 0.0, 0.0 ] },
{ "name": "CRTgamma", "type": "vec4", "values": [ 2.4, 0.0, 0.0, 0.0 ] },
{ "name": "monitorgamma", "type": "vec4", "values": [ 2.2, 0.0, 0.0, 0.0 ] },
{ "name": "overscan", "type": "vec4", "values": [ 1.0, 1.0, 0.0, 0.0 ] },
{ "name": "aspect", "type": "vec4", "values": [ 1.0, 0.75,0.0, 0.0 ] },
{ "name": "d", "type": "vec4", "values": [ 2.0, 0.0, 0.0, 0.0 ] },
{ "name": "R", "type": "vec4", "values": [ 3.5, 0.0, 0.0, 0.0 ] },
{ "name": "angle", "type": "vec4", "values": [ 0.0,-0.05,0.0, 0.0 ] },
{ "name": "cornersize", "type": "vec4", "values": [ 0.01,0.0, 0.0, 0.0 ] },
{ "name": "cornersmooth", "type": "vec4", "values": [ 1000.0,0.0,0.0,0.0 ] },
{ "name": "aperture_strength", "type": "vec4", "values": [ 0.25,0.0,0.0,0.0 ] },
{ "name": "aperture_brightboost","type": "vec4", "values": [ 0.25,0.0,0.0,0.0 ] },
{ "name": "halation", "type": "vec4", "values": [ 0.1,0.0,0.0,0.0 ] },
{ "name": "blurwidth", "type": "vec4", "values": [ 2.0,0.0,0.0,0.0 ] },
{ "name": "rasterbloom","type": "vec4", "values": [ 0.01,0.0,0.0,0.0 ] }
]
}

View File

@ -1,41 +1,42 @@
{
"blend": {
"equation": "add",
"srcColor": "1",
"dstColor": "0",
"srcAlpha": "1",
"dstAlpha": "0"
"equation": "add",
"srcColor": "1",
"dstColor": "0",
"srcAlpha": "1",
"dstAlpha": "0"
},
"depth": {
"function": "always",
"writeenable": false
"function": "always",
"writeenable": false
},
"cull": {
"mode": "none"
"mode": "none"
},
"write": {
"rgb": true,
"alpha": true
"rgb": true,
"alpha": true
},
"vertex": "chains/crt-geom/vs_crt-geom",
"fragment": "chains/crt-geom/fs_crt-geom",
"uniforms": [
{ "name": "u_tex_size0", "type": "vec4", "values": [ 1.0, 1.0, 0.0, 0.0 ] },
{ "name": "u_tex_size1", "type": "vec4", "values": [ 1.0, 1.0, 0.0, 0.0 ] },
{ "name": "u_quad_dims", "type": "vec4", "values": [ 1.0, 1.0, 0.0, 0.0 ] },
{ "name": "u_rotation_type", "type": "vec4", "values": [ 1.0, 0.0, 0.0, 0.0 ] },
{ "name": "mpass_texture", "type": "int", "values": [ 0 ] },
{ "name": "mask_texture", "type": "int", "values": [ 1 ] },
{ "name": "curvature", "type": "vec4", "values": [ 1.0, 0.0, 0.0, 0.0 ] },
{ "name": "CRTgamma", "type": "vec4", "values": [ 2.4, 0.0, 0.0, 0.0 ] },
{ "name": "monitorgamma", "type": "vec4", "values": [ 2.2, 0.0, 0.0, 0.0 ] },
{ "name": "overscan", "type": "vec4", "values": [ 1.0, 1.0, 0.0, 0.0 ] },
{ "name": "aspect", "type": "vec4", "values": [ 1.0, 0.75,0.0, 0.0 ] },
{ "name": "d", "type": "vec4", "values": [ 2.0, 0.0, 0.0, 0.0 ] },
{ "name": "R", "type": "vec4", "values": [ 3.5, 0.0, 0.0, 0.0 ] },
{ "name": "angle", "type": "vec4", "values": [ 0.0,-0.05,0.0, 0.0 ] },
{ "name": "cornersize", "type": "vec4", "values": [ 0.01,0.0, 0.0, 0.0 ] },
{ "name": "cornersmooth", "type": "vec4", "values": [ 1000.0,0.0,0.0,0.0 ] },
{ "name": "aperture_strength", "type": "vec4", "values": [ 0.25,0.0,0.0,0.0 ] }
{ "name": "u_tex_size0", "type": "vec4", "values": [ 1.0, 1.0, 0.0, 0.0 ] },
{ "name": "u_tex_size1", "type": "vec4", "values": [ 1.0, 1.0, 0.0, 0.0 ] },
{ "name": "u_quad_dims", "type": "vec4", "values": [ 1.0, 1.0, 0.0, 0.0 ] },
{ "name": "u_rotation_type", "type": "vec4", "values": [ 1.0, 0.0, 0.0, 0.0 ] },
{ "name": "mpass_texture", "type": "int", "values": [ 0 ] },
{ "name": "mask_texture", "type": "int", "values": [ 1 ] },
{ "name": "curvature", "type": "vec4", "values": [ 1.0, 0.0, 0.0, 0.0 ] },
{ "name": "CRTgamma", "type": "vec4", "values": [ 2.4, 0.0, 0.0, 0.0 ] },
{ "name": "monitorgamma", "type": "vec4", "values": [ 2.2, 0.0, 0.0, 0.0 ] },
{ "name": "overscan", "type": "vec4", "values": [ 1.0, 1.0, 0.0, 0.0 ] },
{ "name": "aspect", "type": "vec4", "values": [ 1.0, 0.75,0.0, 0.0 ] },
{ "name": "d", "type": "vec4", "values": [ 2.0, 0.0, 0.0, 0.0 ] },
{ "name": "R", "type": "vec4", "values": [ 3.5, 0.0, 0.0, 0.0 ] },
{ "name": "angle", "type": "vec4", "values": [ 0.0,-0.05,0.0, 0.0 ] },
{ "name": "cornersize", "type": "vec4", "values": [ 0.01,0.0, 0.0, 0.0 ] },
{ "name": "cornersmooth", "type": "vec4", "values": [ 1000.0,0.0,0.0,0.0 ] },
{ "name": "aperture_strength", "type": "vec4", "values": [ 0.25,0.0,0.0,0.0 ] },
{ "name": "aperture_brightboost","type": "vec4", "values": [ 0.25,0.0,0.0,0.0 ] }
]
}

View File

@ -1,29 +1,29 @@
{
"blend": {
"equation": "add",
"srcColor": "1",
"dstColor": "0",
"srcAlpha": "1",
"dstAlpha": "0"
"equation": "add",
"srcColor": "1",
"dstColor": "0",
"srcAlpha": "1",
"dstAlpha": "0"
},
"depth": {
"function": "always",
"writeenable": false
"function": "always",
"writeenable": false
},
"cull": {
"mode": "none"
"mode": "none"
},
"write": {
"rgb": true,
"alpha": true
"rgb": true,
"alpha": true
},
"vertex": "chains/crt-geom/vs_gaussx",
"fragment": "chains/crt-geom/fs_gaussx",
"uniforms": [
{ "name": "s_tex", "type": "int", "values": [ 0 ] },
{ "name": "u_tex_size0", "type": "vec4", "values": [ 1.0, 1.0, 0.0, 0.0 ] },
{ "name": "u_width", "type": "vec4", "values": [ 2.0, 0.0, 0.0, 0.0 ] },
{ "name": "u_aspect", "type": "vec4", "values": [ 1.0,0.75, 0.0, 0.0 ] },
{ "name": "u_gamma", "type": "vec4", "values": [ 2.2, 0.0, 0.0, 0.0 ] }
{ "name": "s_tex", "type": "int", "values": [ 0 ] },
{ "name": "u_tex_size0", "type": "vec4", "values": [ 1.0, 1.0, 0.0, 0.0 ] },
{ "name": "u_width", "type": "vec4", "values": [ 2.0, 0.0, 0.0, 0.0 ] },
{ "name": "u_aspect", "type": "vec4", "values": [ 1.0,0.75, 0.0, 0.0 ] },
{ "name": "u_gamma", "type": "vec4", "values": [ 2.2, 0.0, 0.0, 0.0 ] }
]
}

View File

@ -1,29 +1,29 @@
{
"blend": {
"equation": "add",
"srcColor": "1",
"dstColor": "0",
"srcAlpha": "1",
"dstAlpha": "0"
"equation": "add",
"srcColor": "1",
"dstColor": "0",
"srcAlpha": "1",
"dstAlpha": "0"
},
"depth": {
"function": "always",
"writeenable": false
"function": "always",
"writeenable": false
},
"cull": {
"mode": "none"
"mode": "none"
},
"write": {
"rgb": true,
"alpha": true
"rgb": true,
"alpha": true
},
"vertex": "chains/crt-geom/vs_gaussy",
"fragment": "chains/crt-geom/fs_gaussy",
"uniforms": [
{ "name": "s_tex", "type": "int", "values": [ 0 ] },
{ "name": "u_tex_size0", "type": "vec4", "values": [ 1.0, 1.0, 0.0, 0.0 ] },
{ "name": "u_width", "type": "vec4", "values": [ 2.0, 0.0, 0.0, 0.0 ] },
{ "name": "u_aspect", "type": "vec4", "values": [ 1.0,0.75, 0.0, 0.0 ] },
{ "name": "u_gamma", "type": "vec4", "values": [ 2.2, 0.0, 0.0, 0.0 ] }
{ "name": "s_tex", "type": "int", "values": [ 0 ] },
{ "name": "u_tex_size0", "type": "vec4", "values": [ 1.0, 1.0, 0.0, 0.0 ] },
{ "name": "u_width", "type": "vec4", "values": [ 2.0, 0.0, 0.0, 0.0 ] },
{ "name": "u_aspect", "type": "vec4", "values": [ 1.0,0.75, 0.0, 0.0 ] },
{ "name": "u_gamma", "type": "vec4", "values": [ 2.2, 0.0, 0.0, 0.0 ] }
]
}

View File

@ -0,0 +1,29 @@
{
"blend": {
"equation": "add",
"srcColor": "1",
"dstColor": "0",
"srcAlpha": "1",
"dstAlpha": "0"
},
"depth": {
"function": "always",
"writeenable": false
},
"cull": {
"mode": "none"
},
"write": {
"rgb": true,
"alpha": true
},
"vertex": "chains/crt-geom/vs_mipmap8",
"fragment": "chains/crt-geom/fs_mipmap8",
"uniforms": [
{ "name": "u_tex_size0", "type": "vec4", "values": [ 1.0, 1.0, 0.0, 0.0 ] },
{ "name": "u_tex_size1", "type": "vec4", "values": [ 1.0, 1.0, 0.0, 0.0 ] },
{ "name": "u_smooth", "type": "vec4", "values": [ 0.5, 0.0, 0.0, 0.0 ] },
{ "name": "s_screen", "type": "int", "values": [ 0 ] },
{ "name": "s_mipmap", "type": "int", "values": [ 1 ] }
]
}

View File

@ -1,29 +1,29 @@
{
"blend": {
"equation": "add",
"srcColor": "1",
"dstColor": "0",
"srcAlpha": "1",
"dstAlpha": "0"
"equation": "add",
"srcColor": "1",
"dstColor": "0",
"srcAlpha": "1",
"dstAlpha": "0"
},
"depth": {
"function": "always",
"writeenable": false
"function": "always",
"writeenable": false
},
"cull": {
"mode": "none"
"mode": "none"
},
"write": {
"rgb": true,
"alpha": true
"rgb": true,
"alpha": true
},
"vertex": "chains/crt-geom/vs_phosphor_apply",
"fragment": "chains/crt-geom/fs_phosphor_apply",
"uniforms": [
{ "name": "s_screen", "type": "int", "values": [ 0 ] },
{ "name": "s_phosphor", "type": "int", "values": [ 1 ] },
{ "name": "u_phosphor_power", "type": "vec4", "values": [ 1.3, 0.0, 0.0, 0.0 ] },
{ "name": "u_phosphor_amplitude","type": "vec4", "values": [ 0.2, 0.0, 0.0, 0.0 ] },
{ "name": "u_gamma", "type": "vec4", "values": [ 2.2, 0.0, 0.0, 0.0 ] }
{ "name": "s_screen", "type": "int", "values": [ 0 ] },
{ "name": "s_phosphor", "type": "int", "values": [ 1 ] },
{ "name": "u_phosphor_power", "type": "vec4", "values": [ 1.3, 0.0, 0.0, 0.0 ] },
{ "name": "u_phosphor_amplitude","type": "vec4", "values": [ 0.2, 0.0, 0.0, 0.0 ] },
{ "name": "u_gamma", "type": "vec4", "values": [ 2.2, 0.0, 0.0, 0.0 ] }
]
}

View File

@ -1,29 +1,29 @@
{
"blend": {
"equation": "add",
"srcColor": "1",
"dstColor": "0",
"srcAlpha": "1",
"dstAlpha": "0"
"equation": "add",
"srcColor": "1",
"dstColor": "0",
"srcAlpha": "1",
"dstAlpha": "0"
},
"depth": {
"function": "always",
"writeenable": false
"function": "always",
"writeenable": false
},
"cull": {
"mode": "none"
"mode": "none"
},
"write": {
"rgb": true,
"alpha": true
"rgb": true,
"alpha": true
},
"vertex": "chains/crt-geom/vs_phosphor_update",
"fragment": "chains/crt-geom/fs_phosphor_update",
"uniforms": [
{ "name": "s_screen", "type": "int", "values": [ 0 ] },
{ "name": "s_phosphor", "type": "int", "values": [ 1 ] },
{ "name": "u_phosphor_power", "type": "vec4", "values": [ 1.3, 0.0, 0.0, 0.0 ] },
{ "name": "u_phosphor_amplitude","type": "vec4", "values": [ 0.2, 0.0, 0.0, 0.0 ] },
{ "name": "u_gamma", "type": "vec4", "values": [ 2.2, 0.0, 0.0, 0.0 ] }
{ "name": "s_screen", "type": "int", "values": [ 0 ] },
{ "name": "s_phosphor", "type": "int", "values": [ 1 ] },
{ "name": "u_phosphor_power", "type": "vec4", "values": [ 1.3, 0.0, 0.0, 0.0 ] },
{ "name": "u_phosphor_amplitude","type": "vec4", "values": [ 0.2, 0.0, 0.0, 0.0 ] },
{ "name": "u_gamma", "type": "vec4", "values": [ 2.2, 0.0, 0.0, 0.0 ] }
]
}

Binary file not shown.

Binary file not shown.

View File

@ -28,12 +28,17 @@ $input v_sinangle, v_cosangle, v_stretch, v_one, v_texCoord
SAMPLER2D(mpass_texture, 0);
SAMPLER2D(mask_texture, 1);
SAMPLER2D(blur_texture, 2);
SAMPLER2D(mipmap_texture, 3);
vec4 TEX2D(vec2 c)
{
vec2 underscan = step(0.0,c) * step(0.0,vec2_splat(1.0)-c);
vec4 col = texture2D(mpass_texture, c) * vec4_splat(underscan.x*underscan.y);
#ifdef LINEAR_PROCESSING
# define TEX2D(c) pow(texture2D(mpass_texture, (c)), vec4(CRTgamma))
#else
# define TEX2D(c) texture2D(mpass_texture, (c))
col = pow(col, vec4_splat(CRTgamma.x));
#endif
return col;
}
// Enable screen curvature.
uniform vec4 curvature;
@ -43,6 +48,7 @@ uniform vec4 u_tex_size1;
uniform vec4 u_quad_dims;
uniform vec4 aperture_strength;
uniform vec4 aperture_brightboost;
uniform vec4 CRTgamma;
uniform vec4 monitorgamma;
@ -57,6 +63,22 @@ uniform vec4 cornersize;
uniform vec4 cornersmooth;
uniform vec4 halation;
uniform vec4 rasterbloom;
uniform vec4 blurwidth;
vec3 texblur(vec2 c)
{
vec3 col = pow(texture2D(blur_texture,c).rgb, vec3_splat(CRTgamma.x));
// taper the blur texture outside its border with a gaussian
float w = blurwidth.x / 320.0;
c = min(c, vec2_splat(1.0)-c) * aspect.xy * vec2_splat(1.0/w);
vec2 e2c = exp(-c*c);
// approximation of erf gives smooth step
// (convolution of gaussian with step)
c = (step(0.0,c)-vec2_splat(0.5)) * sqrt(vec2_splat(1.0)-e2c) * (vec2_splat(1.0) + vec2_splat(0.1749)*e2c) + vec2_splat(0.5);
return col * vec3_splat( c.x * c.y );
}
float intersect(vec2 xy , vec2 sinangle, vec2 cosangle)
{
@ -157,8 +179,13 @@ void main()
xy = transform(v_texCoord, v_stretch, v_sinangle, v_cosangle);
else
xy = (v_texCoord-vec2_splat(0.5))/overscan.xy+vec2_splat(0.5);
vec2 xy0 = xy;
float cval = corner(xy);
// extract average brightness from the mipmap texture
float avgbright = dot(texture2D(mipmap_texture,vec2(1.0,1.0)).rgb,vec3_splat(1.0))/3.0;
float rbloom = 1.0 - rasterbloom.x * ( avgbright - 0.5 );
// expand the screen when average brightness is higher
xy = (xy - vec2_splat(0.5)) * rbloom + vec2_splat(0.5);
vec2 xy0 = xy;
// Of all the pixels that are mapped onto the texel we are
// currently rendering, which pixel are we currently rendering?
@ -191,13 +218,13 @@ void main()
// using the Lanczos coefficients above.
vec4 col = clamp(TEX2D(xy + vec2(-v_one.x, 0.0))*coeffs.x +
TEX2D(xy)*coeffs.y +
TEX2D(xy +vec2(v_one.x, 0.0))*coeffs.z +
TEX2D(xy + vec2(2.0 * v_one.x, 0.0))*coeffs.w , 0.0, 1.0);
TEX2D(xy +vec2(v_one.x, 0.0))*coeffs.z +
TEX2D(xy + vec2(2.0 * v_one.x, 0.0))*coeffs.w , 0.0, 1.0);
vec4 col2 = clamp(TEX2D(xy + vec2(-v_one.x, v_one.y))*coeffs.x +
TEX2D(xy + vec2(0.0, v_one.y))*coeffs.y +
TEX2D(xy + v_one)*coeffs.z +
TEX2D(xy + vec2(2.0 * v_one.x, v_one.y))*coeffs.w , 0.0, 1.0);
TEX2D(xy + vec2(0.0, v_one.y))*coeffs.y +
TEX2D(xy + v_one)*coeffs.z +
TEX2D(xy + vec2(2.0 * v_one.x, v_one.y))*coeffs.w , 0.0, 1.0);
#ifndef LINEAR_PROCESSING
@ -220,16 +247,29 @@ void main()
vec3 mul_res = (col * weights + col2 * weights2).rgb;
// halation and corners
vec3 blur = pow(texture2D(blur_texture,xy0).rgb, vec3_splat(CRTgamma.x));
mul_res = mix(mul_res, blur, halation.x) * vec3_splat(cval);
// Convert the image gamma for display on our output device.
mul_res = pow(mul_res, vec3_splat(1.0 / monitorgamma.x));
vec3 blur = texblur(xy0);
// include factor of rbloom:
// (probably imperceptible) brightness reduction when raster grows
mul_res = mix(mul_res, blur, halation.x) * vec3_splat(cval*rbloom);
// Shadow mask
xy = v_texCoord.xy * u_quad_dims.xy / u_tex_size1.xy;
vec3 mask = texture2D(mask_texture, xy).rgb;
mask = mix(vec3_splat(1.0), mask, aperture_strength.x);
vec4 mask = texture2D(mask_texture, xy);
// count of total bright pixels is encoded in the mask's alpha channel
float nbright = 255.0 - 255.0*mask.a;
// fraction of bright pixels in the mask
float fbright = nbright / ( u_tex_size1.x * u_tex_size1.y );
// average darkening factor of the mask
float aperture_average = mix(1.0-aperture_strength.x*(1.0-aperture_brightboost.x), 1.0, fbright);
// colour of dark mask pixels
vec3 clow = vec3_splat(1.0-aperture_strength.x) * mul_res + vec3_splat(aperture_strength.x*(aperture_brightboost.x)) * mul_res * mul_res;
float ifbright = 1.0 / fbright;
// colour of bright mask pixels
vec3 chi = vec3_splat(ifbright*aperture_average) * mul_res - vec3_splat(ifbright - 1.0) * clow;
vec3 cout = mix(clow,chi,mask.rgb); // mask texture selects dark vs bright
gl_FragColor = vec4(mul_res*mask, col.a);
// Convert the image gamma for display on our output device.
cout = pow(cout, vec3_splat(1.0 / monitorgamma.x));
gl_FragColor = vec4(cout,1.0);
}

View File

@ -27,11 +27,16 @@ $input v_sinangle, v_cosangle, v_stretch, v_one, v_texCoord
SAMPLER2D(mpass_texture, 0);
SAMPLER2D(mask_texture, 1);
vec4 TEX2D(vec2 c)
{
vec2 underscan = step(0.0,c) * step(0.0,vec2_splat(1.0)-c);
vec4 col = texture2D(mpass_texture, c) * vec4_splat(underscan.x*underscan.y);
#ifdef LINEAR_PROCESSING
# define TEX2D(c) pow(texture2D(mpass_texture, (c)), vec4(CRTgamma))
#else
# define TEX2D(c) texture2D(mpass_texture, (c))
col = pow(col, vec4_splat(CRTgamma.x));
#endif
return col;
}
// Enable screen curvature.
uniform vec4 curvature;
@ -41,6 +46,7 @@ uniform vec4 u_tex_size1;
uniform vec4 u_quad_dims;
uniform vec4 aperture_strength;
uniform vec4 aperture_brightboost;
uniform vec4 CRTgamma;
uniform vec4 monitorgamma;
@ -186,13 +192,13 @@ void main()
// using the Lanczos coefficients above.
vec4 col = clamp(TEX2D(xy + vec2(-v_one.x, 0.0))*coeffs.x +
TEX2D(xy)*coeffs.y +
TEX2D(xy +vec2(v_one.x, 0.0))*coeffs.z +
TEX2D(xy + vec2(2.0 * v_one.x, 0.0))*coeffs.w , 0.0, 1.0);
TEX2D(xy +vec2(v_one.x, 0.0))*coeffs.z +
TEX2D(xy + vec2(2.0 * v_one.x, 0.0))*coeffs.w , 0.0, 1.0);
vec4 col2 = clamp(TEX2D(xy + vec2(-v_one.x, v_one.y))*coeffs.x +
TEX2D(xy + vec2(0.0, v_one.y))*coeffs.y +
TEX2D(xy + v_one)*coeffs.z +
TEX2D(xy + vec2(2.0 * v_one.x, v_one.y))*coeffs.w , 0.0, 1.0);
TEX2D(xy + vec2(0.0, v_one.y))*coeffs.y +
TEX2D(xy + v_one)*coeffs.z +
TEX2D(xy + vec2(2.0 * v_one.x, v_one.y))*coeffs.w , 0.0, 1.0);
#ifndef LINEAR_PROCESSING
@ -214,14 +220,24 @@ void main()
#endif
vec3 mul_res = (col * weights + col2 * weights2).rgb * vec3_splat(cval);
// Convert the image gamma for display on our output device.
mul_res = pow(mul_res, vec3_splat(1.0 / monitorgamma.x));
// Color the texel.
// Shadow mask
xy = v_texCoord.xy * u_quad_dims.xy / u_tex_size1.xy;
vec3 mask = texture2D(mask_texture, xy).rgb;
mask = mix(vec3_splat(1.0), mask, aperture_strength.x);
vec4 mask = texture2D(mask_texture, xy);
// count of total bright pixels is encoded in the mask's alpha channel
float nbright = 255.0 - 255.0*mask.a;
// fraction of bright pixels in the mask
float fbright = nbright / ( u_tex_size1.x * u_tex_size1.y );
// average darkening factor of the mask
float aperture_average = mix(1.0-aperture_strength.x*(1.0-aperture_brightboost.x), 1.0, fbright);
// colour of dark mask pixels
vec3 clow = vec3_splat(1.0-aperture_strength.x) * mul_res + vec3_splat(aperture_strength.x*(aperture_brightboost.x)) * mul_res * mul_res;
float ifbright = 1.0 / fbright;
// colour of bright mask pixels
vec3 chi = vec3_splat(ifbright*aperture_average) * mul_res - vec3_splat(ifbright - 1.0) * clow;
vec3 cout = mix(clow,chi,mask.rgb); // mask texture selects dark vs bright
gl_FragColor = vec4(mul_res*mask, col.a);
// Convert the image gamma for display on our output device.
cout = pow(cout, vec3_splat(1.0 / monitorgamma.x));
gl_FragColor = vec4(cout,1.0);
}

View File

@ -0,0 +1,148 @@
$input v_texCoord
#include "common.sh"
SAMPLER2D(s_screen, 0);
SAMPLER2D(s_mipmap, 1);
uniform vec4 u_tex_size0;
uniform vec4 u_tex_size1;
uniform vec4 u_smooth;
/*
* Based loosely on the idea outlined at
* https://nyorain.github.io/mipmap-compute-shader.html
* Each higher mipmap level is delayed by one frame.
*
* A rectangle containing (1,1) has the last mipmap level
* (normally a single pixel containing the average of the frame),
* passed through a two-tap IIR temporal filter.
*/
const vec2 v05 = vec2(0.5,0.5);
// pix has integer coordinates -> average four pixels using bilinear filtering
vec3 sample_screen(vec2 pix)
{
vec2 border = step(-0.5, u_tex_size0.xy - pix);
float weight = border.x * border.y;
// avoid boundary! if dimensions are odd, average 1 or 2 pixels
vec2 x = clamp(pix, vec2_splat(0.0), u_tex_size0.xy - v05);
// if we're at the boundary, include weight factor
// -> effectively always average 4 pixels, with some of them possibly zero
border = clamp(u_tex_size0.xy-x,0.0,1.0);
weight *= border.x * border.y;
vec3 tex = texture2D(s_screen, x / u_tex_size0.xy).rgb;
return tex * vec3_splat(weight);
}
vec3 sample_mipmap(vec2 pix, vec2 offset, vec2 size)
{
vec2 border = step(-0.5, size - pix) * step(-0.5, pix);
float weight = border.x * border.y;
// avoid boundary! if dimensions are odd, average 1 or 2 pixels
vec2 x = clamp(pix, vec2_splat(0.0), size - v05);
// if we're at the boundary, include weight factor
// -> effectively always average 4 pixels, with some of them possibly zero
border = clamp(size-x,0.0,1.0);
weight *= border.x * border.y;
vec3 tex = texture2D(s_mipmap, (x + offset) / u_tex_size0.xy).rgb;
return tex * vec3_splat(weight);
}
void main()
{
vec2 pix = v_texCoord.xy * u_tex_size0.xy;
vec2 x = pix*vec2_splat(8.0);
if (pix.x < u_tex_size0.x * 0.5) {
// first level: sample from screen texture
// sample 4x4 grid
// each sample uses bilinear filtering to average a 2x2 region
// overall reduction by 8x8
vec3 tex = ( sample_screen(x + vec2(-3.0,-3.0))
+ sample_screen(x + vec2(-3.0,-1.0))
+ sample_screen(x + vec2(-3.0, 1.0))
+ sample_screen(x + vec2(-3.0, 3.0))
+ sample_screen(x + vec2(-1.0,-3.0))
+ sample_screen(x + vec2(-1.0,-1.0))
+ sample_screen(x + vec2(-1.0, 1.0))
+ sample_screen(x + vec2(-1.0, 3.0))
+ sample_screen(x + vec2( 1.0,-3.0))
+ sample_screen(x + vec2( 1.0,-1.0))
+ sample_screen(x + vec2( 1.0, 1.0))
+ sample_screen(x + vec2( 1.0, 3.0))
+ sample_screen(x + vec2( 3.0,-3.0))
+ sample_screen(x + vec2( 3.0,-1.0))
+ sample_screen(x + vec2( 3.0, 1.0))
+ sample_screen(x + vec2( 3.0, 3.0)) ) * 0.0625;
gl_FragColor = vec4(tex.rgb,1.0);
} else {
// higher levels: sample from mipmap texture
vec2 newsize = u_tex_size0.xy; // size of texture being sampled
float fac = 8.0; // keep track of the linear reduction factor
float dx = u_tex_size0.x;
vec2 offset = vec2_splat(0.0);
vec2 offset0 = offset;
bool fc = false;
for (int i = 0; i < 3; i++) { // 3 is sufficient for dimensions up to 4k
// place subsequent levels to the right
if (pix.x > dx * 0.5) {
dx = dx * 0.5;
newsize = ceil(newsize*v05*v05*v05); // size of sampled texture is eighthed
fac *= 8.0;
offset0 = offset;
offset.x = offset.x + dx;
pix.x -= dx;
x = pix * vec2_splat(8.0);
if (newsize.x < 8.5 && newsize.y < 8.5) { // reducing to a single pixel
fc = true;
break;
}
} else break;
}
if (fc)
x = vec2(4.0,4.0);
vec3 tex = ( sample_mipmap(x + vec2(-3.0,-3.0),offset0,newsize)
+ sample_mipmap(x + vec2(-3.0,-1.0),offset0,newsize)
+ sample_mipmap(x + vec2(-3.0, 1.0),offset0,newsize)
+ sample_mipmap(x + vec2(-3.0, 3.0),offset0,newsize)
+ sample_mipmap(x + vec2(-1.0,-3.0),offset0,newsize)
+ sample_mipmap(x + vec2(-1.0,-1.0),offset0,newsize)
+ sample_mipmap(x + vec2(-1.0, 1.0),offset0,newsize)
+ sample_mipmap(x + vec2(-1.0, 3.0),offset0,newsize)
+ sample_mipmap(x + vec2( 1.0,-3.0),offset0,newsize)
+ sample_mipmap(x + vec2( 1.0,-1.0),offset0,newsize)
+ sample_mipmap(x + vec2( 1.0, 1.0),offset0,newsize)
+ sample_mipmap(x + vec2( 1.0, 3.0),offset0,newsize)
+ sample_mipmap(x + vec2( 3.0,-3.0),offset0,newsize)
+ sample_mipmap(x + vec2( 3.0,-1.0),offset0,newsize)
+ sample_mipmap(x + vec2( 3.0, 1.0),offset0,newsize)
+ sample_mipmap(x + vec2( 3.0, 3.0),offset0,newsize) ) * 0.0625;
if (fc) { // this sample yields average over the whole screen
// apply a compensation for the zeros included in the 8^n average
float f = fac*fac / (u_tex_size0.x * u_tex_size0.y);
vec3 col = tex * vec3_splat(f);
if (v_texCoord.y * u_tex_size1.y < ( offset0.y + u_tex_size1.y ) * 0.5) {
gl_FragColor = vec4(col,1.0);
} else {
// we are near (1,1): in this region include the temporal filter
vec4 old = texture2D(s_mipmap, v_texCoord.xy);
gl_FragColor = vec4(mix(col,old.rgb,u_smooth.x),1.0);
}
} else {
gl_FragColor = vec4(tex.rgb,1.0);
}
}
}

View File

@ -0,0 +1,11 @@
$input a_position, a_texcoord0, a_color0
$output v_texCoord
#include "common.sh"
void main()
{
// Do the standard vertex processing.
gl_Position = mul(u_viewProj, vec4(a_position.xy, 0.0, 1.0));
v_texCoord = a_texcoord0;
}