Commit Graph

119 Commits

Author SHA1 Message Date
Eric Wasylishen de90fc8613 New per-light dirtmapping 2015-01-30 22:58:41 -07:00
Eric Wasylishen 172c81a556 Merge branch 'dirt5' into testbuild 2015-01-21 13:56:14 -07:00
Eric Wasylishen 33fe708dd7 trace.c: fix bug in determining hitpoint->point 2015-01-21 13:38:39 -07:00
Eric Wasylishen a6e8cfdf1a Undo part of cc36d8e that flipped the signs of ON_EPSILON for one of the checks in the TraceLine 2015-01-21 13:36:55 -07:00
Eric Wasylishen ca32a8ffe4 WIP 0-1 scaling 2015-01-19 00:13:20 -07:00
Eric Wasylishen fc5de76f8f correct comment 2015-01-16 15:00:14 -07:00
Eric Wasylishen df06f00788 fix whitespace 2015-01-16 14:58:33 -07:00
Eric Wasylishen 024ea7083d Dirt support 2015-01-14 01:24:22 -07:00
Eric Wasylishen 4df394f9fe light: Increase precision of lightmap extents calculations
This bug is a counterpart to this bug in quakespasm:
   https://sourceforge.net/p/quakespasm/patches/15/

If the precision of the calculation in WorldToTexCoord done by ‘light’
is significantly different than the precision of the same calculation
in the engine, you can get corrupted lightmaps. The problem affects
light when it’s built as something other than vanilla 32-bit
x86. (e.g. x86_64 on a mac).

Signed-off-by: Kevin Shanahan <kmshanah@disenchant.net>
2014-06-30 12:58:30 +09:30
Kevin Shanahan d68748d1d8 light: fix minlight clamping for coloured lights
Colours need to be scaled correctly by the light intensity.
Thanks to Mechtech for reporting this issue.

Reported-by: Paul R <automan1001@yahoo.com>
Signed-off-by: Kevin Shanahan <kmshanah@disenchant.net>
2014-02-15 18:56:44 +10:30
Kevin Shanahan 4b1e3aec1a light, vis, bsputil, bspinfo: Add BSP2 support
Add BSP2 support to the remaining utils.  Since these share the common
bspfile.[ch] files, it was more effort than is justifiable to break this
into multiple staged patches - so you just get this disgustingly big
commit instead.  Here is basically what was done:

 * Modify the bspdata_t struct with a union of the two bsp formats
 * Modify the tools to use bsp2_t for all internal processing
 * Split out the byte swapping routines for the different bsp data types
 * Add simple (although verbose) code to convert bsp29 <-> bsp2

Hundreds of lines added to bspfile.c, but mostly trivial stuff.  The tools
internally had little modification except to substitute the bsp2 type
names.

Signed-off-by: Kevin Shanahan <kmshanah@disenchant.net>
2013-09-25 15:18:50 +09:30
Kevin Shanahan e970bea8c7 common: save the bsp version in the bspdata struct
Adjust the Load and Write API functions as appropriate.

Signed-off-by: Kevin Shanahan <kmshanah@disenchant.net>
2013-08-22 13:25:47 +09:30
Kevin Shanahan 89abf25218 common: convert all tools to instanced bsp data
Transition all tools to access the BSP data via the bspdata struct instead
of the shared globals.  Remove the compatibility code from bspfile which
copied the global values to/from the instanced bspdata struct.

Mostly the changes just involved passing along the bspdata struct to the
various functions which needed to reference the data.  TraceLine and
MakeTNodes in light got some extra changes so that we cache the node
dplane pointer and remove the need to pass the bspdata struct to every
trace operation!

Signed-off-by: Kevin Shanahan <kmshanah@disenchant.net>
2013-08-22 11:01:08 +09:30
Kevin Shanahan d0617760f5 common: add the ability to pass an arg to spawned threads
Signed-off-by: Kevin Shanahan <kmshanah@disenchant.net>
2013-08-20 19:27:40 +09:30
Kevin Shanahan 6ddb109dde light: convert WriteLitFile to use the bspdata struct
Avoids reference to global LightDataSize.  Need to move writing the lit
file above the call to WriteBSPFile, since that will do the byte swapping.

