예제 #1
0
    private IEnumerator doLife()
    {
        while (true)
        {
            if (!lifeIsActive)
            {
                yield return(new WaitForEndOfFrame());
            }
            else
            {
                Graphics.Blit(Life, Intermediary);

                SetShaderParams();

                MainShader.SetTexture(KERNEL_ID_LifeCycle, "Life", Life);
                MainShader.SetTexture(KERNEL_ID_LifeCycle, "Intermediary", Intermediary);

                int threadGroupsX = Mathf.CeilToInt(LifeDimentions.x / ThreadBlockSize.x);
                int threadGroupsY = Mathf.CeilToInt(LifeDimentions.y / ThreadBlockSize.y);

                MainShader.Dispatch(KERNEL_ID_LifeCycle, threadGroupsX, threadGroupsY, 1);

                yield return(new WaitForSeconds(0.05f));
                // yield return new WaitForEndOfFrame();
            }
        }
    }
    private void InitComputeBuffer()
    {
        mainBuffer = new ComputeBuffer(count, stride);

        SetShaderParams();

        MainShader.SetBuffer(KERNEL_ID_Init, "Boids", mainBuffer);
        MainShader.Dispatch(KERNEL_ID_Init, BOID_CYCLE_BLOCK_COUNT, 1, 1);
    }
예제 #3
0
    public override void Render(RenderTexture destination)
    {
        int threadGroupsX = Mathf.CeilToInt(WIDTH / ThreadBlockSize.x);
        int threadGroupsY = Mathf.CeilToInt(HEIGHT / ThreadBlockSize.y);

        MainShader.SetTexture(KERNEL_ID_Render, "Result", Result);
        MainShader.Dispatch(KERNEL_ID_Render, threadGroupsX, threadGroupsY, 1);

        Graphics.Blit(Result, destination);
    }
예제 #4
0
 public override void InitRenderTexture()
 {
     if (createTexture(ref Life, (int)LifeDimentions.x, (int)LifeDimentions.y))
     {
         MainShader.SetTexture(KERNEL_ID_Init, "Life", Life);
         int threadGroupsX = Mathf.CeilToInt(LifeDimentions.x / ThreadBlockSize.x);
         int threadGroupsY = Mathf.CeilToInt(LifeDimentions.y / ThreadBlockSize.y);
         MainShader.Dispatch(KERNEL_ID_Init, threadGroupsX, threadGroupsY, 1);
     }
     createTexture(ref Intermediary, (int)LifeDimentions.x, (int)LifeDimentions.y);
     createTexture(ref Result, (int)(WIDTH * zoomFactor), (int)(HEIGHT * zoomFactor));
 }
    public override void Render(RenderTexture destination)
    {
        MainShader.SetBuffer(KERNEL_ID_Update, "Boids", mainBuffer);
        MainShader.SetTexture(KERNEL_ID_Update, "Result", Result);
        MainShader.SetTexture(KERNEL_ID_Render, "Result", Result);

        int threadGroupsX = Mathf.CeilToInt(WIDTH / ThreadBlockSize.x);
        int threadGroupsY = Mathf.CeilToInt(HEIGHT / ThreadBlockSize.y);

        MainShader.Dispatch(KERNEL_ID_Render, threadGroupsX, threadGroupsY, 1);
        MainShader.Dispatch(KERNEL_ID_Update, BOID_CYCLE_BLOCK_COUNT, 1, 1);

        Graphics.Blit(Result, destination);
    }
예제 #6
0
    public override void Render(RenderTexture destination)
    {
        MainShader.SetTexture(KERNEL_ID_Render, "Result", Result);

        int threadGroupsX = Mathf.CeilToInt(WIDTH / 8.0f);
        int threadGroupsY = Mathf.CeilToInt(HEIGHT / 8.0f);

        MainShader.Dispatch(KERNEL_ID_Render, threadGroupsX, threadGroupsY, 1);

        if (_addMaterial == null)
        {
            _addMaterial = new Material(Shader.Find("Hidden/AddShader"));
        }

        _addMaterial.SetFloat("_Sample", _currentSample);

        Graphics.Blit(Result, destination, _addMaterial);

        _currentSample++;
    }