Horror / retro mood shader

Hints and Guidelines, How To's on Registration, Activation, NWN, etc.

Moderators: Forum Moderators, Active DMs

Post Reply
User avatar
Liareth
General Admin
General Admin
Posts: 1167
Joined: Mon Sep 08, 2014 8:25 am

Horror / retro mood shader

Post by Liareth » Thu Aug 04, 2022 7:31 pm

I made a shader which can be used on Arelith. It has an old school retro horror vibe, kinda like Heretic II or other games from that era. It's definitely not for everybody so check out these before/afters, and if you like it, try it out.

Before 1 | After 1
Before 2 | After 2
Before 3 | After 3
Before 4 | After 4
Before 5 | After 5

If you want to try it out, grab the file from the link below then move it into your override folder which can be found in My Documents/Neverwinter Nights. If you're feeling spicy, you can even tweak the strength of the effect: open up the fsfbpostpr.shd in a text editor and tweak the number at the top (following the instructions in the file), where 0.0 is the effect fully disabled and 1.0 is the effect fully enabled. I find around 0.5 to 0.6 to work best - too much and all the colour disappears, too little and it loses the vibe.

Note: You must have at least one full screen effect enabled (such as high contrast, etc, they're all together in the menu) for this to work in the current patch!

Shader file: https://file.io/y6NoivAvq5cy

The code is below, you can instead copy/paste the code into your override folder in a file called fsfbpostpr.shd if you don't want to download with the above link. You don't need this if you downloaded from the link above.

Code: Select all

// 0.0 is the same as no effect, 1.0 is the same as full effect.
#define SHADER_STRENGTH 0.6 // <- Edit this number to change the strength of the effect!

#define SHADER_TYPE 2

#include "inc_postpr"

vec3 rgb2xyz(vec3 c)
{
    vec3 tmp;
    tmp.x = ( c.r > 0.04045 ) ? pow( ( c.r + 0.055 ) / 1.055, 2.4 ) : c.r / 12.92;
    tmp.y = ( c.g > 0.04045 ) ? pow( ( c.g + 0.055 ) / 1.055, 2.4 ) : c.g / 12.92,
    tmp.z = ( c.b > 0.04045 ) ? pow( ( c.b + 0.055 ) / 1.055, 2.4 ) : c.b / 12.92;
    const mat3 mat = mat3(
        0.4124, 0.3576, 0.1805,
        0.2126, 0.7152, 0.0722,
        0.0193, 0.1192, 0.9505 
    );
    return 100.0 * tmp * mat;
}

vec3 xyz2lab(vec3 c)
{
    vec3 n = c / vec3(95.047, 100, 108.883);
    vec3 v;
    v.x = ( n.x > 0.008856 ) ? pow( n.x, 1.0 / 3.0 ) : ( 7.787 * n.x ) + ( 16.0 / 116.0 );
    v.y = ( n.y > 0.008856 ) ? pow( n.y, 1.0 / 3.0 ) : ( 7.787 * n.y ) + ( 16.0 / 116.0 );
    v.z = ( n.z > 0.008856 ) ? pow( n.z, 1.0 / 3.0 ) : ( 7.787 * n.z ) + ( 16.0 / 116.0 );
    return vec3(( 116.0 * v.y ) - 16.0, 500.0 * ( v.x - v.y ), 200.0 * ( v.y - v.z ));
}

vec3 rgb2lab(vec3 c)
{
    vec3 lab = xyz2lab( rgb2xyz( c ) );
    return vec3( lab.x / 100.0, 0.5 + 0.5 * ( lab.y / 127.0 ), 0.5 + 0.5 * ( lab.z / 127.0 ));
}

#define PALETTE_COUNT 16

void main()
{
	gl_FragColor = FS_PostProcess();
    vec3 lab = rgb2lab(gl_FragColor.rgb);

    const vec3 palette[PALETTE_COUNT] = vec3[]
    (
        // Based on DARKSEED 16
        vec3(0.012,0.012,0.012),
        vec3(0.,0.078,0.094),
        vec3(0.,0.125,0.141),
        vec3(0.,0.173,0.22),
        vec3(0.078,0.204,0.267),
        vec3(0.267,0.204,0.267),
        vec3(0.345,0.235,0.282),
        vec3(0.424,0.298,0.267),
        vec3(0.502,0.376,0.345),
        vec3(0.424,0.439,0.424),
        vec3(0.533,0.502,0.471),
        vec3(0.643,0.58,0.518),
        vec3(0.769,0.675,0.612),
        vec3(0.847,0.69,0.659),
        vec3(0.925,0.831,0.816),
        vec3(0.988,0.988,0.988)
    );

    float distMin = 1.0f;
    int distMinPalette = 0;

    for (int i = 0; i < PALETTE_COUNT; ++i)
    {
        float dist = distance(lab, rgb2lab(palette[i]));
    
        if (dist < distMin)
        {
            distMin = dist;
            distMinPalette = i;
        }
    }

    gl_FragColor.rgb = mix(gl_FragColor.rgb, palette[distMinPalette], SHADER_STRENGTH);
}

User avatar
Mattamue
Arelith Silver Supporter
Arelith Silver Supporter
Posts: 468
Joined: Mon Dec 10, 2018 1:45 am

Re: Horror / retro mood shader

Post by Mattamue » Thu Aug 04, 2022 8:11 pm

Thanks, looks cool! I'm also going to use this to learn shaders

Who is the audience for this post?


Post Reply