diff --git a/CHANGELOG.md b/CHANGELOG.md index ddfbd0c..2bb79d5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,17 @@ * Up to date. +## [1.1.0] - 2019-07-15 + +### Added + +* More parameters to adjust the shader: + * `vignette_opacity` + * `show_grille` + * `show_scanlines` + * `show_vignette` + * `show_curvature` + ## [1.0.0] - 2019-06-27 * Released stable version. \ No newline at end of file diff --git a/README.md b/README.md index a201b05..1229d1d 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,39 @@ If, for for reason, when loading the `crt_material.tres`, the `crt.shader` is em | Name | Type | Default | Description | | --- | --- | --- | --- | -| `boost` | `float` | `1.0` | Gives extra brightness to compensate for the scanlines. Range from `1.0` to `1.5` with `0.05` steps. | +| `boost` | `float` | `1.2` | Gives extra brightness to compensate for the scanlines and the vignette. Range from `1.0` to `1.5` with `0.05` steps. | + +### Vignette opacity + +| Name | Type | Default | Description | +| --- | --- | --- | --- | +| `vignette_opacity` | `float` | `0.3` | Control the opacity of the vignette. Range from `0.1` to `0.5` with `0.05` steps. | + +### Show grille + +| Name | Type | Default | Description | +| --- | --- | --- | --- | +| `show_grille` | `bool` | `true` | Enable/disable the grille. | + +Only works in `window/stretch/mode="2d"`. + +### Show scanlines + +| Name | Type | Default | Description | +| --- | --- | --- | --- | +| `show_scanlines` | `bool` | `true` | Enable/disable the scanlines. | + +### Show vignette + +| Name | Type | Default | Description | +| --- | --- | --- | --- | +| `show_vignette` | `bool` | `true` | Enable/disable the vignette. | + +### Show curvature + +| Name | Type | Default | Description | +| --- | --- | --- | --- | +| `show_curvature` | `bool` | `true` | Enable/disable the curvature. | ## Changelog diff --git a/crt_material.tres b/crt_material.tres index de872cc..7dca991 100644 --- a/crt_material.tres +++ b/crt_material.tres @@ -2,9 +2,13 @@ [ext_resource path="res://crt_shader.shader" type="Shader" id=1] - [resource] shader = ExtResource( 1 ) shader_param/blend_color = Color( 1, 1, 1, 1 ) -shader_param/boost = 1.0 +shader_param/boost = 1.2 +shader_param/vignette_opacity = 0.35 +shader_param/show_grille = true +shader_param/show_scanlines = true +shader_param/show_vignette = true +shader_param/show_curvature = true diff --git a/crt_shader.shader b/crt_shader.shader index 53b950a..2386e94 100644 --- a/crt_shader.shader +++ b/crt_shader.shader @@ -2,32 +2,52 @@ shader_type canvas_item; render_mode blend_mul; uniform vec4 blend_color : hint_color = vec4(1.0, 1.0, 1.0, 1.0); -uniform float boost : hint_range(1.0, 1.5, 0.05); +uniform float boost : hint_range(1.0, 1.5, 0.05) = float(1.2); +uniform float vignette_opacity : hint_range(0.1, 0.5, 0.05) = float(0.3); +uniform bool show_grille = true; // Grille only works in Stretch Mode: 2D. +uniform bool show_scanlines = true; +uniform bool show_vignette = true; +uniform bool show_curvature = true; vec2 CRTCurveUV(vec2 uv) { - uv = uv * 2.0 - 1.0; - vec2 offset = abs(uv.yx) / vec2(6.0, 4.0); - uv = uv + uv * offset * offset; - uv = uv * 0.5 + 0.5; + if(show_curvature) { + uv = uv * 2.0 - 1.0; + vec2 offset = abs(uv.yx) / vec2(6.0, 4.0); + uv = uv + uv * offset * offset; + uv = uv * 0.5 + 0.5; + } return uv; } -void DrawVignette(inout vec4 color, vec2 uv) { - float vignette = uv.x * uv.y * ( 1.0 - uv.x ) * ( 1.0 - uv.y ); - vignette = clamp( pow( 16.0 * vignette, 0.3 ), 0.0, 1.0 ); - color *= vignette; +void DrawVignette(inout vec4 color, vec2 uv) { + if(show_vignette) { + float vignette = uv.x * uv.y * (1.0 - uv.x) * (1.0 - uv.y); + vignette = clamp(pow(16.0 * vignette, vignette_opacity), 0.0, 1.0); + color *= vignette; + } else { + return; + } } void DrawScanline(inout vec4 color, vec2 uv, float time) { float scanline = clamp(0.95 + 0.05 * cos(3.14 * (uv.y + 0.008 * time) * 240.0 * 1.0), 0.0, 1.0); - float grille = 0.85 + 0.15 * clamp(1.5 * cos(3.14 * uv.x * 640.0 * 1.0), 0.0, 1.0); - color *= scanline * grille * boost; + float grille = 0.85 + 0.15 * clamp(1.5 * cos(3.14 * uv.x * 640.0 * 1.0), 0.0, 1.0); + + if(show_scanlines && !show_grille) { + color *= scanline * boost; + } else if(!show_scanlines && show_grille) { + color *= grille * boost; + } else if(show_scanlines && show_grille) { + color *= scanline * grille * boost; + } else { + color *= boost; + } } void fragment() { vec4 color = blend_color; - vec2 crtUV = CRTCurveUV( UV ); + vec2 crtUV = CRTCurveUV(UV); if (crtUV.x < 0.0 || crtUV.x > 1.0 || crtUV.y < 0.0 || crtUV.y > 1.0) { color = vec4(0.0, 0.0, 0.0, 1.0); } diff --git a/project.godot b/project.godot index da5c649..9bd5362 100644 --- a/project.godot +++ b/project.godot @@ -25,7 +25,7 @@ window/size/width=320 window/size/height=180 window/size/test_width=640 window/size/test_height=360 -window/stretch/mode="viewport" +window/stretch/mode="2d" [rendering]