Ambient light (dynamic) in FTEQW

Discuss programming topics for the various GPL'd game engine sources.
toneddu2000
Posts: 1395
Joined: Tue Feb 24, 2009 4:39 pm
Location: Italy

Ambient light (dynamic) in FTEQW

Post by toneddu2000 »

There's a way to create a dynamic ambient light in FTEQW? For ambient light I mean an overall non-specular light that could or couldn't (better couldn't) project shadows but that gives a subtle (or not so subtle, it depends on how much you increase it)illumination, that, combined with point lights, gives a nice result. Because, to simulate this effect, I'm forced to use many lights (10 or so) and fte doesn't seem to like them (framerate drops from 200/250 frames to 40/60 frames per second).
I don't want to use lightmaps but only dynamic lights.

My workflow is (I don't know if it's the correct one) to create lights in NetRadiant and build BSP + VIS passes (no light pass) and to open map in FTEQW and dynamics lights are already there because r_editlights_import_diffuse and speculare set to 1

r_editlights_import_ambient set to 1 with just one light doesn't give a nice result because point light is directional and, it floods (as it should) the area where it is but leaves black the areas where radius falloffs.

cvar ambient_level and ambient_fade seem to be ambient sound cvars

Questions to Spike:
1) I saw in fte src that there's a cvar named r_ambient but I tried to digit it but it doesn't exist
2) Any plan to add dynamic global illumination in FTEQW? That would be a GREAT addition! :D
3) There's a way to exclude some dynamic point light to project specular light (project only diffuse light)?

The ideal method would be (imho) to create a group entity in NetRadiant that covers the entire area where I need the area ambient light (in my case, the entire map) and, in quakec, to set the ambient light via pflags, but WITHOUT radius. COuld it be feasible?

Thanks guys
Meadow Fun!! - my first commercial game, made with FTEQW game engine
frag.machine
Posts: 2126
Joined: Sat Nov 25, 2006 1:49 pm

Re: Ambient light (dynamic) in FTEQW

Post by frag.machine »

toneddu2000 wrote:My workflow is (I don't know if it's the correct one) to create lights in NetRadiant and build BSP + VIS passes (no light pass)
What you want is a minimal light level that (AFAIK) only can be achieved running LIGHT with the -minlight value set.
I know FrikaC made a cgi-bin version of the quakec interpreter once and wrote part of his website in QuakeC :) (LordHavoc)
Spike
Posts: 2914
Joined: Fri Nov 05, 2004 3:12 am
Location: UK
Contact:

Re: Ambient light (dynamic) in FTEQW

Post by Spike »

csaddon's light editor provides separate ambient/diffuse/specular scalers.

if you actually care about performance, you would set r_shadow_realtime_world to 1 and then have your rtlights be additive to that.
then you can use whatever ugly minlight settings you want without it exhibiting bumpmaps from the other side of the map. it'll be ugly, of course.
toneddu2000
Posts: 1395
Joined: Tue Feb 24, 2009 4:39 pm
Location: Italy

Re: Ambient light (dynamic) in FTEQW

Post by toneddu2000 »

Thanks guys for your replies

@frag.machine: thanks, I'll try that even if I decided not to use q3map2 -light command. I'm start thinking that my crusade against using lightmaps in FTEQW it's useless. Probably lightmaps + 2/3 rtlights is the only way to lit a q3 map without playing with 13fps... :(
I saw that generated lightmaps are 128x128. There is at least a method to increase single lightmap resolution?

@Spike:thanks but now I more confused that before! :)
Because now I think I confused rtlights with radiant editor lights.

I thought that, through r_shadow_import* commands I just converted static editor lights into rtlights.
r_shadow_realtime_world is set to 1 but, frankly, now I cannot be sure if it's what I was thinking for! :D I thougth that was the method to set all the lights in the world to be dynamic
This is my configuration

Code: Select all

