Closed nezix closed 6 years ago
The texture is cloned on startup, so if you're looking at it in the editor inspector, it will always be black.
Does the viewport render correctly?
No it does not.
Any errors / warnings?
Sadly no
Well, that's going to be tricky to debug remotely.
My guess is that something in the compute shader isn't compiling correctly -- what if you just set the texture to red in the raytrace kernel and return right away? If that works, you might need to manually bisect it until you find the line that's causing trouble.
And thanks for reporting the bug(!), I'm sure other people are hitting it too.
I will try to debug it ! I keep you updated.
Something goes wrong line 273 of RayTracer.compute.
If I change the line from _MainTex[xy] += vec4(r.color, 1);
to _MainTex[xy] = vec4(r.color, 1);
I get that
Ah, that line is actually somewhat shady - what if you grab the value, add to it and then store it back?
vec4 colTmp = _MainTex[xy];
colTmp += vec4(r.color,1);
_MainTex[xy] = colTmp;
Does not do the trick.
That buffer is never explicitly cleared, perhaps my driver is initializing it to 0 and yours is defaults to garbage (NaN, etc).
Right after initialization (the link I sent) set Render texture.active equal to the newly allocated texture then GL.Clear() it.
m_accumulatedImage = new RenderTexture(MainTexture.descriptor);
m_accumulatedImage.enableRandomWrite = true;
RenderTexture.active = m_accumulatedImage;
GL.Clear(false, true, Color.white);
m_accumulatedImage.Create();
Still a black screen. It has to be a driver issue anyway.
If I uncomment the MainTex[xy] += vec4(r.color, 1);
line, I have a white screen as expected.
Yeah, seems like a driver issue, what version are you using?
I am on 390.77. I am currently updating to 391.35
Ah there is some interesting interaction between the compute shader and the texture (looking into it more now). I think the solution is to write to a single value to the texture from the compute shader and then accumulate into the final texture with a blit after; in pseudo code:
RayTraceKernels.SetTexture(m_rayTraceKernel, "_MainTexInput", m_tempSingleValueImage);
...
compute.Dispatch(...);
Graphics.Blit(m_tempSingleValueImage, m_accumulatedImage, AdditiveMaterial);
Let me know if this works -- or if you don't want to invest more time, I'll push a branch for you to try later tonight.
I updated to the latest driver version and I still get the black screen. I see what you mean. I don't have much time today but I can look into it probably tomorrow. Thanks for your support !
Thanks for reporting and trying to debug it! I'll probably just make that change and push it (sometime later), this seems like a good change regardless.
Oh, it looks like reading and writing RWTexture2D
I tried to use 2 different RenderTexture but could not make it work properly. Did you find a workaround ?
I've confirmed with friends at NVIDIA that float4 with RWTexture2D was not supported on your generation of GPU. I think I have a decent work around, hopefully I'll have some time tonight to finish it up.
Ok, this is still a work in progress, but want to give it a try? https://github.com/jcowles/gpu-ray-tracing/commit/55dd69dfb79c4b4f5911c14a9189e849ec0ba789
It skips the texture entirely and color is accumulated directly from the rays in the full screen resolve.
Works like a charm. I really appreciate your support !
Sweet!
Note that there is still a bug with this version (some bad aliasing was introduced), so I'll track that down and then merge it back into the main branch.
I added the https://github.com/Chman/SMAA asset but it does not fully solve the aliasing issue. Thanks again !
Yeah, this is a legit bug somewhere, it should look as clean as the images in the blog post.
Ah, FYI, the aliasing bug is due to the difference in resolution of the accumulation buffer and the screen resolution -- the texture was filtered via the texture sampler in the full screen resolve pass, where sampling the rays directly has no filtering.
The final fix has been pushed to master as ae99186
Hello,
I was impatient to try your implementation in Unity but I have black screen on a freshly cloned repo on Unity 2017.1 and 2017.3. Windows 10 / 780 Ti. The AccumulatedColorTexture is filled with black.