Darker [Updated 11/13/21]

Post your example zscripts/ACS scripts/etc here.
Forum rules
The Projects forums are only for projects. If you are asking questions about a project, either find that project's thread, or start a thread in the General section instead.

Got a cool project idea but nothing else? Put it in the project ideas thread instead!

Projects for any Doom-based engine (especially 3DGE) are perfectly acceptable here too.

Please read the full rules for more details.
Hey Doomer
Posts: 283
Joined: Sat Sep 25, 2021 3:38 am

Darker [Updated 11/13/21]

Post by Hey Doomer »

This is my take on darkening sectors and adding optional color, experimenting with the FindMinSurroundingLight() method. If this "adjacent" light level is lower than the sector, the sector becomes darker based on three levels defined in user cvars. Colors are added according to ceiling and floor textures when light levels are adjusted.

CVar:

Code: Select all

user bool dk_color = true;
user int dk_low = 65;
user int dk_med = 129;
user int dk_hi = 225;
user float dk_step = 1.5;
ZScript:

Code: Select all

class darker_EventHandler : EventHandler
{
	static const string texname[] = 
	{
		"TLITE6_5", // red
		"BLOOD1",
		"BLOOD2",
		"BLOOD3",
		"TLITE6_1", // yellow
		"TLITE6_4",
		"TLITE6_6",
		"NUKAGE1", // green
		"NUKAGE2",
		"NUKAGE2",
		"LAVA1", // orange
		"LAVA2",
		"LAVA3",
		"LAVA4"
	};
	static const string hexcolor[] = 
	{
		"#ff0000", // red
		"#ff0000",
		"#ff0000",
		"#ff0000",
		"#ffff00", // yellow
		"#ffff00",
		"#ffff00",
		"#00ff00", // green
		"#00ff00",
		"#00ff00",
		"#ff8c00", // orange
		"#ff8c00",
		"#ff8c00"
	};

	override
	void WorldLoaded(WorldEvent e)
	{
		int FLOOR = 0;
		int CEILING = 1;
		TexMan texture;

		int dk_low =  Cvar.FindCvar("dk_low").GetInt();
		int dk_med =  Cvar.FindCvar("dk_med").GetInt();
		int dk_hi =  Cvar.FindCvar("dk_hi").GetInt();
		double dk_step = Cvar.FindCvar("dk_step").GetFloat();

		Array<int> darker;

		// fill darker array
		for(int i = 0; i < Level.Sectors.Size(); i++)
		{
			int lightlevel = Level.Sectors[i].lightlevel;
			int minadjacent = Level.Sectors[i].FindMinSurroundingLight(dk_hi);
			int lightstep = lightlevel < dk_low ? 32 : lightlevel < dk_med ? 16 : lightlevel < dk_hi ? 8 : 0;
			int newlightlevel = minadjacent < lightlevel ? lightlevel - (lightstep * dk_step) : lightlevel - lightstep;

			darker.Push(newlightlevel);
		}
		// apply light levels and colors
		for(int i = 0; i < Level.Sectors.Size(); i++)
		{
			Level.Sectors[i].SetLightLevel(darker[i]);

			if (Cvar.FindCVar("dk_color").GetBool())
			{
				textureid floorid = Level.Sectors[i].GetTexture(FLOOR);
				textureid ceilingid = Level.Sectors[i].GetTexture(CEILING);
				string text_floor = texture.GetName(floorid);
				string text_ceiling = texture.GetName(ceilingid);

				for (int ii = 0; ii < texname.Size(); ii++)
				{
					if (text_floor == texname[ii] || text_ceiling == texname[ii])
					{
						Level.Sectors[i].SetColor(hexcolor[ii]);
						break;
					}
				}
			}
		}
	}
}
So this loops twice through Sectors. The first time the darker array is filled - we don't want to do this while changing light levels - and the second pass applies the new light levels. Colors are set in that loop.

While structures can be defined, they can't be used as a dynamic array type that I can see, hence clunky dual arrays. This also crudely subtracts light. At this stage there's nothing fancy about it. I'm not competing with the excellent DarkDoomZ. I just wondered, What if the dark got darker? without completely changing the feel of a level. It's possible to add fog e.g. green fog for nukage, and I believe to add color based on sidedef textures. Still pondering.

Update 11/12/21:
Spoiler:
Screenshots:

The dark gets darker.
https://i.postimg.cc/nrSZnw6V/Screensho ... 103521.png

With added colors.
https://i.postimg.cc/zDxqwVVm/Screensho ... 103535.png
https://i.postimg.cc/QxVhfhTF/Screensho ... 103648.png

Update 11/13/21
Spoiler:
Last edited by Hey Doomer on Sat Nov 13, 2021 9:56 am, edited 2 times in total.
Plasmazippo
Posts: 115
Joined: Sat Sep 25, 2021 11:55 am
Graphics Processor: ATI/AMD with Vulkan/Metal Support

Re: Darker

Post by Plasmazippo »

Nice little experiment. I'll do a test run with it later, if you don't mind.
Hey Doomer
Posts: 283
Joined: Sat Sep 25, 2021 3:38 am

Darker [Updated 11/14/21]

Post by Hey Doomer »

Well, this is getting messier as it progresses. Yep.

I've divided the structures into flatcolor and sidecolor, because the lighting options seem somewhat different. Many other small changes and optimizations.

Code: Select all

	struct flatcolor
	{
		textureid texid;
		color texcolor;
		int desat;
		color fade;
		int dens;
		int glow_floor;
		int glow_ceiling;
	}
	struct sidecolor
	{
		textureid texid;
		color texcolor;
		int desat;
		int light;
	}
I've also added an options menu and an additional cvar called dk_strength that determines the step multiplier. Nothing fancy, since it all amounts to subtracting sector light in one way or another. Here are the related functions:

Code: Select all

	int lightstep(int lightlevel)
	{
		int dk_low =  Cvar.FindCvar("dk_low").GetInt();
		int dk_med =  Cvar.FindCvar("dk_med").GetInt();
		int dk_hi =  Cvar.FindCvar("dk_hi").GetInt();
		int dk_strength =  Cvar.FindCvar("dk_strength").GetInt();
		return lightlevel - lightlevel < dk_low ? dk_strength * 4 : lightlevel < dk_med ? dk_strength * 2 : lightlevel < dk_hi ? dk_strength : 0;
	}
	int newlightlevel(int minadjacent, int lightlevel)
	{
		double dk_step = Cvar.FindCvar("dk_step").GetFloat();
		return minadjacent < lightlevel ? lightlevel - (lightstep(lightlevel) * dk_step) : lightlevel - lightstep(lightlevel);
	}
Lightlevel is adjusted depending on three thresholds (set in Options) and multiplied by a strength variable. Crude (it's gotta be a broad brush) but effective.

I've added other stuff I've been playing around with, such as SetPlaneLight (to make ceilings gloomier, since light tends to fade into the distance), SetGlowColor for floor and/or ceiling, and set the light of a sidedef regardless of sector lighting. Colors are not combined, and it's pretty much first come first serve. If sector coloring has already been changed it will be changed again if a different sidedef in the array is found, in other words. Much depends on a level author's choices.

Finally, I've added a number of textures with testing preferences for the most part. New colors etc. can be added in the LoadColors function with AddFlatColor or AddSideColor, giving one the ability to change a sector light level, desaturation level (make outside areas washed out), color, fog color, fog density, etc. depending. I've played with this a little, and I like it so far. Frankly I hadn't realized that so much is possible with venerable sector lighting and without the hit of dynamic lights. It would be nice to have an option for fuzzy blending between sectors.

Return to “Script Library”