Notch Notch Manual 1.0
 Light | Dark
HLSL Shaders

HLSL Shaders

Method #

The Custom CSG Code field allows you to write a line of HLSL code to implement your own CSG operation. This requires a working knowledge of HLSL and signed distance fields.

The inputs to the operation are:

Input Description
float blendWeight; The value of the CSG Blend Weight attribute.
float dist; The signed distance field value calculated by the node you are adding the custom operation to.
float sdfValue; The current signed distance field value to combine with. This was calculated by other nodes in the graph.

To produce an output from your operation, you must overwrite sdfValue with the result of your CSG operation.

Here is an example line of HLSL code which will implement a union CSG operation with an additional blending capability:

sdfValue = lerp(sdfValue, min(sdfValue, dist), blendWeight);

As another example, to mimic the replace CSG operation the code would be as follows:

sdfValue = dist;

Example HLSL Shader #

sdfValue = lerp(sdfValue, min(sdfValue, dist), blendWeight);

Further Reference #

Microsoft HLSL

Download Example Project