r_shadow_realtime_world_lightmaps 0
r_shadow_realtime_dlight_shadows 1
r_shadow_realtime_dlight 1
r_shadow_realtime_world_shadows 1
r_shadow_realtime_world 1
Please Spike, can you please tell me where I can find a detailed explanation of all these lights + shadows commands? Because it's really frustrating to toy with commands if you don't know what they do! :D
Thanks again
Meadow Fun!! - my first commercial game, made with FTEQW game engine
Spike
Posts: 2914
Joined: Fri Nov 05, 2004 3:12 am
Location: UK
Contact:

Re: Ambient light (dynamic) in FTEQW

Post by Spike »

if you're making a TC:
r_editlights_import_radius 0
r_shadow_realtime_world_lightmaps 1
then your rtlights are additive.

the great thing about lightmaps is that you can use radiance algorithms, with backscatter and all sorts of other refinements.
rtlights on the other hand are simple spheres of light. they're just a realtime equivelent of vanilla quake. Sure they contribute to bumpmaps and stuff, but the overall light levels are not fantastically different from quake.
they cannot bounce around corners.
if you enable deluxemapping (in both engine and map compiler), you should be able to attain nicer looking lighting without needing to resort to the expense of rtlights.

the problem with importing lights from your map editor is that the rules for those lights are identical to both and thus you just get doubled light rather than anything more useful.

ideally you would use spotlights in preference to omni-lights, whereever practical. regular 'omni' lights need to generate 6 different shadowmaps every single frame, while spotlights need only 1.
alternatively, use shadowless rtlights, as these don't need to cast any shadows at all.

make sure your glsl uses the SKELETAL permutation. if your glsl does not provide this, your skeletal models will be animated on the cpu.
don't underestimate the cost of offsetmapping. :(

you can write some csqc to read the entity lump clientside and emit some static rtlights with the properties you want in the same way that csaddon does, just do it without the whole userinput thing. parsing can be a pain though.
this would allow you to edit both sets of lights from a single place. or you could just use csaddon.
toneddu2000
Posts: 1395
Joined: Tue Feb 24, 2009 4:39 pm
Location: Italy

Re: Ambient light (dynamic) in FTEQW

Post by toneddu2000 »

thanks Spike,
bur r_shadow_realtime_world must be set to 0 or 1?
make sure your glsl uses the SKELETAL permutation. if your glsl does not provide this, your skeletal models will be animated on the cpu.
don't underestimate the cost of offsetmapping. :(
Good to know it, thanks, I'll copy your glsl SKELETAL permutation into mine glsl files
rtlights on the other hand are simple spheres of light. they're just a realtime equivelent of vanilla quake. Sure they contribute to bumpmaps and stuff, but the overall light levels are not fantastically different from quake.
they cannot bounce around corners.
well, without bouncing, I've quite exhausted my enthusiasm about real time lights! :D The fact you didn't reply to my "Any plan to add dynamic global illumination in FTEQW? " question make me think you'll never think about it! :D
alternatively, use shadowless rtlights, as these don't need to cast any shadows at all.
Yeah, but players and entities wouldn't use soft dynamic shadows

csaddon is great, only problem, moving light with m button is impossible. It would need a tripod axis gizmo instead. I'll try to tweak it if I can and I'll post here any possible upgrade. Spot light thing it's supercool, though
Meadow Fun!! - my first commercial game, made with FTEQW game engine
toneddu2000
Posts: 1395
Joined: Tue Feb 24, 2009 4:39 pm
Location: Italy

Re: Ambient light (dynamic) in FTEQW

Post by toneddu2000 »

WARNING! (Possibly) FTE BUG!
if you set

Code: Select all

r_editlights_import_radius 0
and, you have a model with a shader that has the block

Code: Select all

{
		map $lightmap
		blendFunc GL_DST_COLOR GL_ZERO
		rgbGen identity
}
FTE will crash without no explanation, no matter if there are lights in the map or not!!
So, either delete map $lightmap block from shader or set r_editlights_import_radius to 1

