Darker [Updated 11/13/21]

Post your example zscripts/ACS scripts/etc here.

Darker [Updated 11/13/21]

Postby Hey Doomer » Thu Nov 11, 2021 5:36 am

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 allExpand view
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 allExpand view
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/Screenshot-Doom-20211113-103521.png

With added colors.
https://i.postimg.cc/zDxqwVVm/Screenshot-Doom-20211113-103535.png
https://i.postimg.cc/QxVhfhTF/Screenshot-Doom-20211113-103648.png

Update 11/13/21
Spoiler:
You do not have the required permissions to view the files attached to this post.
Last edited by Hey Doomer on Sat Nov 13, 2021 9:56 am, edited 2 times in total.
Hey Doomer
 
Joined: 25 Sep 2021
Operating System: Windows 11
OS Test Version: No (Using Stable Public Version)
Graphics Processor: ATI/AMD with Vulkan Support

Re: Darker

Postby Plasmazippo » Thu Nov 11, 2021 6:04 am

Nice little experiment. I'll do a test run with it later, if you don't mind.
Plasmazippo
 
Joined: 25 Sep 2021
Operating System: Windows 10 ARM
OS Test Version: No (Using Stable Public Version)
Graphics Processor: ATI/AMD with Vulkan Support

Darker [Updated 11/14/21]

Postby Hey Doomer » Sun Nov 14, 2021 5:08 am

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 allExpand view
   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 allExpand view
   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.
You do not have the required permissions to view the files attached to this post.
Hey Doomer
 
Joined: 25 Sep 2021
Operating System: Windows 11
OS Test Version: No (Using Stable Public Version)
Graphics Processor: ATI/AMD with Vulkan Support


Return to Script Library

Who is online

Users browsing this forum: No registered users and 0 guests