23 Commits
Author SHA1 Message Date
BMagnu 25eebd96de Shadow Overhaul (#7529)
* Extract shadows into own shader and render pass

# Conflicts:
#	code/def_files/data/effects/main-g.sdr

* Consolidate render queue code

* More cleanup

* Fix missing clear of shadow buffer inter frame

* Request capability for viewport layer rendering

* instanced shadows

* Fix issues

* Switch to PCF+PCSS and proper textures for it

* Smooth PCSS toggle

* Fix for windows

* Fix OGL error

* Cleanup of old flag

* Expose shadow smoothness

* Fix missing uniform

* Make number of shadow cascades dynamic

* Progress on cockpit shadow integration

* Wrangle Cockpit and show-ship shadows into correct behaviour

* Cleanup

* make player ship shadow table options more intuitive

* Cleanup

* Only read from correct set of shadow maps, also stretch first main-scene map to 0

* Remove now non-necessary validation

* Make shadow cascade buffer more typesafe and less wasteful

* Don't allocate cockpit cascades if not used

* Cleanup

* Final fixes

* Fix Warnings

* clang tidy

* Fix missing fallback for shader precaching

* That weird FOV multiplier that always ruins your day

* Avoid shadow geometry artifacts by using hardware depth clamping

* Correctly handle shadow cascade overrides with hardcoded length

* GCC9 and its sad state of C++17 support.

* Address Feedback

# Conflicts:
#	code/graphics/shadows.cpp
2026-07-04 16:08:41 +02:00
BMagnuandGoober5000 20c8417e8b Fullneb Revamp (#7352)
* change to new fog system

* Fix fog conversion issues

* remove unused old neb values

* Update scripting API

* temporary old-value round trip

* Rewrite nebula fog with four explicit parameters

Replace the legacy `+Fog Near Mult` / `+Fog Far Mult` model — which
depended on fixed engine constants — with four parameters that map
directly to renderer behavior:

  +Fog 1000m Visibility    fraction of light surviving 1000m of fog
  +Fog Near Distance       meters from camera where fog begins
  +Fog Skybox Clip Distance  max render distance for the skybox in fog
  +Fog Clip Distance       max render distance for the scene in fog

The deferred-lighting fog shader, material system, model renderer,
object sort, and the Lua mission API all consume the new parameters
directly. The legacy `Neb2_fog_near_mult` / `Neb2_fog_far_mult`
globals are removed.

Mission parsing accepts either the legacy keys or the modern keys.
Legacy values are converted to the modern set at parse time, and a
per-mission flag (`Neb2_fog_use_legacy_values`) records which keys to
write back on save. The flag is cleared only when something actually
changes, so opening and OK'ing an unmodified legacy mission preserves
its on-disk format. Saving uses `optional_string_fred` to preserve
user comments through edit cycles.

FRED2 and QtFRED background editors both expose the four parameters
in place of the old multipliers, with friendly labels and tooltips.
Both editors validate input (visibility clamped to [0, 1]; near
distance must be > 0; skybox and scene clip distances may be 0 to
disable fog at that range) and use a snapshot-and-compare at close
time so that a no-op open-then-OK never spuriously rewrites a legacy
mission in the modern format.

FRED2's background dialog is also reorganized so that "Display bg
bitmaps in nebula", "Override nebula fog palette", the RGB row, and
the four fog parameters all sit inside the Nebula group box; the
"Old Nebula" group box is restored below it with its Pattern, Color,
Pitch, Bank, and Heading controls back inside the frame. The dialog
now overrides PreTranslateMessage so that the new fog tooltips —
and the previously broken "Save sun/bitmap angles in correct format"
tooltip — actually fire.

QtFRED's BackgroundEditor.ui adds four QDoubleSpinBox controls in
the existing nebula form layout, with per-field decimals chosen to
avoid scientific notation, and per-field min/max declaring the
validation rules. The QtFRED help page is updated to describe the
new fields.

* fix tooltips

* restore forward-renderer fog

* Clang Tidy

* address feedback

* Refine nebula fog rewrite

- Rename Neb2_fog_use_legacy_values to Neb2_fog_save_legacy_values
  to reflect that the flag governs save format, not runtime
  behavior.
- Decide both the save flag and the legacy-to-modern conversion
  purely from whether the file contains modern fog keys, dropping
  the prior heuristic based on required_fso_version. A mission
  without modern keys (legacy- or retail-format) converts on load
  and saves back in legacy format; missions with modern keys are
  saved as modern.
- Snapshot the four fog values as floats at editor open and use
  fl_equal for the no-change comparison in both FRED2 and QtFRED,
  replacing the FRED2 CString comparison and the QtFRED strict
  inequality.
- Document the on-disk invariant in missionsave: when not saving
  legacy keys, the four modern keys must always be written (never
  gated on "only if non-default"), since the parser uses their
  presence to decide whether to run the conversion on next load.

---------

Co-authored-by: Goober5000 <[email protected]>
2026-05-28 14:43:48 +09:00
BMagnu fb229ccbb1 Fix texture slot 0 incorrectly being considered invalid in a lot of cases (#7106) 2025-11-06 09:34:03 +09:00
BMagnu 9b82daeefc Proper Ambient Light (#6849)
* Remove ambient handling from amin / decal pass

* Add ambient light to deferred pass

* Make decals work and fix double insignia rendering

* Fix decal vertex shader

* render insignias as decals

* Cleanup of old insignia stuff

* Move insignia post-processing to model load

* perform envmap lighting in deferred shader

* Remove Envmapping from main shader

* Fix MSVC warning

* exclude def_files from clang tidy
2025-07-22 00:17:22 +02:00
Birk Magnussen 2a6c14d3b5 Make it properly configurable 2024-02-05 19:22:33 +01:00
Birk Magnussen 46408cce3a Conditionally set shader flags at run or compiletime 2024-02-05 19:22:33 +01:00
The Force 98e20c0979 Fix #5743 2023-10-31 18:07:33 +00:00
Fabian Woltermann 076ad7770b remove main shader compile-time flags (#5055) 2023-02-15 15:20:11 +01:00
EatThePath 8e560a0ba4 More old dead shader override code that isn't hooked to anything anymore. (#4861) 2022-11-22 11:06:51 -05:00
David Gibson 830fed0bdc always set the default gloss uniform since it is now always used. Fixes flickering issue 2022-11-05 11:16:51 -05:00
EatThePath 06fc2c81f9 Shader/Material cleanup pass (#4838)
* Ripping out the gloss override code because it's vestigial

* Remove redundant teammask declaration.

* The NORMAL_ALPHA shader feature appears both useless and unusable.
Consequently, I'm removing it.
2022-11-02 17:19:54 -04:00
Adam Leach fed039fd54 logic error fix - update envMatrix even if there's no specmap (#4699) 2022-09-22 22:00:19 -04:00
BMagnu 5593bd168d Add optional deferred lighting pass for cockpits (#3445)
* Add deferred cockpit lighting

* Put deferred Cockpits behind a flag

* (hopefully) fix bad in-case initializer

* clear non base color buffer in subsequent deferred passes

* Proper deferred Cockpit rendering

* undo whitespace changes
2022-09-17 15:29:35 -04:00
EatThePath 452f554193 Crossing the specular rubicon (#4302)
* Applying directional brightness profile value, disconnected spec flags and made specular light always equal to diffuse light

* Switched over to new command line arguments

* Wire lab up to new lighting controls, and provide backwards-compatible defaults for emissive.

* cleanup unused new function

* make static some functions that can be static

* revise command-line and emissive handling

* handled specular sun depreciation and general removal of specular value handling

* Removed specular light color as a separate value in the uniform buffers.

* cleanup of leftover/post-rebase specular references

* further post-rebase repair of light flags command line and leftover specular

* move techroom/selection/breifing 'room' lights to a common function and
augment lighting setup for current rendering

* fixed some mishandling of lighting modifiers.

* Addressed code clarity and comments from review
2022-09-15 05:47:58 +09:00
BMagnu 1da6f4a6a2 Simplistic Ship Transparency (#3436)
* Basic per-render-model + per-ship tools

* Tidy up settable transparency for standalone use

* Force Alpha Premultiplied on external Alphamult

* Fix sexp description.
2021-10-08 21:49:13 +09:00
asarium 56dc373bb9 Add support for using Vulkan GLSL code with OpenGL
This is an effort to be able to use the same GLSL code for both Vulkan
and OpenGL. This is done by first compiling the Vulkan GLSL code to
SPIR-V and then using a custom tool (which uses SPIRV-Cross) to convert
that back into GLSL 1.50 compatible code.

The required tool will be downloaded by CMake when glslc is found in the
path. This is included in the Vulkan SDK. To avoid having a hard
dependency on this, the generated files are included in the VCS and are
only regenerated when glslc is found on the system.
2020-09-27 12:45:05 +02:00
asarium 5ce6c251ff Add persistent mapping support
Persistent buffer mapping is an OpenGL technique where the contents of a
buffer object are mapped to a persistent pointer instead of having to
map and unmap a buffer every time it is modified.

This decreases the overhead for updating data in a uniform buffer object
which now only consists of a memcpy and a flush call.
2020-01-12 11:59:23 +01:00
Fabian 9e5cd347be Makes slight adjustments to the lighting defaults.
This commit disables emissive lighting on objects by default (as the new HDR process makes it unnecessary) and switches the -no-emissive commandline parameter to -emissive; Setting that parameter will restore the old behaviour. The -no-emissive parameter is retained to avoid user-facing error messages.
In addition, this commit sets the default bloom value to 25.
2019-11-17 13:38:24 +01:00
asarium 357cd76252 Render hardpoint model outlines using geometry shaders
This adds support for rendering models using thick lines (that means
lines wider than 1 pixel) which is required by the hardpoint HUD gauge.
This feature was present before the switch to OpenGL code and had to be
removed since the core profile does not support rendering lines wider
than 1 pixel.

This uses a geometry shader for converting all the triangles from a
model to 3 quads along the triangle lines which are as thick as set by
the model renderer. Geometry shaders are quite slow if they generate a
lot of geometry (and this generates 4 times the usual amount of geometry
in the shader) so it's probably not a very fast rendering operation but
it is only needed once per frame so it shouldn't be too bad.

I also added support for the RenderDoc API since I needed that for
debugging and it might be useful in the future. It will only become
active if RenderDoc is actually attached to the process so in most cases
the new code will do nothing.
2018-06-07 16:44:41 +02:00
asarium 1571caa95e Set team_glow_enabled uniform to proper value
This was missed when converting the model uniforms to a uniform buffer
and caused some issues with team colors. This sets that uniform to the
value it had before the uniform buffer changes.

This fixes #1683.
2018-04-13 10:36:32 +02:00
asarium c463709399 Remove gr_set_fog
Specifying the fog rendering options is now handled by the materials
system and the implementation of gr_set_fog was pretty much empty so I
removed it.
2018-02-24 19:37:39 +01:00
Fabian Woltermann 3b21b2469f A clean, up-to-date patch of the new lab code 2018-02-14 16:19:38 +01:00
asarium c6975fda3c Use uniform buffer blocks for passing uniform data to shaders
This uses UBOs for building a buffer object of uniform data before
using that data to draw objects. This should reduce the CPU overhead by
reducing the amount of glUniform calls required for executing a single
draw call. This is especially useful if rendering is limited by the CPU
which should help performance for people with slower CPUs.

This fixes #910.
2017-09-13 11:54:16 +02:00