Example #1
0
 public void CreateCone(Player p, byte type, ConeType coneType, ushort radius, ushort verticalExpansion)
 {
     List<Pos> buffer = new List<Pos>();
     Level level = p.level;
     ushort cx = (ushort)(p.pos[0] / 32), cy = (ushort)((p.pos[1] / 32) - 1), cz = (ushort)(p.pos[2] / 32);
     ushort sx = (ushort)(cx - radius - 1), sy = cy, sz = (ushort)(cz - radius - 1), ex = (ushort)(cx + radius + 1), ey = (ushort)(cy + (radius * verticalExpansion)), ez = (ushort)(cz + radius + 1);
     ushort tempRadius = radius;
     Pos pos = new Pos(); pos.x = cx; pos.y = ey; pos.z = cz;
     for (ushort i = 0; i < verticalExpansion; i++)
         if (level.GetTile(cx, (ushort)(ey + i), cz) != type)
         {
             pos.y = (ushort)(ey + i);
             buffer.Add(pos);
         }
     int temp = 0;
     if (coneType == ConeType.Hollow)
     {
         for (ushort y = sy; y < ey; y++)
         {
             for (ushort x = sx; x < ex; x++)
                 for (ushort z = sz; z < ez; z++)
                     if (Math.Round(Distance(cx, y, cz, x, y, z)) == tempRadius)
                         if (level.GetTile(x, y, z) != type)
                         {
                             pos.x = x; pos.y = y; pos.z = z;
                             buffer.Add(pos);
                         }
             temp++;
             if (temp == verticalExpansion)
             {
                 temp = 0;
                 tempRadius--;
             }
         }
     }
     else if (coneType == ConeType.Solid)
     {
         for (ushort y = sy; y < ey; y++)
         {
             for (ushort x = sx; x < ex; x++)
                 for (ushort z = sz; z < ez; z++)
                     if (Math.Round(Distance(cx, y, cz, x, y, z)) <= tempRadius)
                         if (level.GetTile(x, y, z) != type)
                         {
                             pos.x = x; pos.y = y; pos.z = z;
                             buffer.Add(pos);
                         }
             temp++;
             if (temp == verticalExpansion)
             {
                 temp = 0;
                 tempRadius--;
             }
         }
     }
     Execute(p, buffer, type);
 }
    string GetConeKeyword(ConeType type)
    {
        switch (type)
        {
        case ConeType.Diffuse: return("TRACE_DIFFUSE");

        case ConeType.Reflectance: return("TRACE_REFLECTANCE");

        case ConeType.Transmittance: return("TRACE_TRANSMITTANCE");

        default: return(null);
        }
    }
    public void RenderDeferred(ScriptableRenderContext renderContext, Camera camera, VXGI vxgi)
    {
        ScriptableCullingParameters cullingParams;

        if (!CullResults.GetCullingParameters(camera, out cullingParams))
        {
            return;
        }
        CullResults.Cull(ref cullingParams, renderContext, ref _cullResults);

        _command.BeginSample(_command.name);

        _command.GetTemporaryRT(_propDepth, camera.pixelWidth, camera.pixelHeight, 24, FilterMode.Point, RenderTextureFormat.Depth);
        _command.GetTemporaryRT(_propDiffuse, camera.pixelWidth, camera.pixelHeight, 0, FilterMode.Point, RenderTextureFormat.ARGBHalf);
        _command.GetTemporaryRT(_propNormal, camera.pixelWidth, camera.pixelHeight, 0, FilterMode.Point, RenderTextureFormat.ARGBFloat);
        _command.GetTemporaryRT(_propEmission, camera.pixelWidth, camera.pixelHeight, 0, FilterMode.Point, RenderTextureFormat.ARGBHalf);
        _command.GetTemporaryRT(_propOther, camera.pixelWidth, camera.pixelHeight, 0, FilterMode.Point, RenderTextureFormat.ARGBHalf);
        _command.GetTemporaryRT(_propIrradiance,
                                (int)(vxgi.diffuseResolutionScale * camera.pixelWidth),
                                (int)(vxgi.diffuseResolutionScale * camera.pixelHeight),
                                0, FilterMode.Bilinear, RenderTextureFormat.ARGBHalf
                                );

        var binding = new RenderTargetBinding(
            new RenderTargetIdentifier[] { _propDiffuse, _propNormal, _propEmission, _propOther },
            new[] { RenderBufferLoadAction.DontCare, RenderBufferLoadAction.DontCare, RenderBufferLoadAction.DontCare, RenderBufferLoadAction.DontCare },
            new[] { RenderBufferStoreAction.DontCare, RenderBufferStoreAction.DontCare, RenderBufferStoreAction.DontCare, RenderBufferStoreAction.DontCare },
            _propDepth, RenderBufferLoadAction.DontCare, RenderBufferStoreAction.DontCare
            );

        _command.SetRenderTarget(binding);
        _command.ClearRenderTarget(true, true, Color.clear);
        renderContext.ExecuteCommandBuffer(_command);
        _command.Clear();

        var drawSettings = new DrawRendererSettings(camera, new ShaderPassName("Deferred"));

        drawSettings.sorting.flags = SortFlags.CommonOpaque;

        renderContext.DrawRenderers(_cullResults.visibleRenderers, ref drawSettings, _filterSettings);

        if (vxgi.pass == Pass.ConeTracing)
        {
            renderContext.SetupCameraProperties(camera);
            renderContext.DrawSkybox(camera);
        }

        if (_gBufferType != vxgi.gBufferType)
        {
            _command.DisableShaderKeyword(GetGBufferKeyword(_gBufferType));
            _command.EnableShaderKeyword(GetGBufferKeyword(vxgi.gBufferType));
            _gBufferType = vxgi.gBufferType;
        }

        if (_coneType != vxgi.coneType)
        {
            var keyword = GetConeKeyword(_coneType);
            if (keyword != null)
            {
                _command.DisableShaderKeyword(keyword);
            }

            keyword = GetConeKeyword(vxgi.coneType);
            if (keyword != null)
            {
                _command.EnableShaderKeyword(keyword);
            }

            _coneType = vxgi.coneType;
        }

        if (vxgi.skybox == null)
        {
            _command.DisableShaderKeyword("REFLECT_SKYBOX");
        }
        else
        {
            _command.EnableShaderKeyword("REFLECT_SKYBOX");
            _command.SetGlobalTexture("Skybox", vxgi.skybox);
        }

        Matrix4x4 clipToWorld = camera.cameraToWorldMatrix * GL.GetGPUProjectionMatrix(camera.projectionMatrix, false).inverse;

        _command.SetGlobalVector("CameraPosition", camera.transform.position);
        _command.SetGlobalMatrix("ClipToWorld", clipToWorld);
        _command.SetGlobalMatrix("ClipToVoxel", vxgi.worldToVoxel * clipToWorld);
        _command.SetGlobalMatrix("WorldToVoxel", vxgi.worldToVoxel);
        _command.SetGlobalMatrix("VoxelToWorld", vxgi.voxelToWorld);

        _command.EndSample(_command.name);

        renderContext.ExecuteCommandBuffer(_command);

        _command.Clear();

        if (vxgi.pass == Pass.ConeTracing)
        {
            _commandDiffuse.BeginSample(_commandDiffuse.name);
            _commandDiffuse.Blit(_propDiffuse, _propIrradiance, material, (int)Pass.DiffuseConeTracing);
            _commandDiffuse.EndSample(_commandDiffuse.name);

            renderContext.ExecuteCommandBuffer(_commandDiffuse);

            _commandDiffuse.Clear();
        }

        _commandReflection.BeginSample(_commandReflection.name);
        _commandReflection.Blit(_propDiffuse, BuiltinRenderTextureType.CameraTarget, material, (int)vxgi.pass);
        _commandReflection.EndSample(_commandReflection.name);

        renderContext.ExecuteCommandBuffer(_commandReflection);

        _commandReflection.Clear();

        _command.BeginSample(_command.name);

        _command.ReleaseTemporaryRT(_propDepth);
        _command.ReleaseTemporaryRT(_propDiffuse);
        _command.ReleaseTemporaryRT(_propNormal);
        _command.ReleaseTemporaryRT(_propEmission);
        _command.ReleaseTemporaryRT(_propOther);
        _command.ReleaseTemporaryRT(_propIrradiance);

        _command.EndSample(_command.name);

        renderContext.ExecuteCommandBuffer(_command);

        _command.Clear();
    }
