Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?xml version="1.0" encoding="UTF-8"?>
- <!--
- PhosphorLUT-scanlines v1.0
- This shader uses an external lookup texture (LUT) to create a shadow mask with individual RGB phosphor lenses.
- You can swap out the LUTs by changing the 'file' referenced in Line 11.
- You can also uncomment line 157 if you're using this shader on a low-resolution display (i.e., 1080p or below) to fix the colors a bit.
- Author: hunterk
- License: GPL (contains code from other GPL shaders).
- -->
- <shader language="GLSL">
- <texture id="phosphorLUT" file="aperture2.png" filter="linear"/>
- <vertex><![CDATA[
- uniform vec2 rubyTextureSize;
- uniform vec2 rubyInputSize;
- uniform vec2 rubyOutputSize;
- varying vec2 omega;
- void main()
- {
- gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
- gl_TexCoord[0].xy = gl_MultiTexCoord0.xy;
- gl_TexCoord[1].xy = gl_MultiTexCoord1.xy;
- omega = vec2(3.1415 * rubyOutputSize.x * rubyTextureSize.x / rubyInputSize.x, 2.0 * 3.1415 * rubyTextureSize.y);
- }
- ]]></vertex>
- <fragment filter="linear" outscale="2.0"><![CDATA[
- uniform sampler2D rubyTexture;
- uniform sampler2D phosphorLUT;
- uniform vec2 rubyTextureSize;
- uniform vec2 rubyInputSize;
- uniform vec2 rubyOutputSize;
- varying vec2 omega;
- const float base_brightness = 0.95;
- const vec2 sine_comp = vec2(0.05, 0.85);
- void main()
- {
- vec4 frame = texture2D(rubyTexture, gl_TexCoord[0].xy);
- vec4 inverse = 1 - texture2D(rubyTexture, gl_TexCoord[0].xy);
- vec4 screen = texture2D(phosphorLUT, gl_TexCoord[1].xy);
- vec4 final = screen - inverse;
- vec4 scanline = final * (base_brightness + dot(sine_comp * sin(gl_TexCoord[0].xy * omega), vec2(1.0)));
- gl_FragColor = clamp(scanline, 0.0, 1.0);
- //gl_FragColor = screen - inverse;
- }
- ]]></fragment>
- <fragment filter="linear" outscale="1.0"><![CDATA[
- uniform sampler2D rubyTexture;
- uniform vec2 rubyTextureSize;
- uniform vec2 rubyInputSize;
- uniform vec2 rubyOutputSize;
- #define CRTgamma 2.5
- #define display_gamma 2.0
- #define TEX2D(c) pow(texture2D(rubyTexture,(c)),vec4(CRTgamma))
- void main()
- {
- vec2 xy = gl_TexCoord[0].st;
- float oney = 1.0/rubyTextureSize.y;
- float wid = 2.0;
- float c1 = exp(-1.0/wid/wid);
- float c2 = exp(-4.0/wid/wid);
- float c3 = exp(-9.0/wid/wid);
- float c4 = exp(-16.0/wid/wid);
- float norm = 1.0 / (1.0 + 2.0*(c1+c2+c3+c4));
- vec4 sum = vec4(0.0);
- sum += TEX2D(xy + vec2(0.0, -4.0 * oney)) * vec4(c4);
- sum += TEX2D(xy + vec2(0.0, -3.0 * oney)) * vec4(c3);
- sum += TEX2D(xy + vec2(0.0, -2.0 * oney)) * vec4(c2);
- sum += TEX2D(xy + vec2(0.0, -1.0 * oney)) * vec4(c1);
- sum += TEX2D(xy);
- sum += TEX2D(xy + vec2(0.0, +1.0 * oney)) * vec4(c1);
- sum += TEX2D(xy + vec2(0.0, +2.0 * oney)) * vec4(c2);
- sum += TEX2D(xy + vec2(0.0, +3.0 * oney)) * vec4(c3);
- sum += TEX2D(xy + vec2(0.0, +4.0 * oney)) * vec4(c4);
- gl_FragColor = pow(sum*vec4(norm),vec4(1.0/display_gamma));
- }
- ]]></fragment>
- <fragment filter="linear" outscale="1.0"><![CDATA[
- uniform sampler2D rubyTexture;
- uniform vec2 rubyTextureSize;
- uniform vec2 rubyInputSize;
- uniform vec2 rubyOutputSize;
- #define CRTgamma 2.5
- #define display_gamma 2.0
- #define TEX2D(c) pow(texture2D(rubyTexture,(c)),vec4(CRTgamma))
- void main()
- {
- vec2 xy = gl_TexCoord[0].st;
- float oney = 1.0/rubyTextureSize.y;
- float wid = 6.0;
- float c1 = exp(-1.0/wid/wid);
- float c2 = exp(-4.0/wid/wid);
- float c3 = exp(-9.0/wid/wid);
- float c4 = exp(-16.0/wid/wid);
- float norm = 1.0 / (1.0 + 2.0*(c1+c2+c3+c4));
- vec4 sum = vec4(0.0);
- sum += TEX2D(xy + vec2(0.0, -4.0 * oney)) * vec4(c4);
- sum += TEX2D(xy + vec2(0.0, -3.0 * oney)) * vec4(c3);
- sum += TEX2D(xy + vec2(0.0, -2.0 * oney)) * vec4(c2);
- sum += TEX2D(xy + vec2(0.0, -1.0 * oney)) * vec4(c1);
- sum += TEX2D(xy);
- sum += TEX2D(xy + vec2(0.0, +1.0 * oney)) * vec4(c1);
- sum += TEX2D(xy + vec2(0.0, +2.0 * oney)) * vec4(c2);
- sum += TEX2D(xy + vec2(0.0, +3.0 * oney)) * vec4(c3);
- sum += TEX2D(xy + vec2(0.0, +4.0 * oney)) * vec4(c4);
- gl_FragColor = pow(sum*vec4(norm),vec4(1.0/display_gamma));
- }
- ]]></fragment>
- <vertex><![CDATA[
- attribute vec2 rubyOrigTexCoord;
- varying vec2 orig_tex;
- void main()
- {
- gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
- orig_tex = rubyOrigTexCoord;
- gl_TexCoord[1].xy = gl_MultiTexCoord1.xy;
- }
- ]]></vertex>
- <fragment filter="linear" outscale="1.0"><![CDATA[
- uniform sampler2D rubyOrigTexture;
- uniform sampler2D phosphorLUT;
- varying vec2 orig_tex;
- uniform float brightness;
- void main()
- {
- float brightness = 1.2;
- vec4 frame = texture2D(rubyOrigTexture, orig_tex);
- vec4 inverse = 1 - (brightness * texture2D(rubyOrigTexture, orig_tex));
- vec4 screen = texture2D(phosphorLUT, gl_TexCoord[1].xy);
- gl_FragColor = screen - inverse;
- }
- ]]></fragment>
- <vertex><![CDATA[
- attribute vec2 rubyPass1TexCoord;
- attribute vec2 rubyPass2TexCoord;
- varying vec2 pass1_tex;
- varying vec2 pass2_tex;
- void main() {
- gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
- gl_TexCoord[0] = gl_MultiTexCoord0;
- pass1_tex = rubyPass1TexCoord;
- pass2_tex = rubyPass2TexCoord;
- }
- ]]></vertex>
- <fragment filter="linear"><![CDATA[
- uniform sampler2D rubyPass1Texture; // Result from Pass 1.
- uniform sampler2D rubyPass2Texture; // Result from Pass 2.
- uniform sampler2D rubyTexture; // Result from Pass 3 (previous pass).
- varying vec2 pass1_tex;
- varying vec2 pass2_tex;
- //#define LOWRES
- void main() {
- vec4 pass1 = texture2D(rubyPass1Texture, pass1_tex);
- vec4 pass2 = texture2D(rubyPass2Texture, pass2_tex);
- vec4 pass3 = texture2D(rubyTexture, gl_TexCoord[0].xy);
- #ifdef LOWRES
- gl_FragColor = 1.0 - (1.0 - pass1) * (1.0 - pass2) * (1.0 - pass2) * (1.0 - pass2);
- #else
- gl_FragColor = 1.0 - (1.0 - pass1) * (1.0 - pass2) * (1.0 - pass3);
- #endif
- }
- ]]></fragment>
- </shader>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement