Problem drawing assets after a custom image effect.

I’m completely baffled by an issue I’m having with drawing assets after an image effect.
I cant seem to find a way to do it. Ive posted this problem in the support forum but its getting no traction.

Ive tried setting the render queue values in the respective shaders for the image effect and the assets i want to draw after it with no success.

Ive tried multiple ways of using a second camera to achieve the same result. But every combination of Forward/Deferred , clear buffers, capture depth buffer ect has failed to.

My guess is that somewhere that i cant find, the draw order for image effects is hard wired.
Draw order is so fundamental and ultimately should be child’s play to set. In the docs it would seem that way to.

I must be missing something drop dead obvious or the Unity Image effect base has been shipped with a terrible flaw.

I’m tantalizingly close to a very usable and extensive depth fog solution.

I just need to be able to do this

Draw solid assets
Draw DepthFog Image effect
Draw Transparent Assets
Draw Other Image Effects

Heres where I’m at right now with the effect. files attached
So far it takes the following into consideration.

Near fog color, Vignette and depth based
Middle Fog color, Start rage and depth base
Far Fog Color
Emissive Sources fog penatration and bloom bias
LitSurfaces fog penatration and bloom bias ( worked in a simple type of HDR solution, eg white surfaces wont bloom out unless they are actually lit beyond white).
Density of fog. effects bloom directly.

Once i can mange the draw order properly i can achieve the following;
Particles that work properly and integrate into the bloom and fog that utilize the above properties.
Basic light volumes that will go some way to emulating proper volumetrics.

Your best chance is to put the transparent objects in a different layer and then on the camera set the cullingmask for the camera.

So you would do the following:
-Set up a manual camera
-Set the cullingmask to cull your specified layer
-Enable the fog image effect script on the camera
-Call Render on the camera
-Change the camera clear settings
-Disable the fog image effect and enable the other effects on the camera
-Invert the culling mask
-Call render again

Have you tried using culling mask yet for this stuff? Have you tried what i suggested. It would be nice if the render function could just take the tags you want to render rather then using a culling mask.

1 Like

Ive tried using multiple cameras, but not with a single camera that renders multiple times per frame.
Neat idea Stramit. I’ll give it ago now.

Thanks heaps!

I haven’t had a chance to test it properly yet but it seems the 3.2 release has fixed the majority of the issues I was running into.
I’ll still try doing everything on the one camera though.

Well its sad news, 3.2 is broken. “camera.clearFlags = CameraClearFlags.Nothing;” Clears the whole color buffer, Zbuffer comes through ok.

Ho Hum…
I’m not doing very much but if Ive missed something and its user error id be happy to hear it. Packaged assets attached.

function Update () {

camera.clearFlags = CameraClearFlags.SolidColor;
camera.cullingMask = 1 << 0;
camera.Render();

camera.clearFlags = CameraClearFlags.Nothing;
camera.cullingMask = 1 << 1;
camera.Render();

}

496143–17485–$ClearBuffersNotworkingExample.unitypackage (41.1 KB)

Haven’t looked at your code but wouldn’t replacement shaders (render with shader) work here?

Not really. Replacement shaders replace the shader you are rendering with with the specified replacement shader. He wants to still use the ‘normal’ shader but only render objects in certain ‘groups’ (i.e opaque / transparent). If the camera supported a ‘render with type’ paramater it would be even more trivial then the method I described.

@brn are you using forward or deferred? there was something in the patch notes about clear flags and deferred rendering…

It indicates a fix though. Make sure you set up a repro and send it in. Unity are good about fixing stuff like this. I tested the clearflags in my test project and they seem be be respected.

I drew a scene
set the clear flags to none
drew another scene

The result was as expected.

You can kinda do that using RenderWithShader by specifying “RenderType” as the tag to query for replacment, it’ll only render objects that have a shader with a the matching render types you’ve defined in the replacement shader.

So if your replacement shader uses the rendertype transparent tag then it’ll render all transparent objects and nothing else. You’d be limited to a single shader for everything using the transparent tag though so defiantly not ideal. Well, you ~could~ create unique tags for each transparent shader and matching tags in each subshader of your replacement shader, bit of a pain in the ass to do though.

I can totally understand wanting a solution that’ll work with unmodified built-in shaders.

Thanks for the Suggestions Stramit and Cameron.

Its quite probable that my card is at fault here its a Nvidia 8800 gts.

@Stramit

Deferred works as expected for me as well. But unfortunately because of the order I’m trying, rendering a deferred camera a second time without clearing the buffers results in redrawing the info that’s stored in those buffers eg Normals,Diffuse, Lights etc. Which effectively overwrites any post effects that were done on the first camera pass.

First Pass ( Deferred)
Clear buffers
Draw opaque Assets only
Draw Fog Image Effect
Second pass (Deferred) Even though I’m really after Forward at this stage
Don’t clear buffers to retain depth info
Deferred System then reuses all the first pass deferred buffer and redraws opaque assets (undesired because fog is now lost).
Render transparent assets.
Render Bloom, etc.

So what I really want to do is draw using Deferred in the first pass and Forward in the second.

This is where I get the bug. Every time I redraw the camera using Forward I either lose the depth or the color buffer info. This happens no matter what combination I use if I dont clear the buffer on the second camera pass. Such as Deferred > Forward or Forward > Forward.

Ive put in a Bug report with the Unity Devs its Case 391414

I havent checked yet if when using a Defered camera if its possible to skip the deferred part of the pipeline yet, which would be another possible solution.

I’ll post up any solutions if I find one and any feedback I get form the Unity Devs.

Cheers
Bruno