Skip to content

Commit

Permalink
Add standalone nds_color shader
Browse files Browse the repository at this point in the history
  • Loading branch information
jdgleaver committed Apr 28, 2022
1 parent e6eacc8 commit 2b28fb3
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@ A port of the 'sharp-bilinear'/'sharp-bilinear-simple' shader from RetroArch. Cr
## zFast LCD

A port of the 'zfast_lcd' shader from RetroArch. Creates an LCD effect by adding a subtle grid lattice to the screen. REQUIRES a high resolution display (at least 1080p). Works best with integer screen scaling, but fine without.

## NDS Color

A stand-alone DS Phat colour correction shader, which may be combined (as a first pass) with other shaders not included in this repository.
27 changes: 27 additions & 0 deletions nds_color.dfx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// nds_color shader
=============================================
<options>
name=NDS Color
textures=1
</options>

<fheader>
#if GL_ES
#ifdef GL_FRAGMENT_PRECISION_HIGH
precision highp float;
#else
precision mediump float;
#endif
#endif
</fheader>

<texture:0>
input=framebuffer
min_filter=GL_NEAREST
mag_filter=GL_NEAREST
</texture>

<pass>
shader=nds_color.dsd
sampler:u_texture=0
</pass>
67 changes: 67 additions & 0 deletions nds_color.dsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// nds_color - Applies NDS colour correction, designed to mimic the
// display characteristics of an NDS Phat
//
// - Original 'nds_color' code written by hunterk, modified by Pokefan531 and
// 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>

// Colour defines...
#define target_gamma 1.91
#define display_gamma 1.91
#define lum 0.89
#define r 0.87
#define g 0.645
#define b 0.73
#define rg 0.10
#define rb 0.10
#define gr 0.255
#define gb 0.17
#define br -0.125
#define bg 0.255

uniform sampler2D u_texture;
uniform vec4 u_texture_size;

varying vec2 v_texture_coordinate;

void main()
{
// Get colour sample and apply colour correction
vec3 colour = pow(texture2D(u_texture, v_texture_coordinate.xy).rgb, vec3(target_gamma));
colour = clamp(colour * lum, 0.0, 1.0);
colour = pow(
mat3(r, rg, rb,
gr, g, gb,
br, bg, b) * colour,
vec3(1.0 / display_gamma)
);

gl_FragColor = vec4(colour.rgb, 1.0);
}

</fragment>

0 comments on commit 2b28fb3

Please sign in to comment.