Obi Official Forum
Simple2DFluid Look w/ DieletricFluid Shader - Printable Version

+- Obi Official Forum (https://obi.virtualmethodstudio.com/forum)
+-- Forum: Obi Users Category (https://obi.virtualmethodstudio.com/forum/forum-1.html)
+--- Forum: Obi Fluid (https://obi.virtualmethodstudio.com/forum/forum-3.html)
+--- Thread: Simple2DFluid Look w/ DieletricFluid Shader (/thread-1452.html)



Simple2DFluid Look w/ DieletricFluid Shader - goldenmommy - 30-10-2019

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?


RE: Simple2DFluid Look w/ DieletricFluid Shader - josemendez - 30-10-2019

(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]


RE: Simple2DFluid Look w/ DieletricFluid Shader - goldenmommy - 01-11-2019

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?


RE: Simple2DFluid Look w/ DieletricFluid Shader - josemendez - 01-11-2019

(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.