コード例 #1
0
 public void SetBlendOption(FluidBlendOption.BlendOption blendoption)
 {
     if (blend.GetBlendOption() != blendoption)
     {
         blend.SetBlendOption(blendoption);
         blend.Porcess(material);
     }
 }
コード例 #2
0
    RenderTexture Render(RenderTexture target)
    {
        if (target == null)
        {
            return(null);
        }

        if (bloom_enabled)
        {
            ApplyBloom(density_dfbo.GetReadFBO(), bloom_fbo);
        }
        blendOption = FluidBlendOption.BlendOption.Enable_One_OMSA;

        int width  = target.width;
        int height = target.height;

        if (transparent_enable)
        {
            backgroundProgram.SetFloat("_aspectRatio", (float)width / (float)height);
            backgroundProgram.Blit(target, target, blendOption);
        }
        else
        {
            colorProgram.SetColor("_color", BACK_COLOR);
            colorProgram.Blit(target, target, blendOption);
        }
        if (shading_enable)
        {
            FluidProgram program = bloom_enabled ? displayBloomShadingProgram : displayShadingProgram;
            program.SetFloat("_texelSize_x", 1.0f / simWidth);
            program.SetFloat("_texelSize_y", 1.0f / simHeight);
            program.SetTexture("_uTexture", density_dfbo.GetReadFBO());
            if (bloom_enabled)
            {
                program.SetTexture("_Bloom", bloom_fbo);
                program.SetTexture("_Dithering", ditheringTexture);
                Vector2 scale = GetTextureScale(ditheringTexture, width, height);
                program.SetFloat("_ditherScale_x", scale.x);
                program.SetFloat("_ditherScale_y", scale.y);
            }
            program.Blit(target, target, blendOption);
        }
        else
        {
            FluidProgram program = bloom_enabled ? displayBloomProgram : displayProgram;
            program.SetTexture("_uTexture", density_dfbo.GetReadFBO());
            if (bloom_enabled)
            {
                program.SetTexture("_Bloom", bloom_fbo);
                program.SetTexture("_Dithering", ditheringTexture);
                Vector2 scale = GetTextureScale(ditheringTexture, width, height);
                program.SetFloat("_ditherScale_x", scale.x);
                program.SetFloat("_ditherScale_y", scale.y);
            }
            program.Blit(target, target, blendOption);
        }
        return(target);
    }
コード例 #3
0
    RenderTexture ApplyBloom(RenderTexture source, RenderTexture destination)
    {
        if (bloomFramebuffers.Count < 2)
        {
            Debug.Log("ApplyBloom return  frameid:" + frameid);
            return(destination);
        }
        RenderTexture last = destination;

        blendOption = FluidBlendOption.BlendOption.Disable;
        float knee   = bloom_threshold * BLOOM_SOFT_KNEE + 0.0001f;
        float curve0 = bloom_threshold - knee;
        float curve1 = knee * 2;
        float curve2 = 0.25f / knee;

        bloomPrefilterProgram.SetFloat("_curve_x", curve0);
        bloomPrefilterProgram.SetFloat("_curve_y", curve1);
        bloomPrefilterProgram.SetFloat("_curve_z", curve2);
        bloomPrefilterProgram.SetFloat("_threshold", bloom_threshold);
        bloomPrefilterProgram.SetTexture("_uTexture", source);
        bloomPrefilterProgram.Blit(last, last, blendOption);

        for (int i = 0; i < bloomFramebuffers.Count; i++)
        {
            RenderTexture dest = bloomFramebuffers[i];
            bloomBlurProgram.SetTexture("_uTexture", last);
            bloomBlurProgram.SetFloat("_texelSize_x", 1.0f / last.width);
            bloomBlurProgram.SetFloat("_texelSize_y", 1.0f / last.height);
            bloomBlurProgram.Blit(dest, dest, blendOption);
            last = dest;
        }

        blendOption = FluidBlendOption.BlendOption.Enable_One_One;
        for (int i = bloomFramebuffers.Count - 2; i >= 0; i--)
        {
            RenderTexture baseTex = bloomFramebuffers[i];
            bloomBlurProgram.SetTexture("_uTexture", last);
            bloomBlurProgram.SetFloat("_texelSize_x", 1.0f / last.width);
            bloomBlurProgram.SetFloat("_texelSize_y", 1.0f / last.height);
            bloomBlurProgram.Blit(baseTex, baseTex, blendOption);
            last = baseTex;
        }

        blendOption = FluidBlendOption.BlendOption.Disable;
        bloomFinalProgram.SetFloat("_texelSize_x", 1.0f / last.width);
        bloomFinalProgram.SetFloat("_texelSize_y", 1.0f / last.height);
        bloomFinalProgram.SetTexture("_uTexture", last);
        bloomFinalProgram.SetFloat("_intensity", bloom_intensity);
        bloomFinalProgram.Blit(destination, destination, blendOption);
        return(destination);
    }
