DXX Raytracer is a fork of the DXX Retro project for Windows. DXX Raytracer uses modern raytracing techniques to update the graphics of the beloved retro game known as Descent.
This pull request adds parallax mapping support. This works by added a new height texture slot (grayscale) and using that texture to offset all the other texture maps by a calculated parallax to give the impression of depth/height for surfaces. The supplied height texture should use middle gray for base surface. Darker shades of gray will appear to recess into the surface, lighter shades will appear to pop out of the surface. This addition is currently limited to parallaxing the color channel and does not update the lighting and depth calculations which can result in some minor graphical oddities. This addition does result in a 2-3% performance hit. I added a toggle in the raytracing settings to allow for disabling of the effect.
Off
On
Off
On
Changes:
RTmaterials.h
Added new member height_texture to RT_MaterialPaths
RTmaterials.c
Added new height texture slot to g_rt_texture_slot_names
Update RT_ParseMaterialDefinitionFile to also look for height texture
Update RT_InitAllBitmaps to also look for height texture
Renderer.h
Added member RT_MaterialTextureSlot_Height to RT_MaterialTextureSlot
Added member height_texture to RT_Material and RT_MaterialPathsExist
shared_common.hlsl.h
Added member height_index to struct Material
primary_ray.hlsli
Updated GetHitGeometryFromRay to sample the new height texture and offset the uv coordinates of the surface to give the impression of depth. It does this by starting the depth check at the middle gray value and comparing that to the sampled height value at the original uv coordinate. If the sampled value is above this starting value the shader will search toward the ray direction (popout), if the sampled value is below it will search away from the ray direction (recess). This search will consist of offsetting the uv coordinate by a predetermined amount and then sampling the height again. It will continue to do this until the sample is on the opposite side of the height value it started on. The last step is to take this new uv offset and blend it with the uv offset from the previous loop.
GlobalDX.h
Updated struct D3D12State to add new gray_texture slots. These slots are necessary to hold a middle gray texture to be loaded into the height slot of any material that does not specify a height texture.
RenderBackend.cpp
Updated CreateDefaultTextures() to create a new gray texture to be used in the height slot of any material that doesn't specify a height texture.
Updated UpdateMaterial() to assign new gray texture to height slot of any material that doesn't specify a height texture.
menu.c
Added to menu option "Parallax Mapping" to enable or disable parallaxing feature
shared_tweakvars.hlsl.h
Added new tweakvar "enable_parallax_mapping" to control if parallax mapping feature is enabled.
Issues:
This addition does create some minor graphical issues to be aware of and may need additional work to address. As this update does not update the lighting calculations the lighting does not move with the parallaxing texture resulting in the lighting appearing to "slide" against texture. Most noticeable in darker areas with a bright light source like a flare, brightly lit areas the issue isn't really noticeable.
The addition of depth can cause textures that were not meant to wrap to be wrapped like the below light texture. It might be possible to add a new mirrored texture sampler to address this issue, but is not part of this PR.
This pull request adds parallax mapping support. This works by added a new height texture slot (grayscale) and using that texture to offset all the other texture maps by a calculated parallax to give the impression of depth/height for surfaces. The supplied height texture should use middle gray for base surface. Darker shades of gray will appear to recess into the surface, lighter shades will appear to pop out of the surface. This addition is currently limited to parallaxing the color channel and does not update the lighting and depth calculations which can result in some minor graphical oddities. This addition does result in a 2-3% performance hit. I added a toggle in the raytracing settings to allow for disabling of the effect.
Off On Off On
Changes:
RTmaterials.h
RTmaterials.c
Renderer.h
shared_common.hlsl.h
primary_ray.hlsli
GlobalDX.h
RenderBackend.cpp
menu.c
shared_tweakvars.hlsl.h
Issues: This addition does create some minor graphical issues to be aware of and may need additional work to address. As this update does not update the lighting calculations the lighting does not move with the parallaxing texture resulting in the lighting appearing to "slide" against texture. Most noticeable in darker areas with a bright light source like a flare, brightly lit areas the issue isn't really noticeable.
The addition of depth can cause textures that were not meant to wrap to be wrapped like the below light texture. It might be possible to add a new mirrored texture sampler to address this issue, but is not part of this PR.