Skip to content

Commit

Permalink
Bumped to v1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
hiulit committed Jul 15, 2019
1 parent b61d848 commit 7e36a14
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 16 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
34 changes: 33 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 6 additions & 2 deletions crt_material.tres
Original file line number Diff line number Diff line change
Expand Up @@ -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

44 changes: 32 additions & 12 deletions crt_shader.shader
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down

0 comments on commit 7e36a14

Please sign in to comment.