Build of Sebastian Lague's fluid sim doesn't work

I am making a project using Sebastian Lague’s fluid sim as a starting point: GitHub - SebLague/Fluid-Sim: A simple 2D and 3D fluid simulation

Both my project and Sebastian’s work in the editor; however, I noticed that when I try to build the project using the 2D scenes, they only show a black screen when run. The 3D scene does render spheres, but not using the velocity map colors, only in black and white.

I have a feeling it has something to do with the way this shader is set up:

Shader "Instanced/Particle3DSurf" {
    Properties{
        _MainTex("Albedo (RGB)", 2D) = "white" {}
        _Glossiness("Smoothness", Range(0,1)) = 0.5
        _Metallic("Metallic", Range(0,1)) = 0.0
    }
        SubShader{
            Tags { "RenderType" = "Opaque" }
            LOD 200

            CGPROGRAM
            #pragma surface surf Standard addshadow fullforwardshadows vertex:vert
            #pragma multi_compile_instancing
            #pragma instancing_options procedural:setup

            sampler2D _MainTex;

            struct Input {
                float2 uv_MainTex;
                float4 colour;
                float3 worldPos;
            };


        #ifdef UNITY_PROCEDURAL_INSTANCING_ENABLED
            StructuredBuffer<float3> Positions;
            StructuredBuffer<float3> Velocities;
        #endif



            SamplerState linear_clamp_sampler;
            float velocityMax;

            float scale;
            float3 colour;

            sampler2D ColourMap;

            void vert(inout appdata_full v, out Input o)
            {
                UNITY_INITIALIZE_OUTPUT(Input, o);
                o.uv_MainTex = v.texcoord.xy;

    #ifdef UNITY_PROCEDURAL_INSTANCING_ENABLED
                float speed = length(Velocities[unity_InstanceID]);
                float speedT = saturate(speed / velocityMax);
                float colT = speedT;
                o.colour = tex2Dlod(ColourMap, float4(colT, 0.5,0,0));
    #endif
            }

            void setup()
            {
            #ifdef UNITY_PROCEDURAL_INSTANCING_ENABLED
                float3 pos = Positions[unity_InstanceID];

                unity_ObjectToWorld._11_21_31_41 = float4(scale, 0, 0, 0);
                unity_ObjectToWorld._12_22_32_42 = float4(0, scale, 0, 0);
                unity_ObjectToWorld._13_23_33_43 = float4(0, 0, scale, 0);
                unity_ObjectToWorld._14_24_34_44 = float4(pos, 1);
                unity_WorldToObject = unity_ObjectToWorld;
                unity_WorldToObject._14_24_34 *= -1;
                unity_WorldToObject._11_22_33 = 1.0f / unity_WorldToObject._11_22_33;

            #endif
            }

            half _Glossiness;
            half _Metallic;

            void surf(Input IN, inout SurfaceOutputStandard o) {
                o.Albedo = IN.colour;
                o.Metallic = 0;
                o.Smoothness = 0;
                o.Alpha = 1;
            }
            ENDCG
        }
            FallBack "Diffuse"
}

Basically the code marked with #ifdef UNITY_PROCEDURAL_INSTANCING_ENABLED is being skipped in the build, but not in the editor.

I am not the only one having this issue; there is a related open issue on the Github page but it has sat open for quite some time. Would anyone be willing to test building the project for themselves to help diagnose the issue? Thanks

Hello! I played with the demo some time ago. To see those velocities in the player you add a line in ParticleDisplay3D.cs in public void Init(Simulation3D sim) function. Just add needsUpdate = true; somewhere in that funciton. That variable is set to true in OnValidate later in that file but that’s an Editor only function so it doesn’t get called in the player. This will trigger the generation of color lookup texture.

1 Like

Thank you!