Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Simple2DFluid Look w/ DieletricFluid Shader
#1
Hi! Just started diving in w/ this great asset.  With Simple2DFluid, the fluid is rendered on top of all other objects in the scene so you would, for example, see the fluid through even an opaque bucket.  With DieletricFluid this is not the case and this is how I would like my rendering to behave.  However I am unable to replicate the exact quality of the Simple2DFluid w/ DieletricFluid even messing with the cloudiness level.  Is there any way to either get DielectricFluid to look like Simple2DFluid or to have Simple2DFluid render "behind" opaque objects in the scene?
Reply
#2
(30-10-2019, 06:27 AM)goldenmommy Wrote: Hi! Just started diving in w/ this great asset.  With Simple2DFluid, the fluid is rendered on top of all other objects in the scene so you would, for example, see the fluid through even an opaque bucket.  With DieletricFluid this is not the case and this is how I would like my rendering to behave.  However I am unable to replicate the exact quality of the Simple2DFluid w/ DieletricFluid even messing with the cloudiness level.  Is there any way to either get DielectricFluid to look like Simple2DFluid or to have Simple2DFluid render "behind" opaque objects in the scene?

Hi,

The simple fluid shader is trivial, all it does is multiply the background (refracted image) with a color. So simply modify the dielectric one to do the same. Here's the modified fragment shader for DielectricFluidShader:

Code:
fout frag (v2f i)
{
    fout fo;
    fo.color = fixed4(0,0,0,1);

    float3 eyePos,eyeNormal, worldPos, worldNormal, worldView;
    float thickness = SetupEyeSpaceFragment(i.uv,eyePos,eyeNormal);
    GetWorldSpaceFragment(eyePos,eyeNormal,worldPos,worldNormal,worldView);

    fo.color.rgb = tex2D(_Refraction, i.uv) * _CloudinessColor.rgb;

    OutputFragmentDepth(eyePos,fo);
    return fo;
}

In this case, the color being multiplied is the cloudiness color. Here's the result:

[Image: u2jrO0M.png]
Reply
#3
Thanks for the response! It's very close but the refraction slider is not having any effect and the fluid is rendered unrefracted.  Also the cloudiness slider does not seem to be doing anything either but the color is being applied.  Any ideas?
Reply
#4
(01-11-2019, 12:47 AM)goldenmommy Wrote: Thanks for the response! It's very close but the refraction slider is not having any effect and the fluid is rendered unrefracted.  Also the cloudiness slider does not seem to be doing anything either but the color is being applied.  Any ideas?

Hi,

Neither of those things are implemented in the shader I posted, as you can see. The resulting color is simply the background color (read from the _Refraction buffer) multiplied by the cloudiness color. No refraction, no gradual application of the cloudiness.

Adding these should be trivial, simply copy-paste the bits you need from the original dielectric shader.
Reply