Signed-off-by: Kevin Shanahan <kmshanah@disenchant.net>
2013-08-20 15:23:04 +09:30
Kevin Shanahan 51419621ec common: add the bsp2/bsp29 data types
Rename the default bsp29 data types and add the bsp2 data types to
the common bspfile.h.  Propogate the bsp29 names into the other tools as
simple renames for now.

Signed-off-by: Kevin Shanahan <kmshanah@disenchant.net>
2013-08-20 13:25:16 +09:30
Kevin Shanahan 1612d60a5f light: keep debug helper for dumping face info
Used this to help with debugging, but may as well keep it around for
future debugging rather than implement it all over again next time.

Signed-off-by: Kevin Shanahan <kmshanah@disenchant.net>
2013-08-18 16:52:19 +09:30
Kevin Shanahan 23591535b4 light: show face area for bad texture axis error
Often these errors are caused by super small faces on brushes, show the
area of the offending face to make it more obvious if that is the case.
Kind of lost in the diff, but moved the TriArea, etc. functions up and
added FaceArea() and then augmented the error message.

Signed-off-by: Kevin Shanahan <kmshanah@disenchant.net>
2013-08-03 16:47:15 +09:30
Kevin Shanahan c94414f288 light: allocate one extra lightmap to simplify handling overflow
Rather than allocating the overflow map within each function and
having to handle it as a special case in each, we always allocate the
extra lightmap in the base LightFace function and use common helper
functions to handle allocation and warning on overflow.

We lose a tiny bit of debugging info here about the specific light
that made the surface overflow MAXLIGHTSTYLES, but that never gave us
all the sources, only the last one encountered.

Signed-off-by: Kevin Shanahan <kmshanah@disenchant.net>
2013-07-10 13:47:58 +09:30
Kevin Shanahan 35bf3f4232 light: factor out adding and clamping of light samples
Simple functions, but just helps to tidy up the bodies of the other
LightFace functions and makes sure we're handling light & colours
consistently across each (we weren't in the case of coloured local
minlights, previously).

Signed-off-by: Kevin Shanahan <kmshanah@disenchant.net>
2013-07-08 15:42:50 +09:30
Kevin Shanahan e09c1f8e2a light: rename FixMinLight -> LightFace_Min
Move away from the "Fix" naming ~ it's not a fix, we're applying the
minimum lighting values as requested.

Signed-off-by: Kevin Shanahan <kmshanah@disenchant.net>
2013-07-08 13:30:38 +09:30
Kevin Shanahan 23f8f1a35e light: unify allocation of new face light styles
Factor out the allocation of new light styles - slightly increases the
code size, but we get two benefits; first is that we now don't
allocate the style 0 lightmap unless we actually need it; second, we
get warnings if sunlight or minlight is unable to be applied due to
lack of a style 0 lightmap.

Signed-off-by: Kevin Shanahan <kmshanah@disenchant.net>
2013-07-04 14:29:47 +09:30
Kevin Shanahan f498ed5ec3 light: pass the sun direction vector into LightFace_Sky
Signed-off-by: Kevin Shanahan <kmshanah@disenchant.net>
2013-07-03 16:32:03 +09:30
Kevin Shanahan ca78568cae light: rename SkyLightFace -> LightFace_Sky
Signed-off-by: Kevin Shanahan <kmshanah@disenchant.net>
2013-07-03 14:55:56 +09:30
Kevin Shanahan 7abfeb35da light: rename SingleLightFace -> LightFace_Entity
Signed-off-by: Kevin Shanahan <kmshanah@disenchant.net>
2013-07-03 14:54:21 +09:30
Kevin Shanahan 12e24085c1 light: always calculate color values for light samples
Simplify the code by removing the if (colored) conditionals from the
code path.  CPU cost is insignificant compared to tracing the rays.
As before, only write the lit file if colored lights are detected or
the use explicity requests it.

