UDK Volumetric light beam

This topic is 421 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Hi, I came across this udk article:

that somewhat teaches you how to make the volumetric light beam using a cone. I'm not using unreal engine so I just wanted to understand how the technique works.

What I'm having problems is with how they calculate the X position of the uv coordinate, they mention the use of a "reflection vector" that according to the documentation (https://docs.unrealengine.com/latest/INT/Engine/Rendering/Materials/ExpressionReference/Vector/#reflectionvectorws ) it just reflects the camera direction across the surface normal in world space (I assume from the WS initials) .

So in my pixel shader I tried doing something like this:

float3 reflected_view = reflect(view_dir, vertex_normal);
tex2D(falloff_texture, float2(reflected_view.x * 0.5 + 0.5, uv.y))

view_dir is the direction that points from the camera to the point in world space. vertex normal is also in world space. But unfortunately it's not working as expected probably because the calculations are being made in world space. I moved them to view space but there is a problem when you move the camera horizontally that makes the coordinates "move" as well. The problem can be seen below:

Notice the white part in the second image, coming from the left side.

Surprisingly I couldn't find as much information about this technique on the internet as I would have liked to, so I decided to come here for help!

Edited by ramirofages

Share on other sites

I am interested in this as well.

I tried to create hlsl by what is going on in their "material node graph" image:

void main_ps(in VERTEX_OUT IN, out PIXEL_OUT OUT)
{
static const float AddR = 8.0f;
static const float MulR = 0.8f;

float3 vvec = camPos.xyz - IN.WorldPos;
float3 v = normalize(vvec);
float3 n = normalize(IN.Normal);
float3 rvec = reflect(v, n);
float3 rx = rvec.x;
float rz = sqrt((rvec.z + AddR) * MulR);
float xcoord = (rx / rz) + 0.5f;
float2 coord = float2(xcoord, IN.TexCoord0.y);
float3 lightFalloff = tex2D(lightSamp, coord);

float3 lightCol = float3(1.0f, 1.0f, 1.0f);
OUT.Color = float4(lightCol, lightFalloff.r);
}

but wrong result:

I copied their image to use as light texture

If you got it solved please share.

Share on other sites

Thanks for sharing your stuff as well. Unfortunately I couldn't make it work yet

Share on other sites

I have downloaded Unreal engine to test it. Cant get it to work even there:

I even created same material as they have shown on tutorial:

Share on other sites

I kinda made some progress. Found their original material and inspect it, i was missing transform ReflectionVector to tangent space.

In Unreal :

In my test program:

i have seam error somehow (might be problems with my mesh exporter). And could not get correct result with CLAMP addressing (above image is WRAP)

void main_ps(in VERTEX_OUT IN, out PIXEL_OUT OUT)
{
float3x3 tangentBasis = float3x3(normalize(IN.Tangent), normalize(IN.Binormal), normalize(IN.Normal));

float2 uv = IN.TexCoord0;

static const float AddR = 8.0f;
static const float MulR = 0.6f;

float3 toEye = camPos.xyz - IN.WorldPos.xyz;

float3 v = normalize(toEye);
float3 n = normalize(IN.Normal);

float3 R = reflect(v, n);
float3 rvec = mul(R, tangentBasis);

float rx = rvec.x;
float rz = sqrt( (rvec.z + AddR) * MulR );
float xcoord = (rx / rz) + 0.5f;
float2 coord = float2(xcoord, uv.y);

float3 lightFalloff = tex2D(lightSamp, coord);

float3 lightCol = float3(1.0f, 1.0f, 1.0f);
OUT.Color = float4(lightCol, lightFalloff.r);
}

Edited by belfegor

Share on other sites

Wow thanks a lot, they never said anything about tangent space. Will try it out when I get home.

EDIT: Works great, thanks!

Edited by ramirofages

1. 1
Rutin
35
2. 2
3. 3
4. 4
5. 5

• 12
• 14
• 9
• 9
• 14
• Forum Statistics

• Total Topics
633343
• Total Posts
3011430
• Who's Online (See full list)

There are no registered users currently online

×