This literally drove me insane!! :lol:
Last edited by toneddu2000 on Fri Jun 19, 2015 2:22 pm, edited 1 time in total.
Meadow Fun!! - my first commercial game, made with FTEQW game engine
toneddu2000
Posts: 1395
Joined: Tue Feb 24, 2009 4:39 pm
Location: Italy

Re: Ambient light (dynamic) in FTEQW

Post by toneddu2000 »

I forgot a thing. To crash, FTE has to use an entity, which its model has the shader said in the earlier post, PLUS the field .drawmask set. Like

Code: Select all

myentity.drawmask = MASK_NORMAL;
or

Code: Select all

myentity.drawmask = MASK_ENGINE;
Otherwise it won't crash. But 99% of the times you'll use the .drawmask field because without it, predraw function isn't called.
Meadow Fun!! - my first commercial game, made with FTEQW game engine
toneddu2000
Posts: 1395
Joined: Tue Feb 24, 2009 4:39 pm
Location: Italy

Re: Ambient light (dynamic) in FTEQW

Post by toneddu2000 »

from fteqw version 4808 and up, at least on Windows (didn't try on Linux, sorry), if you load a map without any light, a red warning appears

Code: Select all

No lights detected in map. Disabling realtime lights.
And then FTEQW crashes. With 4807 and down, this doesn't happen.
It's not a big deal, because you can just add a light and add the others through cs addon, but, it's kinda weird it crashes
Meadow Fun!! - my first commercial game, made with FTEQW game engine
Spike
Posts: 2914
Joined: Fri Nov 05, 2004 3:12 am
Location: UK
Contact:

Re: Ambient light (dynamic) in FTEQW

Post by Spike »

if you want to provide useful crash reports, reproduce the crash with a debug build and paste the first few lines of the stack trace that it spits out when it crashes (just make sure that its the current build at the time, or do the addr2line lookups yourself).

'no lights detected in map' was added to work around various TF maps becoming pitch black when the lighting tool stripped light entities.
it does not in fact disable rtlights (there arn't any loaded anyway), but merely sets r_shadow_realtime_world_lightmaps back to 1 until the next map change, thereby preventing the blackness without preventing mods from creating lights (either dynamic ones, or editing them with csaddon, or something more advanced).

regarding your $lightmaps on surfaces that don't have lightmap info... yeah, don't do that. it doesn't make sense.
Spike
Posts: 2914
Joined: Fri Nov 05, 2004 3:12 am
Location: UK
Contact:

Re: Ambient light (dynamic) in FTEQW

Post by Spike »

toneddu2000 wrote:bur r_shadow_realtime_world must be set to 0 or 1?
should normally be 1 for static/world lights (note that you can have static 'dynamic' lights too, but these should be rare. really it depends how you want to deal with various settings).
The fact you didn't reply to my "Any plan to add dynamic global illumination in FTEQW? " question make me think you'll never think about it! :D
its tempting, but I don't know of any decent algorithm.
the best I can come up with is a few 3d textures and far far too many tracelines, but this probably won't do colour reflections convincingly enough.
Yeah, but players and entities wouldn't use soft dynamic shadows
so why bother with realtime lights in the first place? just use deluxemaps.
csaddon is great, only problem, moving light with m button is impossible. It would need a tripod axis gizmo instead. I'll try to tweak it if I can and I'll post here any possible upgrade. Spot light thing it's supercool, though
you can use the [ and ] keys to push it to/away from the surface normal underneath the mouse. this makes it easy to push it away/towards any given surface that you can see (but typically the surface you just moved it near). you are correct that the m key will not maintain the same distance from the surface.
toneddu2000
Posts: 1395
Joined: Tue Feb 24, 2009 4:39 pm
Location: Italy

Re: Ambient light (dynamic) in FTEQW

Post by toneddu2000 »

4808 crash
Image

4911 (latest release) crash
Image
Spike wrote:should normally be 1 for static/world lights (note that you can have static 'dynamic' lights too, but these should be rare. really it depends how you want to deal with various settings).
In this map(that is my first map ever, so pardon my ignorance) I wanted that lights cast dynamic soft shadows on players and surfaces, so that, when player is positioned underneath the light, light projects on him/her (and on the ground underneath) a nice soft shadow (plus the shadows on player torso when light intesect player's arms, which it's a nice effect). I don't know if these are dynamic / static lights. I don't know the nomenclature, sorry. So, I know, it's my mistake. I'd like to learn a bit more, but I couldn't find a documentation
Spike wrote:its tempting, but I don't know of any decent algorithm.
Let be tempted, let be tempted! :D
Probably, from the top of my ignorance, the Voxel Cone Tracing algorithm seems the more used today. Iirc also Unreal engine 4 uses this (but I'm not 100% sure), because it gives nice results with fair performance compromise, but probably it's a nightmare to implement it in a Quake-based engine, no idea.
you can use the [ and ] keys to push it to/away from the surface normal underneath the mouse. this makes it easy to push it away/towards any given surface that you can see (but typically the surface you just moved it near). you are correct that the m key will not maintain the same distance from the surface.
I tried, but it seems that light becomes spot and "rotates", instead of translating. Plus, s_light.spr doens't remain aligned to shadow, when shadow moves, so it becomes difficult to follow the light
so why bother with realtime lights in the first place? just use deluxemaps.
No, I explained myself bad, I meant that I wanted players and entities do cast shadows. That's why I rejected static global illumination solution immediately.

Let's do a thing: I'll create a SHINY new FTEQW installation and I'll try deluxemapping and realtime lights mixed. Because, right now, lightmaps aren't visible on my FTEQW installation.
I build the map with this config

Code: Select all

<build name="Test: -bsp, -vis and -light, NO collisions meshes">
<command>[q3map2_32bit] -meta -v "[MapFile]"</command>
<command>[q3map2_32bit] -vis -saveprt "[MapFile]"</command>
<command>[q3map2_32bit] -light -fast -patchshadows -samples 3 -bounce 8 -gamma 2 -compensate 4 -dirty -v "[MapFile]"</command>
</build>
It creates lightmaps folder with .tgas inside but they're not shown during game and I tried every r_shadow and r_editlights command combination :?:

#EDIT:
Spike wrote:regarding your $lightmaps on surfaces that don't have lightmap info... yeah, don't do that. it doesn't make sense.
But, if I discard $lightmap entry on shader, model is not affected by rtlights too! :shock:
Meadow Fun!! - my first commercial game, made with FTEQW game engine
toneddu2000
Posts: 1395
Joined: Tue Feb 24, 2009 4:39 pm
Location: Italy

Re: Ambient light (dynamic) in FTEQW

Post by toneddu2000 »

ok, let's start from the beginning.
The crash appears if
a) the entity has a drawflag in CSQC.
b) the entity has a shader like this

Code: Select all

textures/characters/simplemodel
{
	bemode rtlight spike_rtlight
	diffusemap textures/characters/simplemodel.tga
	normalmap textures/characters/simplemodel_normal.tga
	specularmap textures/characters/simplemodel_spec.tga
	reflectcube textures/cubes/sky
	reflectmask textures/characters/simplemodel_reflect.tga
	{
		map $lightmap
	}
}
And, for spike_rtlight I mean this glsl file Spike adjusted here because I asked, adding cubemaps

the shader needs to edited like this

Code: Select all

textures/characters/simplemodel
{
	program spike_rtlight
	diffusemap textures/characters/simplemodel.tga
	normalmap textures/characters/simplemodel_normal.tga
	specularmap textures/characters/simplemodel_spec.tga
	reflectcube textures/cubes/sky
	reflectmask textures/characters/simplemodel_reflect.tga
}
But, for characters models, now look sh*t. I've really no idea why now it behaves like this! Some days ago this crash never happened! :shock:

Now, I made some tests to understand how FTE displays lights.
To display lightmaps with FTEQW:
  1. Add a light in NetRadiant (or equivalent) but DO NOT add a targetname, set .light and _color field
  2. Build with something like this

    Code: Select all

    <build name="Final: '-light + -bounce 8 -dirtscale 2' (Xonotic approved)">
    <command>[q3map2_32bit] -meta -keepLights -v -maxarea -samplesize 8 -mv 1000000 -mi 6000000 "[MapFile]"</command>
    <command>[q3map2_32bit] -vis -saveprt "[MapFile]"</command>
    <command>[q3map2_32bit] -light -lightmapsize 1024 -lightmapsearchpower 4 -deluxe -patchshadows -randomsamples -samples 4 -fast -fastbounce -dirty -bouncegrid -fill -bounce 8 -dirtscale 2 "[MapFile]"</command>
    <command>[q3map2_32bit] -minimap "[MapFile]"</command>
    </build>
  3. Launch map in fte. If default.cfg is empty and no other .cfg is present, lightmaps should be visible
To display dynamic lights
  1. Add targetname, in NetRadiant (or equivalent), to entities you want to make dynamic
  2. Rebuild
  3. Add to default.cfg in your fte data folder, these values

    Code: Select all

    r_shadow_realtime_world 1 //start using realtime lights
    r_shadow_realtime_world_lightmaps 1//setting to 0, static lightmapped lights won't be taken in account, setting to 1, dynamic lights and lightmaps will coexist
    
  4. Add this code in ssqc

    Code: Select all

    void light()
    {
    	if (!self.targetname){
    		remove(self);
    		return;
    	}		
    }
    
[*]Launch map in fte. If default.cfg is empty and no other .cfg is present, dynamic lights should be visible

Now, I'm still curios about what r_shadow_realtime_dlight,r_shadow_realtime_dlight_shadow,r_shadow_realtime_dlight_diffuse,r_shadow_realtime_dlight_specular do. I think, probably that a dlight is a light that spawns when a temporary event triggered, like a weapon fires or so. Another question I have is tied to quakec (so maybe it's not the right place it to ask) and it's: but, if I write something like that in ssqc

