コード例 #1
0
        private void BakeCubemap()
        {
            PerspCam persp = new PerspCam();

            persp.aspect        = 1;
            persp.farClipPlane  = considerRange;
            persp.nearClipPlane = 0.1f;
            persp.fov           = 90f;
            NativeList <float4x4> worldToCameras = new NativeList <float4x4>(6, 6, Allocator.TempJob);
            NativeList <float4x4> projection     = new NativeList <float4x4>(6, 6, Allocator.TempJob);

            GetMatrix(worldToCameras.unsafePtr, ref persp, transform.position);
            persp.UpdateProjectionMatrix();
            for (int i = 0; i < 6; ++i)
            {
                projection[i] = persp.projectionMatrix;
            }
            RenderTexture rt = new RenderTexture(new RenderTextureDescriptor
            {
                autoGenerateMips  = false,
                bindMS            = false,
                colorFormat       = RenderTextureFormat.ARGBHalf,
                depthBufferBits   = 16,
                dimension         = TextureDimension.Tex2DArray,
                enableRandomWrite = false,
                height            = 128,
                width             = 128,
                volumeDepth       = 6,
                msaaSamples       = 1,
                useMipMap         = true
            });

            rt.filterMode = FilterMode.Trilinear;
            rt.Create();
            RenderTexture tempRT = new RenderTexture(new RenderTextureDescriptor
            {
                autoGenerateMips  = false,
                bindMS            = false,
                colorFormat       = RenderTextureFormat.ARGBHalf,
                depthBufferBits   = 16,
                dimension         = TextureDimension.Tex2D,
                enableRandomWrite = false,
                height            = 128,
                width             = 128,
                volumeDepth       = 1,
                msaaSamples       = 1
            });

            cbuffer.Clear();
            cbuffer.SetGlobalTexture("_Cubemap", rt);
            cbuffer.GenerateMips(rt);
            RenderPipeline.AddRenderingMissionInEditor(worldToCameras, projection, targetCamera, rt, tempRT, cbuffer);
        }
コード例 #2
0
ファイル: AOProbe.cs プロジェクト: zhu1987/Unity-MPipeline
        private IEnumerator BakeOcclusion()
        {
            float3 left  = transform.position - transform.localScale * 0.5f;
            float3 right = transform.position + transform.localScale * 0.5f;

            for (int x = 0; x < resolution.x; ++x)
            {
                for (int y = 0; y < resolution.y; ++y)
                {
                    for (int z = 0; z < resolution.z; ++z)
                    {
                        float3 uv = (float3(x, y, z) + 0.5f) / float3(resolution.x, resolution.y, resolution.z);
                        currentPos = lerp(left, right, uv);
                        NativeList <float4x4> view, proj;
                        CalculateCubemapMatrix(currentPos, radius, 0.01f, out view, out proj);
                        RenderPipeline.AddRenderingMissionInEditor(view, proj, bakeCamera, cameraTarget, buffer);
                        BakeOcclusionData(RenderPipeline.AfterFrameBuffer);
                        yield return(null);
                    }
                }
            }
        }
コード例 #3
0
        private void BakeMap(int3 index, RenderTexture texArray, RenderTexture tempTex)
        {
            float3   left     = transform.position - transform.lossyScale * 0.5f;
            float3   right    = transform.position + transform.lossyScale * 0.5f;
            float3   position = lerp(left, right, ((float3)index + 0.5f) / probeCount);
            PerspCam persp    = new PerspCam();

            persp.aspect        = 1;
            persp.farClipPlane  = considerRange;
            persp.nearClipPlane = 0.1f;
            persp.fov           = 90f;
            NativeList <float4x4> worldToCameras = new NativeList <float4x4>(6, 6, Allocator.TempJob);
            NativeList <float4x4> projection     = new NativeList <float4x4>(6, 6, Allocator.TempJob);

            GetMatrix(worldToCameras.unsafePtr, ref persp, position);
            persp.UpdateProjectionMatrix();
            for (int i = 0; i < 6; ++i)
            {
                projection[i] = persp.projectionMatrix;
            }
            RenderPipeline.AddRenderingMissionInEditor(worldToCameras, projection, targetCamera, texArray, tempTex, cbuffer);
        }