Intersection fading not affected by offset

brum 10 months ago • updated 5 months ago 2

I've been trying to make an additive particle shader that has intersection fading that works nicely in most situations.

The issue is that i have some effects that i don't really want to be intersection-faded right on the surface they hit, because they're visually too important to be cut off. Which is where the offset factor/units property of the shader come into play, which should be used to offset the depth of your particle, meaning it can be rendered on top of geometry, but only to an extent.

Now sadly this offset property doesn't change where your intersection fading starts/ends, so your particle is still never going to render on top of anything if you want any sort of intersection fading to make your edges nice and clean, in case your particle is occluded by something, even after its offset.

I've looked into the compiled shader code, and i was able to come up with a solution, but it's extremely annoying having to change this line within the shader every time i re-compile it from within ShaderForge.

The fix is changing how partZ is calculated within the fragment shader, which by default is:
float partZ = max(0,i.projPos.z - _ProjectionParams.g);
This is the reason why any offset and intersection fading will never work.

My solution right now is to manually change the line to this, every time the shader is compiled:

 float partZ = max(0 - _SurfaceOffset, i.projPos.z - _ProjectionParams.g - _SurfaceOffset );

which goes into the final color calculation as normally implemented;

finalColor = Color*saturate((sceneZ-partZ)/_Smoothness));

I've tried to implement my own partZ calculation in shaderforge, but it just seems to rely too much on a bunch of shader functions that i don't know SF can even access.

I'm wondering, could you account for the offset with shader properties that work based on depth?

Or even better, you could add an "offset" input to the "depth blend" node, and upon compilation, it could do something differently for calculating the fade; calculate it's depth NOT using 0 for "max" depth, but something similar to my solution.

Hopefully this should be pretty easy feature for you to implement!


Feels like this plugin is reaching a dead end, why not just announce it? Why not hire more staff?