コード例 #4
0
    void Step(float dt)
    {
        blendOption = FluidBlendOption.BlendOption.Disable;

        curlProgram.SetFloat("_texelSize_x", 1.0f / simWidth);
        curlProgram.SetFloat("_texelSize_y", 1.0f / simHeight);
        curlProgram.SetTexture("_Velocity", velocity_dfbo.GetReadFBO());
        curlProgram.Blit(curl_fbo, curl_fbo, blendOption);

        vorticityProgram.SetFloat("_texelSize_x", 1.0f / simWidth);
        vorticityProgram.SetFloat("_texelSize_y", 1.0f / simHeight);
        vorticityProgram.SetTexture("_Velocity", velocity_dfbo.GetReadFBO());
        vorticityProgram.SetTexture("_Curl", curl_fbo);
        vorticityProgram.SetFloat("_curl", CURL);
        vorticityProgram.SetFloat("_dt", dt);
        vorticityProgram.Blit(velocity_dfbo.GetWriteFBO(), velocity_dfbo.GetWriteFBO(), blendOption);
        velocity_dfbo.Swap();

        divergenceProgram.SetFloat("_texelSize_x", 1.0f / simWidth);
        divergenceProgram.SetFloat("_texelSize_y", 1.0f / simHeight);
        divergenceProgram.SetTexture("_Velocity", velocity_dfbo.GetReadFBO());
        divergenceProgram.Blit(divergence_fbo, divergence_fbo, blendOption);

        clearProgram.SetTexture("_uTexture", pressure_dfbo.GetReadFBO());
        clearProgram.SetFloat("_value", PRESSURE_DISSIPATION);
        clearProgram.Blit(pressure_dfbo.GetWriteFBO(), pressure_dfbo.GetWriteFBO(), blendOption);
        pressure_dfbo.Swap();

        pressureProgram.SetFloat("_texelSize_x", 1.0f / simWidth);
        pressureProgram.SetFloat("_texelSize_y", 1.0f / simHeight);
        pressureProgram.SetTexture("_Divergence", divergence_fbo);
        for (int i = 0; i < PRESSURE_ITERATIONS; i++)
        {
            pressureProgram.SetTexture("_Pressure", pressure_dfbo.GetReadFBO());
            pressureProgram.Blit(pressure_dfbo.GetWriteFBO(), pressure_dfbo.GetWriteFBO(), blendOption);
            pressure_dfbo.Swap();
        }

        gradienSubtractProgram.SetFloat("_texelSize_x", 1.0f / simWidth);
        gradienSubtractProgram.SetFloat("_texelSize_y", 1.0f / simHeight);
        gradienSubtractProgram.SetTexture("_Pressure", pressure_dfbo.GetReadFBO());
        gradienSubtractProgram.SetTexture("_Velocity", velocity_dfbo.GetReadFBO());
        gradienSubtractProgram.Blit(velocity_dfbo.GetWriteFBO(), velocity_dfbo.GetWriteFBO(), blendOption);
        velocity_dfbo.Swap();

        advectionProgram.SetFloat("_texelSize_x", 1.0f / simWidth);
        advectionProgram.SetFloat("_texelSize_y", 1.0f / simHeight);
        if (!supportLinearFiltering)
        {
            advectionProgram.SetFloat("_dyeTexelSize_x", 1.0f / simWidth);
            advectionProgram.SetFloat("_dyeTexelSize_y", 1.0f / simHeight);
        }
        advectionProgram.SetTexture("_Velocity", velocity_dfbo.GetReadFBO());
        advectionProgram.SetTexture("_Source", velocity_dfbo.GetReadFBO());
        advectionProgram.SetFloat("_dt", dt);
        advectionProgram.SetFloat("_dissipation", VELOCITY_DISSIPATION);
        advectionProgram.Blit(velocity_dfbo.GetWriteFBO(), velocity_dfbo.GetWriteFBO(), blendOption);
        velocity_dfbo.Swap();

        if (!supportLinearFiltering)
        {
            advectionProgram.SetFloat("_dyeTexelSize_x", 1.0f / dyeWidth);
            advectionProgram.SetFloat("_dyeTexelSize_y", 1.0f / dyeHeight);
        }
        advectionProgram.SetTexture("_Velocity", velocity_dfbo.GetReadFBO());
        advectionProgram.SetTexture("_Source", density_dfbo.GetReadFBO());
        advectionProgram.SetFloat("_dissipation", DENSITY_DISSIPATION);
        advectionProgram.Blit(density_dfbo.GetWriteFBO(), density_dfbo.GetWriteFBO(), blendOption);
        density_dfbo.Swap();
    }
コード例 #5
0
 public void Blit(RenderTexture source, RenderTexture destination, FluidBlendOption.BlendOption blendoption)
 {
     SetBlendOption(blendoption);
     Graphics.Blit(source, destination, material);
 }