Is there a way to make this lightmode in gzdoom?

Advanced OpenGL source port fork from ZDoom, picking up where ZDoomGL left off.
[Home] [Download] [Git builds (Win)] [Git builds (Mac)] [Wiki] [Repo] [Bugs&Suggestions]

Moderator: Graf Zahl

Locked
ibm5155
Posts: 152
Joined: Tue Oct 25, 2011 13:05

Is there a way to make this lightmode in gzdoom?

Post by ibm5155 »

Image
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 :D )
User avatar
Rachael
Developer
Developer
Posts: 3646
Joined: Sat May 13, 2006 10:30

Re: Is there a way to make this lightmode in gzdoom?

Post by Rachael »

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:

Code: Select all

gzdoom.pk3/shaders/glsl/main.fp - function R_DoomLightingEquation
And use this MAPINFO definition:

Code: Select all

lightmode = 8
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.
ibm5155
Posts: 152
Joined: Tue Oct 25, 2011 13:05

Re: Is there a way to make this lightmode in gzdoom?

Post by ibm5155 »

Eruanna 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:

Code: Select all

gzdoom.pk3/shaders/glsl/main.fp - function R_DoomLightingEquation
And use this MAPINFO definition:

Code: Select all

lightmode = 8
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.
Thanks Eruanna, that did the trick

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;
}
User avatar
Rachael
Developer
Developer
Posts: 3646
Joined: Sat May 13, 2006 10:30

Re: Is there a way to make this lightmode in gzdoom?

Post by Rachael »

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.
ibm5155
Posts: 152
Joined: Tue Oct 25, 2011 13:05

Re: Is there a way to make this lightmode in gzdoom?

Post by ibm5155 »

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
ibm5155
Posts: 152
Joined: Tue Oct 25, 2011 13:05

Re: Is there a way to make this lightmode in gzdoom?

Post by ibm5155 »

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);

so, with that code it should the fog distance should be based on the light, so, if the sector bright is 255, you can see everything, but if the sector light is zero, you should see nothing.
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)
dpJudas
Developer
Developer
Posts: 798
Joined: Sat Jul 23, 2016 7:53

Re: Is there a way to make this lightmode in gzdoom?

Post by dpJudas »

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:

Code: Select all

		float newlightlevel = 1.0 - R_DoomLightingEquation(uLightLevel);
		color.rgb *= newlightlevel;
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 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);
}
dpJudas
Developer
Developer
Posts: 798
Joined: Sat Jul 23, 2016 7:53

Re: Is there a way to make this lightmode in gzdoom?

Post by dpJudas »

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);
}
ibm5155
Posts: 152
Joined: Tue Oct 25, 2011 13:05

Re: Is there a way to make this lightmode in gzdoom?

Post by ibm5155 »

just wondering, what the .w value is used for?
dpJudas
Developer
Developer
Posts: 798
Joined: Sat Jul 23, 2016 7:53

Re: Is there a way to make this lightmode in gzdoom?

Post by dpJudas »

It is the depth (Z) value of the pixel/fragment in view/eye space (the camera's point of view).
Locked

Return to “GZDoom”