Shadow on ray marching material

I’m trying to implement shadows in the beam material from UE4 DMX Plugin, so I can use it with a flashlight and stop worrying about light trails cause by volumetric fog, the problem is that I really don’t know how, actually, I don’t know anything about HLSL.

So, if any tech artist wizard can help me and explain like I’m five or give me some material to study, it would be awesome.



float traversalDepth = FDepth - NDepth ;
uint numSteps = floor(traversalDepth / StepSize) ;
float3 posOffset = normalize(FSlice-NSlice) * StepSize ;

float Adj = AdjOpp.x;
float Opp = AdjOpp.y + ConeRadius;

float3 cumul = 0;

for(uint i=0; i<numSteps; i++){

///Position & depth at rayHit
float3 pos = NSlice + posOffset * i ;
float depth = NDepth + StepSize * i ;

float dist = length(pos);
float falloff = 1.0f-(length(pos)/MaxDistance);

///Domain Transform
pos.z = -pos.z;
pos /= float3(Opp*2,Opp*2,Adj);

float div = ConeRadius / Opp;
div = (pos.z*(1-div))+div;
pos.xy /= div;

//Falloff old
//float falloff = 1.0-saturate(length(pos));

//Center domain
pos.z -= 0.5 ;

///Clip domain edges.
float maskX = (1-abs(pos.x)) > 0.5 ;
float maskY = (1-abs(pos.y)) > 0.5 ;
float maskZ = (1-abs(pos.z)) > 0.5 ;
if( (maskX*maskY*maskZ) - 0.5 < 0 ) continue ;

///Soft clipping with scene depth.
float dClip = saturate((ScDepth-depth)/SoftClipSize);

// UVs from pos
pos.xy = saturate(pos.xy+0.5);
float2 GoboUV = pos.xy;
float2 ColorUV = pos.xy;

// Gobo scale offset
GoboUV.x = GoboUV.x / NumGobos;
GoboUV.x = GoboUV.x + (GoboIndex/NumGobos) ;

// Gobo scrolling
GoboUV.x = GoboUV.x + (Time*GoboScrollingSpeed);

// Sample Gobo
float GoboSample = TXTpGobo.SampleLevel(TXTpGoboSampler,GoboUV.xy,0) ;

// Color Wheel scale offset
ColorUV.x = ColorUV.x / NumColors;
ColorUV.x = ColorUV.x + (ColorIndex/NumColors) ;

// Color scrolling
ColorUV.x = ColorUV.x + ((Time-CurrentTime) * ColorScrollingSpeed);

// Sample Color Wheel
float3 ColorSample = TXTpColor.SampleLevel(TXTpColorSampler,ColorUV.xy,0) ;

// Add DMXColor in
ColorSample = ColorSample * DMXColor;

// Hotspot
float invsqr = 1.0f / (dist*dist);

///Add to Result
cumul += GoboSample * ColorSample * (1.0f/numSteps) * dClip * invsqr *falloff;

}

return cumul ;


Material: M_Beam_Master posted by anonymous | blueprintUE | PasteBin For Unreal Engine 4

Trying to breathe some life back into this post, has anyone found any answers to this? I am looking for the same thing

One way to do it is to just use shadowmapping, use a scene capture to render a depth view from the lightsource and in your raymarch loop you would check to see if the position at the current step is shadowed or not. Then you would need to consider that when you accumulate all your samples.

This really isn’t something for beginners but there are probably code examples if you search ShaderToy.