Jump to content
  • Advertisement
ramirofages

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.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I came across this udk article:

https://docs.unrealengine.com/udk/Three/VolumetricLightbeamTutorial.html

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:

Screenshot_4.png.9f80ef66237b81e7a53db583f1b3591c.pngScreenshot_5.png.9c801ecfb2d4515c81394eb04921bb13.png

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 this post


Link to post
Share on other sites
Advertisement

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:

KF5WUyg.png

I copied their image to use as light texture

If you got it solved please share.

Share this post


Link to post
Share on other sites

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

V5Mz3GI.png

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

 

LQlDOyk.png

 

Share this post


Link to post
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 :

z5baTJW.png

gZyNSG8.png

 

In my test program:

xio5vwR.png

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)

tpm2drH.png

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 this post


Link to post
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

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!