Example #4
0
        public void CreateCone(Player p, byte type, ConeType coneType, ushort radius, ushort verticalExpansion)
        {
            List <Pos> buffer = new List <Pos>();
            Level      level = p.level;
            ushort     cx = (ushort)(p.pos[0] / 32), cy = (ushort)((p.pos[1] / 32) - 1), cz = (ushort)(p.pos[2] / 32);
            ushort     sx = (ushort)(cx - radius - 1), sy = cy, sz = (ushort)(cz - radius - 1), ex = (ushort)(cx + radius + 1), ey = (ushort)(cy + (radius * verticalExpansion)), ez = (ushort)(cz + radius + 1);
            ushort     tempRadius = radius;
            Pos        pos        = new Pos(); pos.x = cx; pos.y = ey; pos.z = cz;

            for (ushort i = 0; i < verticalExpansion; i++)
            {
                if (level.GetTile(cx, (ushort)(ey + i), cz) != type)
                {
                    pos.y = (ushort)(ey + i);
                    buffer.Add(pos);
                }
            }
            int temp = 0;

            if (coneType == ConeType.Hollow)
            {
                for (ushort y = sy; y < ey; y++)
                {
                    for (ushort x = sx; x < ex; x++)
                    {
                        for (ushort z = sz; z < ez; z++)
                        {
                            if (Math.Round(Distance(cx, y, cz, x, y, z)) == tempRadius)
                            {
                                if (level.GetTile(x, y, z) != type)
                                {
                                    pos.x = x; pos.y = y; pos.z = z;
                                    buffer.Add(pos);
                                }
                            }
                        }
                    }
                    temp++;
                    if (temp == verticalExpansion)
                    {
                        temp = 0;
                        tempRadius--;
                    }
                }
            }
            else if (coneType == ConeType.Solid)
            {
                for (ushort y = sy; y < ey; y++)
                {
                    for (ushort x = sx; x < ex; x++)
                    {
                        for (ushort z = sz; z < ez; z++)
                        {
                            if (Math.Round(Distance(cx, y, cz, x, y, z)) <= tempRadius)
                            {
                                if (level.GetTile(x, y, z) != type)
                                {
                                    pos.x = x; pos.y = y; pos.z = z;
                                    buffer.Add(pos);
                                }
                            }
                        }
                    }
                    temp++;
                    if (temp == verticalExpansion)
                    {
                        temp = 0;
                        tempRadius--;
                    }
                }
            }
            Execute(p, buffer, type);
        }