Is there a way to make this lightmode in gzdoom?
Moderator: Graf Zahl
-
- Posts: 152
- Joined: Tue Oct 25, 2011 13:05
Is there a way to make this lightmode in gzdoom?
I belive it's something similar to the software lightmode, but it start decreasing the light in a far distance, and later everything is black.
So? (at least some tip about where is the software lightmode is so I could play with it )
- Rachael
- Developer
- Posts: 3646
- Joined: Sat May 13, 2006 10:30
Re: Is there a way to make this lightmode in gzdoom?
Yes, there is. You will have to use the shader system, though.
I don't know if there's a cleaner way to do this, but you can target the following shader:
And use this MAPINFO definition:
Graf might have an idea of how it could/should be done differently, though. I've played with that shader some good bit, though, but nothing that's actually published into a project because main.fp is always changing.
I don't know if there's a cleaner way to do this, but you can target the following shader:
Code: Select all
gzdoom.pk3/shaders/glsl/main.fp - function R_DoomLightingEquation
Code: Select all
lightmode = 8
-
- Posts: 152
- Joined: Tue Oct 25, 2011 13:05
Re: Is there a way to make this lightmode in gzdoom?
Thanks Eruanna, that did the trickEruanna wrote:Yes, there is. You will have to use the shader system, though.
I don't know if there's a cleaner way to do this, but you can target the following shader:And use this MAPINFO definition:Code: Select all
gzdoom.pk3/shaders/glsl/main.fp - function R_DoomLightingEquation
Graf might have an idea of how it could/should be done differently, though. I've played with that shader some good bit, though, but nothing that's actually published into a project because main.fp is always changing.Code: Select all
lightmode = 8
Code: Select all
float R_DoomLightingEquation(float light)
{
// Calculated from r_visibility. It differs between walls, floor and sprites.
//
// Wall: globVis = r_WallVisibility
// Floor: r_FloorVisibility / abs(plane.Zat0 - ViewPos.Z)
// Sprite: same as wall
// All are calculated in R_SetVisibility and seem to be decided by the
// aspect ratio amongst other things.
lightscale = clamp(min(pixelpos.w,500.0) / 500.0, 0.0, 1.0);
return lightscale;
}
- Rachael
- Developer
- Posts: 3646
- Joined: Sat May 13, 2006 10:30
Re: Is there a way to make this lightmode in gzdoom?
You're welcome.
Just remember that main.fp changes with every GZDoom version. If this function does not get exported to its own file, you will have to include a script with your distribution that rewrites the user's current main.fp with your custom function, and then stores the changes inside your mod. Otherwise, GZDoom's shaders will fail to compile (with other GZDoom versions) - and in some cases might not even start.
Just remember that main.fp changes with every GZDoom version. If this function does not get exported to its own file, you will have to include a script with your distribution that rewrites the user's current main.fp with your custom function, and then stores the changes inside your mod. Otherwise, GZDoom's shaders will fail to compile (with other GZDoom versions) - and in some cases might not even start.
-
- Posts: 152
- Joined: Tue Oct 25, 2011 13:05
Re: Is there a way to make this lightmode in gzdoom?
uh, I belive for now the new shader option will just be enabled under my separated port, and for gzdoom people will just use the normal software lightmode
-
- Posts: 152
- Joined: Tue Oct 25, 2011 13:05
Re: Is there a way to make this lightmode in gzdoom?
Code: Select all
/* L is the integer light level used in the game */
float L = 255 - light * 255.0;
//Spooky house Light Equation
float lightscale;
lightscale = clamp(( min(pixelpos.w * L , 76500.0)) / 76500.0, 0.0, 1.0);
But for somehow it's not doing that (I belive it should end in something like min ( x * 0, 76500.0), and anything * 0 is 0, unless I'm missing some importante thing here and the minimal valua is a bit higher than 0 (ie 1)
-
- Developer
- Posts: 798
- Joined: Sat Jul 23, 2016 7:53
Re: Is there a way to make this lightmode in gzdoom?
Light and color values in GLSL are in the 0-1 range, with 0 being black and 1 being max. If you look at the code in getLightColor you have this code:
This means that if R_DoomLightingEquation return 0 it will be 1-0 = 1 -> full bright. While if it returns 1 then it will be 1-1 = 0 -> black. uLightLevel is in the range 0-1 as well. So if the sector has a value of 255 in the map, then uLightLevel will be 1. 128 is 0.5 and so on.
The code you're seeing in R_DoomLightingEquation is relatively complex because it maps the value back to 0-255 (by multiplying light by 255) so that the 'zdoom light equation' can be an exact match to what I grabbed out of the zdoom codebase. You don't have to do that. To get the effect you're asking, you can make the function much simpler. Something like this should do the trick:
Code: Select all
float newlightlevel = 1.0 - R_DoomLightingEquation(uLightLevel);
color.rgb *= newlightlevel;
The code you're seeing in R_DoomLightingEquation is relatively complex because it maps the value back to 0-255 (by multiplying light by 255) so that the 'zdoom light equation' can be an exact match to what I grabbed out of the zdoom codebase. You don't have to do that. To get the effect you're asking, you can make the function much simpler. Something like this should do the trick:
Code: Select all
float R_DoomLightingEquation(float light)
{
float fullDarkDistance = 100.0; // Adjust this value to what distance you want it to get fully dark.
return clamp(pixelpos.w / fullDarkDistance, 0.0, 1.0) * (1.0 - light);
}
-
- Developer
- Posts: 798
- Joined: Sat Jul 23, 2016 7:53
Re: Is there a way to make this lightmode in gzdoom?
Damn, think that's also actually wrong. It should look like this:
Code: Select all
float R_DoomLightingEquation(float light)
{
float fullDarkDistance = 100.0; // Adjust this value to what distance you want it to get fully dark.
return 1.0 - max((1.0 - pixelpos.w / fullDarkDistance) * light, 0.0);
}
-
- Posts: 152
- Joined: Tue Oct 25, 2011 13:05
Re: Is there a way to make this lightmode in gzdoom?
just wondering, what the .w value is used for?
-
- Developer
- Posts: 798
- Joined: Sat Jul 23, 2016 7:53
Re: Is there a way to make this lightmode in gzdoom?
It is the depth (Z) value of the pixel/fragment in view/eye space (the camera's point of view).