Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Mobile Suggestions + Help
#3
(04-10-2019, 06:24 PM)neecko Wrote: If anything I would love some help getting a really simple depth for the simple renderer.

Hi,

To get a shader to write a custom value to the depth buffer, you need to change its output from "float4" or "fixed4" to "fout". Then, inside the fragment shader declare a fout instance (as it is a struct, containing both color and depth). Set both its color and depth to the values you desire.

Now, for finding the correct depth value you need to output from the fluid shader, you need to write the particle's depth values to a render texture. So declare a new depth render texture in the SimpleFluidRenderer's command buffer (copy-pasted from the regular Fluid Renderer):

Code:
int depth = Shader.PropertyToID("_FluidDepthTexture");
renderFluid.GetTemporaryRT(depth,-1,-1,24,FilterMode.Point,RenderTextureFormat.Depth);

Then you need to render the particles to it:
Code:
renderFluid.SetRenderTarget(depth); // fluid depth
¡renderFluid.ClearRenderTarget(true,true,Color.clear); //clear
            
// draw fluid depth texture:
foreach(ObiParticleRenderer renderer in particleRenderers){
    if (renderer != null){
        foreach(Mesh mesh in renderer.ParticleMeshes){
            if (renderer.ParticleMaterial != null)
                renderFluid.DrawMesh(mesh,Matrix4x4.identity,renderer.ParticleMaterial,0,0);
        }
    }
}

Lastly, ObiFluids.cginc contains helper functions to get eye space data -position and normal- for a fluid fragment (SetupEyeSpaceFragment) and to compute the depth value from the eye space position of a fragment (OutputFragmentDepth). You can use them in the fluid shader to output the correct depth value (do not forget to #include "ObiFluids.cginc"):

Code:
fout fo;
float3 eyePos,eyeNormal;
float thickness = SetupEyeSpaceFragment(i.uv,eyePos,eyeNormal);

//...rest of your fluid fragment shader here...

fo.color = fluidColor; //set your fluid color
OutputFragmentDepth(eyePos,fo); // this will write the correct depth value to fo.depth
return fo;
Reply


Messages In This Thread
Mobile Suggestions + Help - by neecko - 26-09-2019, 10:17 PM
RE: Mobile Suggestions + Help - by neecko - 04-10-2019, 06:24 PM
RE: Mobile Suggestions + Help - by josemendez - 05-10-2019, 11:30 AM
RE: Mobile Suggestions + Help - by neecko - 08-10-2019, 10:36 PM
RE: Mobile Suggestions + Help - by neecko - 23-10-2019, 09:48 PM