-
Notifications
You must be signed in to change notification settings - Fork 21
/
lcd1x+nds_color.dsd
105 lines (86 loc) · 2.88 KB
/
lcd1x+nds_color.dsd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// lcd1x+nds_color - Simple LCD 'scanline' shader, based on lcd3x
//
// - Original lcd3x code by Gigaherz, released into the public domain
//
// - 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.
//
// lcd1x+nds_color differs from lcd3x in the following manner:
//
// > Omits LCD-style colour separation
//
// > Has 'correctly' aligned scanlines
//
// > Automatically supports 'high resolution 3d rendering' ON or OFF
//
// > Applies NDS colour correction
=============================================
<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 BRIGHTEN_SCANLINES
#define BRIGHTEN_SCANLINES 16.0
#endif
#ifndef BRIGHTEN_LCD
#define BRIGHTEN_LCD 4.0
#endif
#define PI 3.141592654
// 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;
const float NDS_SCREEN_HEIGHT = 192.0;
const float INV_BRIGHTEN_SCANLINES_INC = 1.0 / (BRIGHTEN_SCANLINES + 1.0);
const float INV_BRIGHTEN_LCD_INC = 1.0 / (BRIGHTEN_LCD + 1.0);
void main()
{
// Note to self: uniform vec4 u_texture_size(1.0/w, 1.0/h, w, h)
// Generate LCD grid effect
// > Note the 0.25 pixel offset -> required to ensure that
// scanlines occur *between* pixels
// > Divide pixel coordinate by current scale factor (texture_height / NDS_SCREEN_HEIGHT)
vec2 angle = 2.0 * PI * (((v_texture_coordinate.xy * u_texture_size.zw) * NDS_SCREEN_HEIGHT * u_texture_size.y) - 0.25);
float yfactor = (BRIGHTEN_SCANLINES + sin(angle.y)) * INV_BRIGHTEN_SCANLINES_INC;
float xfactor = (BRIGHTEN_LCD + sin(angle.x)) * INV_BRIGHTEN_LCD_INC;
// 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)
);
// Apply LCD grid effect
colour.rgb = yfactor * xfactor * colour.rgb;
gl_FragColor = vec4(colour.rgb, 1.0);
}
</fragment>