Code: Select all

void light()
{
	if (!self.targetname){
		remove(self);
		return;
	}
	if(self.targetname == "foo"){
		self.pflags = PFLAGS_FULLDYNAMIC;
		self.light_lev = 400;
		self.think = lightmove;
		self.nextthink = time +2;
		self.color = '0.3 0.1 0.1';
	}
	else if(self.targetname == "bar"){
		self.pflags = PFLAGS_FULLDYNAMIC;
		self.light_lev = 900;
		self.color = '0.1 0.8 0.8';
	}
		
}
Can fte apply 2 different "light styles", recognizing the targetname?
Meadow Fun!! - my first commercial game, made with FTEQW game engine
Spike
Posts: 2914
Joined: Fri Nov 05, 2004 3:12 am
Location: UK
Contact:

Re: Ambient light (dynamic) in FTEQW

Post by Spike »

those stack traces are not from my builds. I don't know what changes you've made.
my tools don't know what changes you've made either.
thus that stack trace is completely useless to me.
you would need to figure out the addresses yourself.

here's a link to debug builds that I can actually get line number info from: http://triptohell.info/moodles/win32/debug/fteglqw.exe

update your csaddon, it got a couple of extra fields (like rotating cubemapped 'static' lights).
you really shouldn't be using FULLDYNAMIC on any entity that your light/q3map2 tool will generate lightmaps for, or that the engine will autogenerate rtlights for. its's just wasteful. also, gamecode should try to avoid having hacks for the targetname, because hacks are bad.
I've heard people complain that -keeplights is broken in q3map2. I don't know the details nor version, just that someone I normally trust claims that it still stripped their lights.
use .style to get a FULLDYNAMIC rtlight to auto-animate according to a lightstyle.
toneddu2000
Posts: 1395
Joined: Tue Feb 24, 2009 4:39 pm
Location: Italy