Signed-off-by: Kevin Shanahan <kmshanah@disenchant.net>
2013-07-03 13:03:27 +09:30
Kevin Shanahan c3bf54e494 common: add printf attribute to Error() declaration in cmdlib.h
Fix a number of warnings now generated as a result.

Signed-off-by: Kevin Shanahan <kmshanah@disenchant.net>
2013-04-23 14:39:44 +09:30
Kevin Shanahan 5082e3ffaa light: reduce "no model has face" to a warning
Since the newskip.exe tool leaves the faces in the bsp but removes
references, we will just skip over lighting such faces.

Signed-off-by: Kevin Shanahan <kmshanah@disenchant.net>
2013-04-22 13:11:22 +09:30
Kevin Shanahan d14793f7ab common: make LoadBSPFile take a bspdata struct
No longer update the globals in this function - make the callers do it
instead.

bspinfo no longer refers to the globals at all.

Signed-off-by: Kevin Shanahan <kmshanah@disenchant.net>
2013-04-20 16:51:45 +09:30
Kevin Shanahan 35024bfa7d common: make dtexdata a union
Just having one base pointer was kind of annoying because you have to cast
to get to the lump offsets, then cast to byte * to find the miptex, etc.
Now we can access the same pointer using the correct types in each case.

Signed-off-by: Kevin Shanahan <kmshanah@disenchant.net>
2013-04-20 16:34:30 +09:30
Kevin Shanahan 37a3a98eff common: make WriteBSPFile take a bspdata struct as input
Signed-off-by: Kevin Shanahan <kmshanah@disenchant.net>
2013-04-20 15:52:31 +09:30
Kevin Shanahan 022b927d79 trivial: fix typo in error message
Signed-off-by: Kevin Shanahan <kmshanah@disenchant.net>
2013-04-19 15:08:55 +09:30
Kevin Shanahan 4275149cee light: improve "bad surface extents" error info
Signed-off-by: Kevin Shanahan <kmshanah@disenchant.net>
2013-04-19 14:59:35 +09:30
Kevin Shanahan f20033fdd7 light: dynamically allocate entities and entstring
Removes the MAX_MAP_ENTITIES and MAX_MAP_ENTSTRING limitations by
counting how much space we will need before parsing/writing.

Now that I look at it, I'm not sure why we should even be re-writing
the entity string in the new bsp file, but I'll leave that behaviour
alone... for now.

Signed-off-by: Kevin Shanahan <kmshanah@disenchant.net>
2013-04-18 09:45:52 +09:30
Kevin Shanahan c193c18d5b make -gate affect linear falloff lights as well
Signed-off-by: Kevin Shanahan <kmshanah@disenchant.net>
2013-04-06 13:25:11 +10:30
Kevin Shanahan ee2dc38f71 light: make command line set sun anglescale as well
Signed-off-by: Kevin Shanahan <kmshanah@disenchant.net>
2013-04-06 08:35:38 +10:30
Kevin Shanahan 4625245b09 light: implement the -addmin command line parameter
Makes minlight additive rather than just bringing low levels up to the
minimum.  Not entirely identical to the bjp implementation as it seems to
treat local minlights in some strange ways, but in most cases the
behaviour should be identical.

Added missing help text for -anglescale|-anglesense parameters too.

Signed-off-by: Kevin Shanahan <kmshanah@disenchant.net>
2013-04-04 15:55:58 +10:30
Kevin Shanahan b4ff9663cc build: add ability to compile for WIN64 using MinGW64
Fix a few minor int<->pointer size warnings.

Signed-off-by: Kevin Shanahan <kmshanah@disenchant.net>
2013-03-15 21:49:16 +10:30
Kevin Shanahan 636a94f260 light: implemented _anglescale key (AKA "_angelsense")
Signed-off-by: Kevin Shanahan <kmshanah@disenchant.net>
2013-03-15 21:27:14 +10:30
Kevin Shanahan 4abc7d31b7 light: remove the old -compress option
Signed-off-by: Kevin Shanahan <kmshanah@disenchant.net>
2013-03-15 20:43:12 +10:30
Kevin Shanahan cc8477c6d9 light: implement -soft command line option
Add the -soft command line option which implements post-processing on
the lightmap surface to blend adjacent samples together to smooth out
hard shadow lines.

