* feat(render): the Vulkan renderer keeps the vertex streams of E4D models as they are, 28 bytes a vertex
Stage 3 of the E4D model format. A model loaded from .e4d (modelformat e4d) reaches the Vulkan renderer as its compact
streams: positions (12 B), attributes (QTangent snorm16x4 + uv f32x2, 16 B), user data and indices, without the 48-byte
gfx::basic_vertex in between.
- gfx: gfx::compact_attributes, geometry_bank::create_compact() and GfxRenderer->Insert_Compact(). The default of
Insert_Compact decodes to basic_vertex, so the OpenGL 4.6 and the null renderers get the models as before. The CPU
readers of a chunk (pantograph, bounds, picking, the editor) get basic_vertex made from the streams the first time they
read it; a chunk which is changed (replace, append) turns into basic_vertex first.
- Vulkan: a bank whose chunks are all compact keeps positions, user data, attributes and indices in buffers of their own;
vertex_kind::scene_compact reads them (location 5 the quaternion as R16G16B16A16_SNORM). A program gets a COMPACT_VERTEX
variant the first time a compact chunk is drawn with it, in the background with gfx.vulkan.asyncresources, as the
MODEL_DRAWS one; the variant of the multi draws makes a compact one of its own. Only vertex.vert and cabprobe.vert
decode the normal (compact_frame() in common.glsl); the shaders of shadows, prepass, picking and cube shadows read
position and uv as before.
- Ray tracing: the BLAS of a compact chunk reads the positions with a stride of 12, and the reflections read the normal
and uv from the attributes (RT_FLAG_COMPACT in the record). Not tried with ray tracing on.
- The loader hands the streams of the file to Insert_Compact as they are; the stars keep their colours in the normals
of basic_vertex and go as before.
Measured on Vulkan (self-test, 250 models of the game, runs alternating with legacy): device memory 1.60-1.64 GiB
against 1.89 GiB, GPU time a frame 1.27-1.39 ms against 1.37-1.57 ms, the same frame time and load time, the picture
within 1/255 of the legacy one, no errors of Vulkan in the log. Unit tests 1189/1189; -e4d diff gives the same results
through the new decode. Not built with GCC here.
* refactor(model): the new model format is EU07M (.eu07m), not E4D
E4D read as the next version of E3D, which the format isn't meant to be tied to; EU07M goes with the world format .eu07.
The format isn't released, so nothing reads the old name.
- The extension .eu07m, the magic EU7M (the four bytes of the header), model/eu07m/ with eu07m_*.{h,cpp},
namespace eu07m, docs/eu07m-format.md, tests/unit/test_eu07m.cpp.
- The command line -eu07m convert|dump|validate|diff, TModel3d::LoadFromEU07M, and the key modelformat eu07m|legacy
of eu07.ini (Global.modelformat_eu07m).
- Nothing else changes: the sections, the records and the components are the same, so a converted file needs only its
magic and its extension changed.
Unit tests 1189/1189.
* fix(render): EU07M review of #537: no whole vertices kept for the bounds, the compact variant checked by CI and given up when it fails
- The bounding radius, offset() and MaxY() read the positions of a chunk alone (Positions(), geometry_bank::positions()):
on Vulkan the compact streams are no longer decoded into basic_vertex and kept for the life of the bank as every model
loads, so the host memory of EU07M models stays below that of E3D. What still needs whole vertices (the editor, the
picking, the export) decodes them on first use as before.
- A COMPACT_VERTEX variant which doesn't compile is told once in the log and the banks of EU07M models go back to
basic_vertex (compact_layout_failed()), those built already when they are drawn next, instead of the models being left
out for the session.
- The shader validator compiles the vk14 shaders which have COMPACT_VERTEX with it, alone and with MODEL_DRAWS, as the
renderer makes the variants.
* feat(model): the EU07M model files take the .r3a extension, the switch is modelformat r3a
The model files of the format are named .r3a in place of .eu07m, and eu07.ini selects them with modelformat r3a in place of
modelformat eu07m. The format keeps its name (EU07M), its magic and the -eu07m command line tool. Neither the extension nor
the key has been released, so nothing reads the old ones.
* feat(model): the EU07M model files take the .ng3d extension, the switch is modelformat ng3d
In place of .r3a (2fe1064f9): the model files are .ng3d and eu07.ini selects them with modelformat ng3d. The format keeps its name (EU07M), its magic and the -eu07m command line tool. Neither name has been released.
Shaders
| Directory | What is in it |
|---|---|
ogl46/ |
GLSL sources of the OpenGL 4.6 renderer |
ogl46bin/ |
SPIR-V binaries of ogl46/ (optional, made by compile_spirv.py) |
vk14/ |
GLSL sources of the Vulkan 1.4 renderer |
vk14bin/ |
SPIR-V binaries of vk14/ (optional, made by compile_spirv.py) |
The renderers load the binary of a shader first, when there is one and it was compiled from the sources that are there now
(manifest.txt of the directory of the binaries lists the sources of each binary with their hashes). Otherwise the source is
compiled: by the OpenGL driver for ogl46/, by glslang inside the simulator for vk14/ (with a cache of the results in the
directory of the user). gfx.shaders.binaries no in eu07.ini makes them always use the sources. The sources are needed
even with the binaries: the directives of the materials (#pragma texture, #pragma param) are read from them.
Compiling to SPIR-V
python shaders/compile_spirv.py
compiles every shader of ogl46/ (with the variant MODEL_DRAWS of the vertex and fragment shaders) and of vk14/ with
glslc (Vulkan SDK, VULKAN_SDK, or --glslc <path>). A single file compiles the same way by hand:
glslc --target-env=opengl4.5 ogl46/mat_default.frag -o ogl46bin/mat_default.frag.spv
glslc --target-env=opengl4.5 -DMODEL_DRAWS=1 ogl46/vertex.vert -o ogl46bin/vertex.vert.MODEL_DRAWS.spv
glslc --target-env=vulkan1.4 vk14/imgui.frag -o vk14bin/imgui.frag.spv
A binary made by hand isn't in the manifest, so it is used only where its source isn't there (otherwise the source is compiled and the log says so). After a change of a source, compile the binaries again (or delete them): a binary older than its source is not used, and the log says so.
Writing shaders
- Every stage file starts with
#version 460 coreand#define STAGE_VERTEX 1(STAGE_FRAGMENT,STAGE_GEOMETRY,STAGE_COMPUTE); files included by others (.glsl) don't. - Includes:
#include "file.glsl", relative to the directory of the file. - Every input and output between the stages has an explicit
layout(location = N), every sampler, image and block an explicit binding, every loose uniform an explicit location: SPIR-V has no names to link by. The locations of the inputs and outputs ofogl46/are one table for all the shaders (a name has the same location everywhere), seeogl46/common.glsl. - The settings of the game (
SHADOWMAP_ENABLED,ENVMAP_ENABLED,MOTIONBLUR_ENABLED,POSTFX_ENABLED,EXTRAEFFECTS_ENABLED,OUTPUT_GAMMA) areconst bool(specialization constants in the binaries,ogl46/settings.glsl): use them inif, not in#if. - A material shader names its textures and parameters with
#pragma texture(name, unit, components)and#pragma param(name, location, offset, size, default); a.matfile sets them astexture_<name>:andparam_<name>:. Every directive of a file and of its includes is read, whatever#ifdefit is in. A fourth argument of#pragma texture(black,white,red,yellow) makes the texture one the material may leave out: the unit then shows a single texel of that colour. - The materials of the metallic and roughness workflow are
mat_pbr.fragand its variants (mat_pbr_detail.frag,mat_pbr_parallax.frag,mat_pbr_coat.frag):mat_pbr.glsldeclares what they share and says what each texture and parameter is,mat_pbr_surface.glslis their fragment stage, the same file inogl46/andvk14/. They definePBR_SURFACE(andPBR_COAT), whichlight_common.glsllights as the texturing tools show the surface. - The constants of the game (bindings, sizes) are written in
ogl46/common.glslandvk14/common.glslfor the binaries; the game puts its own values before the sources and checks at the start that the files have the same ones (the shader validator inci_shadervalidatorchecks them too).
vk14
The shaders of vk14/ are those of ogl46/ made for the descriptor sets of the Vulkan renderer
(rendering/vulkan14/vulkan14bindings.h), drawn with the same matrices and the same conventions as the OpenGL renderer
(nothing is turned upside down but the picture shown in the window, present.frag).
- A stage file includes
common.glslright after its stage define. The pipeline layout it is drawn with is picked by a define before that include: none for the passes of the scene,LAYOUT_POSTfor the post-processing (withquad.vert),LAYOUT_CLUSTERfor the compute passes of the light clusters,LAYOUT_UIfor the user interface. - The scene: set
PASS_SETholds the blocks of the scene, of the draws (model_draws[], the one of a draw picked by the push constantpc.draw), of the instances and of the lights and clusters, and the shadow, environment and headlight maps; setMATERIAL_SETthe textures of the material atMATERIAL_TEXTURE_FIRST + unitof their#pragma texture. The names of the model block (modelview,param,opacity...) stand for the fields of the draw, as in theMODEL_DRAWSvariant ofogl46/. - The push constants (
pc,PUSH_CONSTANTS_SIZEbytes) carry the draw and the parameters of the special shaders inpc.data[]; each of those says at the top what it takes from them. In the post-processingparamstands forpc.data. - The settings are specialization constants with the ids
SPEC_*(vk14/settings.glsl). - The features of the later stages of the renderer (the shadows of the lamps and the headlights, the contact shadows, the
weather and its fog, the sky ambient light, the prefiltered environment map, the automatic exposure, soft and gpu
particles) aren't in
vk14/yet; the code paths are the onesogl46/takes with them off, the fog is an analytic one (vk14/apply_fog.glsl).