[gizdoom] Lazy palette shader

Projects that have specifically been abandoned or considered "dead" get moved here, so people will quit bumping them. If your project has wound up here and it should not be, contact a moderator to have it moved back to the land of the living.

[gizdoom] Lazy palette shader

Postby leileilol » Sat Aug 20, 2016 1:18 am

Because it's the current zdoom noveltrendy and is the new volumetric light linedef.

This is the lazy unproper way of postprocessing the view to a lookup table palette (A more proper way would be indexing every texel and literally colormapping in a shader with LUTs, but...... that calls for more in-depth engine hackery). This is more of a proof-of-concept.

Replaces tonemap shaders, and as a result, there are multiple palettes to look up to:

Unsharted 2 = Doom
Bagel Dawson = Heretic
ReignHard = Strife
Liner = Hexen

Recommended you play this in Software light mode, nearest texture filter and in a low res for best intendedeffect

TELECHARGER:
lei-glsl-palettev2.pk3
(5.73 KiB) Downloaded 264 times


GReeTZ:
- just VileRancour for refactoring my old palette shader for dosbox from a long time ago. this is a porting from hlsl as well
- myself for even getting it to work with 256 colors

BUICKS:
- the flash quad gets caught up in it instead of blending after
- it's slow and not a lookup texture is used.
- it might not even compile on your lower-end card's drivers.

SCREEN SHOOT'S:
thisisnotsoftware.png


FACK:
Q: why whats the point just use zdoom
A: FACK YOU MAN

Spoiler: older than u think
Last edited by leileilol on Tue Aug 23, 2016 12:25 am, edited 1 time in total.
User avatar
leileilol
ダークエルフ!!!!!!!!!!
 
Joined: 30 May 2004
Location: GNU/Hell

Re: [gizdoom] Lazy palette shader

Postby torridgristle » Sat Aug 20, 2016 3:46 am

It gave me the error "Compile Shader 'shaders/glsl/tonemap.fp': 0(1064) : error C7549: OpenGL does not allow C style initializers" so I looked it up online and found what might have been a solution.

