Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UE4 Atmosphere shader breaks with Ray Tracing Enabled #1

Closed
arraybercov opened this issue Mar 21, 2020 · 7 comments
Closed

UE4 Atmosphere shader breaks with Ray Tracing Enabled #1

arraybercov opened this issue Mar 21, 2020 · 7 comments
Labels
bug Something isn't working

Comments

@arraybercov
Copy link

Heya,

I have a project that requires ray tracing enabled even though my space scene does not use it. When I enable ray tracing in the project settings the shader stops working. Any ideas how to fix?

@Dimev
Copy link
Owner

Dimev commented Mar 21, 2020

How exactly does it break? does it just disappear?

@Dimev Dimev added the bug Something isn't working label Mar 21, 2020
@arraybercov
Copy link
Author

arraybercov commented Apr 8, 2020

Hey Dimev,

Yes. I can tell you exactly how.

I get a SM5 Ray tracing closest hit shaders cannot read from the SceneTexturesStruct error in the Stats tab in the material graph (I'm looking at the non-post version.

The issue is in your Get Max Distance custom expression node. Any ideas how we could re-write that Texture2DSampleLevel function to not need this struct? Maybe we can add an input to Get Max Distance to replace that or just try and do it all with nodes?

float3 Forward = mul(float3(0.00000000,0.00000000,1.00000000), ResolvedView.ViewToTranslatedWorld);
float DeviceZ = Texture2DSampleLevel(SceneTexturesStruct.SceneDepthTexture, SceneTexturesStruct.SceneDepthTextureSampler, ScreenAlignedPosition(GetScreenPosition(Parameters)), 0).r;

float Depth = DeviceZ * View.InvDeviceZToWorldZTransform[0] + View.InvDeviceZToWorldZTransform[1] + 1.0f / (DeviceZ * View.InvDeviceZToWorldZTransform[2] - (View.InvDeviceZToWorldZTransform[3] + 0.00000001));

return Depth / abs(dot(Forward, Parameters.CameraVector));

@Dimev
Copy link
Owner

Dimev commented Apr 8, 2020

Someone else also had this issue in the 4.25 preview

The code I'm using here essentially makes sure the distance returned by the depth buffer is correct, because using the scene depth node divided by the dot product of the forward and camera vector directly results in the depth not being 100% accurate at large distances.

I assume the issue has something to do with the material being involved in raytracing. maybe it can be fixed by somehow making the material not a closest hit shader, but I'll have to look at it, and maybe a different workaround of the max distance thing.

@arraybercov
Copy link
Author

If you have any ideas I may be able to implement, happy to try. If there is any way to do it without HLSL that'd be safer of course.

@Dimev
Copy link
Owner

Dimev commented Apr 9, 2020

The weird depth thing is because the ue4 devs added a very small value to DeviceZToWorldZ to avoid dividing by 0 in one shader in the engine (which is a stupid hack, just do proper divide by zero checking), causing the depth to be inaccurate, and needing this workaround (written by Dexyfex, not me)

There's probably a way to get around this with only nodes, but that needs investigation. Probably dividing the resulting depth by some values using nodes may work, but I haven't had success with that so far

@Dimev
Copy link
Owner

Dimev commented May 11, 2020

I found a fix for the issue, I'll soon upload a 4.25 version of the project and close this.
The new code for the Get Max Distance node is this:

float3 Forward = mul(float3(0.00000000,0.00000000,1.00000000), ResolvedView.ViewToTranslatedWorld);
float DeviceZ = LookupDeviceZ(ScreenAlignedPosition(GetScreenPosition(Parameters))).r;

float Depth = DeviceZ * View.InvDeviceZToWorldZTransform[0] + View.InvDeviceZToWorldZTransform[1] + 1.0f / (DeviceZ * View.InvDeviceZToWorldZTransform[2] - (View.InvDeviceZToWorldZTransform[3] + 0.00000001));

return Depth / abs(dot(Forward, Parameters.CameraVector));

@Dimev
Copy link
Owner

Dimev commented May 12, 2020

I uploaded the version with the fix, should work now

@Dimev Dimev closed this as completed May 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants