示例#1
0
    public override void SetShaderParams()
    {
        MainShader.SetInt("L_WIDTH", (int)LifeDimentions.x);
        MainShader.SetInt("L_HEIGHT", (int)LifeDimentions.y);

        MainShader.SetVector("displacement", displacement);
    }
示例#2
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 Awake()
    {
        KERNEL_ID_Render = MainShader.FindKernel("Render");
        KERNEL_ID_Init   = MainShader.FindKernel("Init");
        KERNEL_ID_Update = MainShader.FindKernel("Update");

        SLIME_BLOCK_COUNT = Mathf.CeilToInt(count / InitBlockLength);
    }
示例#4
0
    private void Awake()
    {
        KERNEL_ID_Init      = MainShader.FindKernel("Init");
        KERNEL_ID_Render    = MainShader.FindKernel("Render");
        KERNEL_ID_LifeCycle = MainShader.FindKernel("LifeCycle");

        StartCoroutine(doLife());
    }
    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);
    }
    private void Awake()
    {
        KERNEL_ID_Render = MainShader.FindKernel("Render");
        KERNEL_ID_Init   = MainShader.FindKernel("Init");
        KERNEL_ID_Update = MainShader.FindKernel("Update");

        BOID_CYCLE_BLOCK_COUNT = Mathf.CeilToInt(count / InitBlockLength);

        InitComputeBuffer();
    }
示例#7
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);
    }
示例#8
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));
 }
示例#9
0
    public override void SetShaderParams()
    {
        MainShader.SetMatrix("_CameraToWorld", _Camara.cameraToWorldMatrix);
        MainShader.SetMatrix("_CameraInverseProjection", _Camara.projectionMatrix.inverse);

        MainShader.SetTexture(KERNEL_ID_Render, "_SkyboxTexture", SkyboxTexture);

        MainShader.SetVector("_PixelOffset", new Vector2(Random.value, Random.value));

        var light = DirectionalLight.transform.forward;

        MainShader.SetVector("_DirectionalLight", new Vector4(light.x, light.y, light.z, DirectionalLight.intensity));
    }
    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);
    }
示例#11
0
    public override void SetShaderParams()
    {
        var useTime = Time.time / 20;
        // var useTime = Mathf.Sin(Time.time * Mathf.PI / 15);

        var points = new Vector4[120];

        for (int i = 0; i < points.Length; i++)
        {
            points[i] =
                new Vector4(
                    Mathf.PerlinNoise(10000 + i * Mathf.PI * 50, useTime) * WIDTH,
                    Mathf.PerlinNoise(10600 + i * Mathf.PI * 50, useTime) * HEIGHT,
                    Mathf.PerlinNoise(10000 + (i + 1) * Mathf.PI * 50, useTime) * WIDTH,
                    Mathf.PerlinNoise(10600 + (i + 1) * Mathf.PI * 50, useTime) * HEIGHT);
        }

        MainShader.SetVectorArray("points", points);
    }
示例#12
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++;
    }
 public override void SetShaderParams()
 {
     MainShader.SetInt("count", count);
 }
示例#14
0
    private void Awake()
    {
        _Camara = GetComponent <Camera>();

        KERNEL_ID_Render = MainShader.FindKernel("Render");
    }
 public override void SetShaderParams()
 {
     MainShader.SetInt("count", count);
     MainShader.SetFloat("speed", 10);
 }
示例#16
0
 private void Awake()
 {
     KERNEL_ID_Render = MainShader.FindKernel("Render");
 }