The solution proposed was to change const vec3 rgbi_palette[256] = { to vec3 rgbi_palette[256] = vec3[256]( and also remove the final comma in the array. I don't know if that comma matters and because of what happened when I ran it I'm too scared to test it to find out.

I didn't get an error from GZDoom when I ran it that time, instead my entire laptop locked up for several minutes until the screen went black and a Windows error sound played. I had to hard reboot. It was a terrible experience.

I guess this just won't happen for me until we can access an image from fragment shaders for a proper LUT in GZDoom. It really is a cool concept though.
User avatar
torridgristle
Sprites will be 120% tall in the game.
 
Joined: 23 Aug 2013

Re: [gizdoom] Lazy palette shader

Postby dpJudas » Sat Aug 20, 2016 8:22 am

According to that same page the following syntax should have a lot better performance: uniform vec3 rgbi_palette[256] = vec3[](

However, what is really pulling out teeth is the way the shader brute forces the color->palette lookup. A real testament to just how insanely fast modern GPUs are - doing what id software had to precalculate on every single pixel on the screen in real time. :D

The solution is to do what zdoom does itself for colors: a rgb555 to palette index LUT (https://github.com/rheit/zdoom/blob/master/src/v_video.h#L443). To build it, loot this from zdoom: https://github.com/rheit/zdoom/blob/master/src/v_video.cpp#L657 where ColorMatcher.Pick is something like nearest_rgbi. Shader part then becomes something ala:

Code: Select allExpand view
ivec3 c = ivec3(clamp(color.rgb, vec(0.0), vec(1.0)) * 255.0 + 0.5);
int index = ((c.r >> 3) * 32 + (c.g >> 3)) * 32 + (c.b >> 3);
FragColor = RGB32k[index];

Btw., very cool to see both this shader and the RetroShader! Had a feeling the community would go wild with such stuff. :D
dpJudas
 
 
 
Joined: 28 May 2016

Re: [gizdoom] Lazy palette shader

Postby Nash » Sat Aug 20, 2016 9:25 am

Banded true colour shading in the OpenGL renderer? My dreams are finally coming true. :') This should be a stock GZDoom optional feature, TBH. Get pull requesting!!!

Because it's the current zdoom noveltrendy and is the new volumetric light linedef.


cool grafic's and shader's fx (C) leilielol DON"T NOT STEAL:!!!!!

EDIT:

File in OP does not work. Tried both torridgristle's and dpJudas' code, both do not work. Commands at the end of the arrays have been removed. Additioanlly, changing ( to { also doesn't work. Error is that the shader does not compile.

I'm on an NVidia GTX 960 with the latest drivers if that's relevant.
User avatar
Nash
 
 
 
Joined: 27 Oct 2003
Location: Kuala Lumpur, Malaysia
Github ID: nashmuhandes

Re: [gizdoom] Lazy palette shader

Postby dpJudas » Sat Aug 20, 2016 4:58 pm

Here's the adjusted version that I used on my computer (Nvidia 980).
Attachments
lei-glsl-palette.pk3
Same as original lei-glsl-palette, except it uses uniform instead of const
(6.29 KiB) Downloaded 93 times
dpJudas
 
 
 
Joined: 28 May 2016

Re: [gizdoom] Lazy palette shader

Postby leileilol » Sat Aug 20, 2016 5:07 pm

dpJudas wrote:a rgb555

not precise enough. It's 18-bit (rgb666) or nothing
User avatar
leileilol
ダークエルフ!!!!!!!!!!
 
Joined: 30 May 2004
Location: GNU/Hell

Re: [gizdoom] Lazy palette shader

Postby dpJudas » Sat Aug 20, 2016 5:10 pm

Haha, point taken. :D
dpJudas
 
 
 
Joined: 28 May 2016

Re: [gizdoom] Lazy palette shader

Postby torridgristle » Sat Aug 20, 2016 5:17 pm

dpJudas wrote:Here's the adjusted version that I used on my computer (Nvidia 980).

This one doesn't give me an error and looked good but wow does it not run well at all. I imagine that's to be expected though.

Edit: Black appearing in what should be white.
Image
User avatar
torridgristle
Sprites will be 120% tall in the game.
 
Joined: 23 Aug 2013

Re: [gizdoom] Lazy palette shader

Postby Nash » Sun Aug 21, 2016 12:03 am

dpJudas' fixed version runs for me too.

Oh WOW, MAP25 actually looks ugly, just like in the software renderer again. :O This is just blowing my mind. Never expected to see a banded lighting shader for GZDoom this soon. =P

Also LMAO 30 FPS

My only "complaint" (if you could even call it that) so far is that even the colours on your weapon sprite is slightly affected, but I guess you can't really control this because this is processing the entire screen...
User avatar
Nash
 
 
 
Joined: 27 Oct 2003
Location: Kuala Lumpur, Malaysia
Github ID: nashmuhandes

Re: [gizdoom] Lazy palette shader

Postby Rachael » Sun Aug 21, 2016 12:33 pm

torridgristle wrote:Edit: Black appearing in what should be white.
Image

What mod is that?

I think I know what is going on here, the "white" is simply too white, and floating point pixel values are being passed to the shader, so obviously they are allowed to exceed the maximum.

Look for this line in tonemap.fp:
Code: Select allExpand view
  float min_dst = 2.0;


Change it to something arbitrary, like
Code: Select allExpand view
  float min_dst = 1000.0;


If you're comfortable with shader programming, you can instead put caps on the incoming color vectors and that will be less glitchy but it will take a few more lines of code. This solution is only a hack. Alternatively, you can also do this:

In this loop:
Code: Select allExpand view
  for (int i=0; i<256; i++) {
    dst = distance(original, rgbi_palette[i]);
    if (dst < min_dst) {
      min_dst = dst;
      idx = i;
    }
  }

Change this code:
Code: Select allExpand view
    if (dst < min_dst) {

to
Code: Select allExpand view
    if (dst < min_dst || i == 0) {

This will force a distance check no matter what at the beginning of the loop, allowing really really bright whites to pass through the loop without problems.

Only one of these "fixes" is required. The last one might be the best one.
Last edited by Rachael on Sun Aug 21, 2016 12:40 pm, edited 1 time in total.
User avatar
Rachael
Webmaster
 
Joined: 13 Jan 2004
Discord: Rachael#3767
Twitch ID: madamerachelle
Github ID: madame-rachelle
Graphics Processor: nVidia with Vulkan support

Re: [gizdoom] Lazy palette shader

Postby torridgristle » Sun Aug 21, 2016 12:37 pm

Eruanna wrote:What mod is that?


It's D4D, and your change fixed it.
User avatar
torridgristle
Sprites will be 120% tall in the game.
 
Joined: 23 Aug 2013

Re: [gizdoom] Lazy palette shader

Postby Rachael » Sun Aug 21, 2016 12:40 pm

torridgristle wrote:It's D4D, and your change fixed it.

Great. :) It's exactly what I suspected, then.

Here's the "fixed" version for anyone else then. I also cleaned up the initialization code since it was not needed anymore.
Attachments
lei-glsl-palette2.pk3
(5.94 KiB) Downloaded 92 times
User avatar
Rachael
Webmaster
 
Joined: 13 Jan 2004
Discord: Rachael#3767
Twitch ID: madamerachelle
Github ID: madame-rachelle
Graphics Processor: nVidia with Vulkan support

Re: [gizdoom] Lazy palette shader

Postby Nash » Mon Aug 22, 2016 1:49 am

Thank you for the fixes Eruanna! And of course thanks to leileilol and dpJudas too for the earlier iterations. =) This is so fun to play with even just for the novelty and despite the 30 FPS cap :S
User avatar
Nash
 
 
 
Joined: 27 Oct 2003
Location: Kuala Lumpur, Malaysia
Github ID: nashmuhandes

Re: [gizdoom] Lazy palette shader

Postby Nash » Mon Aug 22, 2016 2:58 am

Update: it seems that after just playing normally for some time, the framerate suddenly goes to 60 and stays smooth indefinitely. However, in that same play session, when I turn off the tonemap feature then back on, the game will go back to the usual 30 FPS and I can't seem to find a way to make it magically go back to 60 FPS.

I've only managed to make this happen once and I don't know how to reproduce it. Thought it was worth mentioning that the game CAN get smooth with this shader loaded, and it's probably worth investigating?

(This happened to me with Eruanna's version)
User avatar
Nash
 
 
 
Joined: 27 Oct 2003
Location: Kuala Lumpur, Malaysia
Github ID: nashmuhandes

Re: [gizdoom] Lazy palette shader

Postby Rachael » Mon Aug 22, 2016 4:48 am

What happens if you try setting vid_vsync to false and set vid_maxfps to 61?

Sounds like something is taking longer than exactly 1/60th of a second but not long enough to take 1/30th of a second - but whatever it is it's triggering the vsync wait anyway, which causes your FPS to drop to 30.

EDIT: Cancel that - vid_maxfps seems to be broken at the moment, reporting as a bug.
User avatar
Rachael
Webmaster
 
Joined: 13 Jan 2004
Discord: Rachael#3767
Twitch ID: madamerachelle
Github ID: madame-rachelle
Graphics Processor: nVidia with Vulkan support

Next

Return to Abandoned/Dead Projects

Who is online

Users browsing this forum: No registered users and 1 guest