This is where the parallax functionality is defined and configured.
It declares the parallax texture and strength:
Several preprocessor macros set up how parallax is computed:
ParallaxRaymarching is selected as the algorithm (instead of simple offset).
It uses 10 raymarching steps to trace into the height map.
Interpolation is enabled to smooth the parallax effect between steps.
Offset limiting and extra search steps are disabled in this setup.
So in short: this shader supports detailed parallax mapping via raymarching, controlled by _ParallaxMap and _ParallaxStrength.
This file contains the vertex and fragment utility functions, including where parallax is actually applied.
In the vertex program, UVs are prepared:
In the fragment program (further down in the file, not fully in the preview), the PARALLAX_FUNCTION macro from the shader (ParallaxRaymarching) is invoked. This function:
Samples the height map (_ParallaxMap).
Offsets the UVs depending on the viewing angle and the sampled height.
Simulates a 3D depth effect on flat geometry.
What it does step by step:
Setup:
Divides the ray into PARALLAX_RAYMARCHING_STEPS (default 10).
Computes how much to move UVs (uvDelta) per step, scaled by _ParallaxStrength.
Raymarching loop:
Starts at the top of the virtual surface (stepHeight = 1).
Moves UVs (uvOffset) along the view direction in small increments (uvDelta).
At each step, samples the height map via GetParallaxHeight.
Stops once the ray has passed below the sampled surface height.
Refinement options:
If PARALLAX_RAYMARCHING_SEARCH_STEPS > 0: does a binary search refinement for more accuracy.
Else if PARALLAX_RAYMARCHING_INTERPOLATE: blends between the last two steps for a smoother result.
Stopping condition:
The loop stops early if the ray has gone below the height map surface.
Output:
Returns a UV offset to apply to textures, creating the illusion of depth.
Result (later in function, not shown yet):
It interpolates between the last two steps (prevUVOffset and uvOffset) to smooth out the intersection, instead of a hard cutoff.