Signed-off-by: Kevin Shanahan <kmshanah@disenchant.net>
2013-03-14 11:28:22 +10:30
Kevin Shanahan 31484a8bcd light: remove comment about removing texmins, etc. from surfinfo_t
A relatively small amount of state to keep, just leave it there rather
than inventing any more types to pass around. Now that lightmap_t,
surfinfo_t & texorg_t are separate, I'm less concerned.

Signed-off-by: Kevin Shanahan <kmshanah@disenchant.net>
2013-03-13 11:59:48 +10:30
Kevin Shanahan cc36d8eadc light: rewrite light tracing function and update callers
Substantial changes to TestLineOrSky which now becomes TraceLine to
more conveniently trace lines through the BSP and, terminate the trace
on specific contents and return information about the termination
point.

TraceLine also more correcly handles the cases where points are close
enough to the node planes to be considered "on-node" to ensure we get
a good intersection point back, when requested.

Finally, the algorithm for making the small adjustments to surface
points in CalcPoints has been changed so if the surface point can't
see the midpoint, we find the obscuring surface and move the surface
point just above that. Seems to work better and eliminates some (but
not quite all - midpoint is still not quite the ideal point to use)
random black spots.

Signed-off-by: Kevin Shanahan <kmshanah@disenchant.net>
2013-03-12 16:40:16 +10:30
Kevin Shanahan 359ddfa41e light: remove nominlimit option and negative color value support
"nominlimit" is a more sensible default - people expect negative
lights to be able to subtract from minlight. The negative colors never
really worked properly and there's not really any worthwhile use for
the (that I know of).

Hopefully nobody will be too upset by these two changes to the old
behaviour.

Signed-off-by: Kevin Shanahan <kmshanah@disenchant.net>
2013-03-10 20:24:19 +10:30
Kevin Shanahan e8d640f88f light: use lightsample_t for minlight and sunlight
Signed-off-by: Kevin Shanahan <kmshanah@disenchant.net>
2013-03-10 18:42:35 +10:30
Kevin Shanahan f82562f9e4 light: use lightsample_t for entity light values
Signed-off-by: Kevin Shanahan <kmshanah@disenchant.net>
2013-03-10 18:28:00 +10:30
Kevin Shanahan d57e7d50fd light: use lightsample_t for modelinfo->minlight
Signed-off-by: Kevin Shanahan <kmshanah@disenchant.net>
2013-03-10 17:17:42 +10:30
Kevin Shanahan 46277eec41 light: fix -nominlimit option causing extra bright lighting
This option has been broken for a while, because we only dealt with
positive vs. negative colours and didn't properly handle the light
intensity.

All this messing around to try and correctly handle negative colors
seems just stupid. I might have to remove support for that in
future... is there really any good use for it?

Signed-off-by: Kevin Shanahan <kmshanah@disenchant.net>
2013-03-10 17:07:14 +10:30
Kevin Shanahan f2395a3dd3 light: re-arrange lightdata_t structure into array of lightmap_t
More messing with data structures. Now a single sample has a
brightness and colour component and a lightmap structure captures all
the non-surface lightmap data.

The pointer arithmetic for iterating over the supersamples in
WriteLightmaps is perhaps a little silly, but it works well enough. It
might be smarter to generate the sample points in a different order
instead. Maybe later.

Signed-off-by: Kevin Shanahan <kmshanah@disenchant.net>
2013-03-10 15:45:06 +10:30
Kevin Shanahan f7e76f16b6 light: factor out writing light data from LightFace
Signed-off-by: Kevin Shanahan <kmshanah@disenchant.net>
2013-03-10 09:37:33 +10:30