Re: Ambient light (dynamic) in FTEQW

Post by toneddu2000 »

Spike wrote:those stack traces are not from my builds. I don't know what changes you've made.
my tools don't know what changes you've made either.
thus that stack trace is completely useless to me.
you would need to figure out the addresses yourself.
Huh? I didn't touch engine source! just svn checkout && make gl-dbg FTE_TARGET=win32 -j 8. That's the only change I made! :D

Anyway, this is from your fteglqw.exe downloaded from your posted link:

Code: Select all

Build: Debug Win32 GL: FTE SVN 4914
0x0960903F ()
DrvPresentBuffers   +0x1aac65 (C:\Windows\system32\atioglxx.dll)
DrvPresentBuffers   +0x27320e (C:\Windows\system32\atioglxx.dll)
DrvPresentBuffers   +0x21ff95 (C:\Windows\system32\atioglxx.dll)
DrvPresentBuffers   +0x1b0c01 (C:\Windows\system32\atioglxx.dll)
DrvPresentBuffers   +0x3fb091 (C:\Windows\system32\atioglxx.dll)
0x00437E47 (D:\game\fte\fteskel\fteglqw.exe)
0x0043843A (D:\game\fte\fteskel\fteglqw.exe)
0x0043B70B (D:\game\fte\fteskel\fteglqw.exe)
0x0043C296 (D:\game\fte\fteskel\fteglqw.exe)
0x0043D4DE (D:\game\fte\fteskel\fteglqw.exe)
0x0043D5B0 (D:\game\fte\fteskel\fteglqw.exe)
0x0043E929 (D:\game\fte\fteskel\fteglqw.exe)
0x0042B150 (D:\game\fte\fteskel\fteglqw.exe)
0x00440557 (D:\game\fte\fteskel\fteglqw.exe)
0x004437CD (D:\game\fte\fteskel\fteglqw.exe)
0x0060BC7E (D:\game\fte\fteskel\fteglqw.exe)
0x0071627F (D:\game\fte\fteskel\fteglqw.exe)
0x007243CF (D:\game\fte\fteskel\fteglqw.exe)
0x00724624 (D:\game\fte\fteskel\fteglqw.exe)
0x00616EAA (D:\game\fte\fteskel\fteglqw.exe)
0x00445C11 (D:\game\fte\fteskel\fteglqw.exe)
0x005D1630 (D:\game\fte\fteskel\fteglqw.exe)
0x004CA5A0 (D:\game\fte\fteskel\fteglqw.exe)
0x004CA6AE (D:\game\fte\fteskel\fteglqw.exe)
0x004013EA (D:\game\fte\fteskel\fteglqw.exe)
BaseThreadInitThunk +0x12 (C:\Windows\syswow64\kernel32.dll)
RtlInitializeExceptionChain+0x63 (C:\Windows\SysWOW64\ntdll.dll)
RtlInitializeExceptionChain+0x36 (C:\Windows\SysWOW64\ntdll.dll)
Spike wrote:update your csaddon, it got a couple of extra fields (like rotating cubemapped 'static' lights).
Thanks, I'll try that!
Spike wrote:you really shouldn't be using FULLDYNAMIC on any entity that your light/q3map2 tool will generate lightmaps for, or that the engine will autogenerate rtlights for. its's just wasteful. also, gamecode should try to avoid having hacks for the targetname, because hacks are bad.
Ok, but how can I differentiate one light from another? That's the only thing I didn't understand. I thought targetname was the only method but now I think it's the wrong one
Spike wrote: I've heard people complain that -keeplights is broken in q3map2. I don't know the details nor version, just that someone I normally trust claims that it still stripped their lights.
use .style to get a FULLDYNAMIC rtlight to auto-animate according to a lightstyle.
Thanks for these infos. But .style is not present neither in ssdefs nor in csdefs. How can I retrieve a light style? Trough lightstyle function? Or through dynamiclight_get function?

Thanks again Spike!
Meadow Fun!! - my first commercial game, made with FTEQW game engine
Post Reply