-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add standalone natural_vision shader
- Loading branch information
Showing
3 changed files
with
123 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// natural_vision shader | ||
============================================= | ||
<options> | ||
name=Natural Vision | ||
textures=1 | ||
</options> | ||
|
||
<fheader> | ||
#if GL_ES | ||
#ifdef GL_FRAGMENT_PRECISION_HIGH | ||
precision highp float; | ||
#else | ||
precision mediump float; | ||
#endif | ||
#endif | ||
// Configuration | ||
#define NATVIS_GIN 1.91 // "NaturalVision Gamma In" | ||
// - default: 1.91, min: 0.0, max: 10.0, step: 0.01 | ||
#define NATVIS_GOUT 1.91 // "NaturalVision Gamma Out" | ||
// - default: 1.91, min: 0.0, max: 10.0, step: 0.01 | ||
#define NATVIS_Y 1.1 // "NaturalVision Luminance" | ||
// - default: 1.1, min: 0.0, max: 10.0, step: 0.01 | ||
#define NATVIS_I 1.1 // "NaturalVision Orange-Cyan" | ||
// - default: 1.1, min: 0.0, max: 10.0, step: 0.01 | ||
#define NATVIS_Q 1.1 // "NaturalVision Magenta-Green" | ||
// - default: 1.1, min: 0.0, max: 10.0, step: 0.01 | ||
</fheader> | ||
|
||
<texture:0> | ||
input=framebuffer | ||
min_filter=GL_NEAREST | ||
mag_filter=GL_NEAREST | ||
</texture> | ||
|
||
<pass> | ||
shader=natural_vision.dsd | ||
sampler:u_texture=0 | ||
</pass> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// natural_vision - Applies 'Natural Vision' colour enhancement | ||
// | ||
// - Original 'natural_vision' code written by ShadX, modified by | ||
// Hyllian and Sp00kyFox, released into the public domain | ||
// | ||
// 'Ported' (i.e. copy/paste) to DraStic format by jdgleaver | ||
// | ||
// This program is free software; you can redistribute it and/or modify it | ||
// under the terms of the GNU General Public License as published by the Free | ||
// Software Foundation; either version 2 of the License, or (at your option) | ||
// any later version. | ||
============================================= | ||
|
||
<vertex> | ||
|
||
attribute vec2 a_vertex_coordinate; | ||
attribute vec2 a_texture_coordinate; | ||
uniform vec4 u_texture_size; | ||
|
||
varying vec2 v_texture_coordinate; | ||
|
||
void main() | ||
{ | ||
v_texture_coordinate = a_texture_coordinate; | ||
gl_Position = vec4(a_vertex_coordinate.xy, 0.0, 1.0); | ||
} | ||
|
||
</vertex> | ||
|
||
<fragment> | ||
|
||
#ifndef NATVIS_GIN | ||
#define NATVIS_GIN 1.91 | ||
#endif | ||
#ifndef NATVIS_GOUT | ||
#define NATVIS_GOUT 1.91 | ||
#endif | ||
#ifndef NATVIS_Y | ||
#define NATVIS_Y 1.1 | ||
#endif | ||
#ifndef NATVIS_I | ||
#define NATVIS_I 1.1 | ||
#endif | ||
#ifndef NATVIS_Q | ||
#define NATVIS_Q 1.1 | ||
#endif | ||
|
||
uniform sampler2D u_texture; | ||
uniform vec4 u_texture_size; | ||
|
||
varying vec2 v_texture_coordinate; | ||
|
||
// Natural Vision helpers | ||
const mat3 RGBtoYIQ = mat3(0.299, 0.595716, 0.211456, | ||
0.587, -0.274453, -0.522591, | ||
0.114, -0.321263, 0.311135); | ||
|
||
const mat3 YIQtoRGB = mat3(1.0, 1.0, 1.0, | ||
0.95629572,-0.27212210,-1.10698902, | ||
0.62102442,-0.64738060, 1.70461500); | ||
|
||
const vec3 YIQ_lo = vec3(0.0, -0.595716, -0.522591); | ||
const vec3 YIQ_hi = vec3(1.0, 0.595716, 0.522591); | ||
|
||
void main() | ||
{ | ||
// Get colour sample and apply colour enhancement | ||
vec3 colour = pow(texture2D(u_texture, v_texture_coordinate.xy).rgb, vec3(NATVIS_GIN)); | ||
colour = RGBtoYIQ * colour; | ||
colour = vec3(pow(colour.x, NATVIS_Y), colour.y * NATVIS_I, colour.z * NATVIS_Q); | ||
colour = clamp(colour, YIQ_lo, YIQ_hi); | ||
colour = YIQtoRGB * colour; | ||
colour = pow(colour, vec3(1.0 / NATVIS_GOUT)); | ||
|
||
gl_FragColor = vec4(colour.rgb, 1.0); | ||
} | ||
|
||
</fragment> |