예제 #1
0
    public void ProjectionOnArray()
    {
        for (int i = 0; i < projectorsArray.Length; ++i)
        {
            CustomProjector p = projectorsArray[i].projector;

            if (p.enableShadow)
            {
                p.cam.SetTargetBuffers(p.depthMap.colorBuffer, p.depthMap.depthBuffer);
                p.cam.Render();
                p.cam.RemoveAllCommandBuffers();
            }
        }
        for (int j = 0; j < renderList.Count; ++j)
        {
            {
                if (convertRenderTextureToTexture2D)
                {
                    for (int i = 0; i < projectorsArray.Length; ++i)
                    {
                        CustomProjector p = projectorsArray[i].projector;

                        if (!p.projectionMat || !p.cam.gameObject.activeInHierarchy)
                        {
                            continue;
                        }

                        RenderSet render = renderList[j];
                        p.SendMatrix(p.projectionMat);
                        p.projectionMat.SetTexture("_DepthMap", p.depthMap);

                        p.projectionMat.SetTexture("_MainTex", p.decal);

                        p.projectionMat.SetTexture("_BaseMap", render.prevTex);

                        Transform t  = renderList[j].render.transform;
                        Matrix4x4 mx = Matrix4x4.TRS(t.position, t.rotation, t.localScale);
                        Graphics.DrawMesh(renderList[j].meshF.sharedMesh, mx, p.projectionMat, LayerMask.NameToLayer("Default"));
                    }
                }
                else
                {
                    for (int i = 0; i < projectorsArray.Length; ++i)
                    {
                        CustomProjector p = projectorsArray[i].projector;

                        if (!p.projectionMat || !p.cam.gameObject.activeInHierarchy)
                        {
                            continue;
                        }

                        RenderSet render = renderList[j];
                        p.SendMatrix(p.projectionMat);
                        p.projectionMat.SetTexture("_DepthMap", p.depthMap);

                        // bool isDilated = false;

                        p.projectionMat.SetTexture("_MainTex", p.decal);

                        p.projectionMat.SetTexture("_BaseMap", render.prevRender);

                        Transform t  = renderList[j].render.transform;
                        Matrix4x4 mx = Matrix4x4.TRS(t.position, t.rotation, t.localScale);
                        Graphics.DrawMesh(renderList[j].meshF.sharedMesh, mx, p.projectionMat, LayerMask.NameToLayer("Default"));
                    }
                }
            }
        }
    }
예제 #2
0
    public void Decal()
    {
        for (int i = 0; i < projectors.Count; ++i)
        {
            CustomProjector p = projectors[i].projector;

            if (p.enableShadow)
            {
                //Debug.Log(p.cam);
                p.cam.SetTargetBuffers(p.depthMap.colorBuffer, p.depthMap.depthBuffer);
                //p.cam.SetTargetBuffers(colorMap.colorBuffer, depthMap.depthBuffer);
                p.cam.Render();
                // for (int j = 0; j < renderSet.Length; ++j)
                //{
                // _uvMaskMaterial.SetTexture("_DepthMap", p.depthMap);
                //}
                p.cam.RemoveAllCommandBuffers();
            }

            // p.SendMatrix(_uvMaskMaterial);


            //int count = GeometryUtility.Physics.OverlapSphereNonAlloc(
            //    directionalRangeAttackArea[currentRangeWeaponNum].bounds.center,
            //    directionalRangeAttackArea[currentRangeWeaponNum].bounds.extents.magnitude,
            //    neighbours,
            //    enemyLayerMask);
            //Plane[] frustumPlanes = GeometryUtility.CalculateFrustumPlanes(p.cam);
        }
        CommandBuffer command = new CommandBuffer();

        command.Clear();
        command.name = "UV Space Renderer";
        for (int j = 0; j < renderList.Count; ++j)
        {
            // if (GeometryUtility.TestPlanesAABB(frustumPlanes, renderList[i].render.bounds))
            {
                //Texture2D prevTex = renderList[j].baseMap;
                //RenderTexture prevRender = renderList[0].captureTex;
                //Texture prevTex = renderList[j].baseMap;
                //RenderTexture.active = prevRender;
                if (convertRenderTextureToTexture2D)
                {
                    for (int i = 0; i < projectors.Count; ++i)
                    {
                        CustomProjector p = projectors[i].projector;

                        RenderSet render = renderList[j];
                        Plane[]   plane  = GeometryUtility.CalculateFrustumPlanes(p.cam);
                        if (!GeometryUtility.TestPlanesAABB(plane, render.render.bounds))
                        {
                            continue;
                        }

                        p.SendMatrix(_uvMaskMaterial);
                        _uvMaskMaterial.SetTexture("_DepthMap", p.depthMap);

                        bool isDilated = false;

                        command.SetRenderTarget(render.captureTex);
                        _uvMaskMaterial.SetTexture("_MainTex", p.decal);
                        //if (render.baseMap)

                        _uvMaskMaterial.SetTexture("_BaseMap", render.prevTex);

                        // _uvMaskMaterial.SetTexture("_BaseMap", convertRenderTextureToTexture2D?prevTex:prevRender/* render.baseMap*/);

                        command.DrawRenderer(render.render, _uvMaskMaterial, 0);
                        if (render.dilateTex && render.dilateMat)
                        {
                            command.Blit(render.captureTex, render.dilateTex, render.dilateMat);
                            isDilated = true;
                        }
                        Graphics.ExecuteCommandBuffer(command);

                        Texture2D tex = RenderTextureToTexture2D(isDilated ? render.dilateTex : render.captureTex);
                        render.render.sharedMaterial.SetTexture("_MainTex", tex /* isDilated ? render.dilateTex : render.captureTex*/);
                        render.prevTex = tex;
                        renderList[j]  = render;

                        command.Clear();
                    }
                }
                else
                {
                    //RenderTexture prevRender = new RenderTexture(prevTex?prevTex.width / 2:1024, prevTex?prevTex.height / 2:1024, 0);
                    //RenderTexture.active = prevRender;
                    //Graphics.Blit(prevTex, prevRender);
                    for (int i = 0; i < projectors.Count; ++i)
                    {
                        CustomProjector p = projectors[i].projector;

                        RenderSet render = renderList[j];
                        Plane[]   plane  = GeometryUtility.CalculateFrustumPlanes(p.cam);
                        if (!GeometryUtility.TestPlanesAABB(plane, render.render.bounds))
                        {
                            continue;
                        }

                        p.SendMatrix(_uvMaskMaterial);
                        _uvMaskMaterial.SetTexture("_DepthMap", p.depthMap);

                        bool isDilated = false;

                        command.SetRenderTarget(render.captureTex);
                        _uvMaskMaterial.SetTexture("_MainTex", p.decal);

                        _uvMaskMaterial.SetTexture("_BaseMap", render.prevRender);

                        command.DrawRenderer(render.render, _uvMaskMaterial, 0);
                        if (render.dilateTex && render.dilateMat)
                        {
                            command.Blit(render.captureTex, render.dilateTex, render.dilateMat);
                            isDilated = true;
                        }
                        Graphics.ExecuteCommandBuffer(command);

                        if (isDilated)
                        {
                            render.captureTex = render.dilateTex;
                        }
                        //RenderTexture rt = isDilated ? render.dilateTex : render.captureTex;
                        render.render.sharedMaterial.SetTexture("_MainTex", render.captureTex /*rt*/);
                        render.prevRender = render.captureTex;// rt;
                        renderList[j]     = render;
                        command.Clear();
                    }
                }
            }
        }
    }
예제 #3
0
    public void ProjectionOnList()
    {
        for (int i = 0; i < projectors.Count; ++i)
        {
            CustomProjector p = projectors[i].projector;

            if (p.enableShadow)
            {
                p.cam.SetTargetBuffers(p.depthMap.colorBuffer, p.depthMap.depthBuffer);
                p.cam.Render();
                p.cam.RemoveAllCommandBuffers();
            }

            projectors[i].cullingCount = 0;
        }
        for (int j = 0; j < renderList.Count; ++j)
        {
            {
                if (convertRenderTextureToTexture2D)
                {
                    for (int i = 0; i < projectors.Count; ++i)
                    {
                        CustomProjector p = projectors[i].projector;

                        if (!p.projectionMat)
                        {
                            continue;
                        }

                        RenderSet render = renderList[j];

                        Plane[] plane = GeometryUtility.CalculateFrustumPlanes(p.cam);
                        if (!GeometryUtility.TestPlanesAABB(plane, render.render.bounds))
                        {
                            continue;
                        }

                        //EFrustumIntersection result = p.frustum.TestPoint(render.render.bounds.center);//(render.render.bounds);
                        //Debug.Log(p.cam.name + "'s " + render.render.name + " Culling Result is " + result);

                        //if(result == EFrustumIntersection.Outside)
                        //{
                        //    continue;
                        //}
                        projectors[i].cullingCount++;

                        p.SendMatrix(p.projectionMat);
                        p.projectionMat.SetTexture("_DepthMap", p.depthMap);

                        p.projectionMat.SetTexture("_MainTex", p.decal);

                        p.projectionMat.SetTexture("_BaseMap", render.prevTex);

                        Transform t  = renderList[j].render.transform;
                        Matrix4x4 mx = Matrix4x4.TRS(t.position, t.rotation, t.localScale);
                        Graphics.DrawMesh(renderList[j].meshF.sharedMesh, mx, p.projectionMat, LayerMask.NameToLayer("Default"));
                    }
                }
                else
                {
                    for (int i = 0; i < projectors.Count; ++i)
                    {
                        CustomProjector p = projectors[i].projector;

                        if (!p.projectionMat)
                        {
                            continue;
                        }

                        RenderSet render = renderList[j];

                        Plane[] plane = GeometryUtility.CalculateFrustumPlanes(p.cam);
                        if (!GeometryUtility.TestPlanesAABB(plane, render.render.bounds))
                        {
                            continue;
                        }

                        //EFrustumIntersection result = p.frustum.TestPoint(render.render.bounds.center);//(render.render.bounds);
                        //Debug.Log(p.cam.name + "'s " + render.render.name + " Culling Result is " + result);

                        //if(result == EFrustumIntersection.Outside)
                        //{
                        //    continue;
                        //}
                        projectors[i].cullingCount++;

                        p.SendMatrix(p.projectionMat);
                        p.projectionMat.SetTexture("_DepthMap", p.depthMap);

                        // bool isDilated = false;

                        p.projectionMat.SetTexture("_MainTex", p.decal);

                        p.projectionMat.SetTexture("_BaseMap", render.prevRender);

                        Transform t  = renderList[j].render.transform;
                        Matrix4x4 mx = Matrix4x4.TRS(t.position, t.rotation, t.localScale);
                        Graphics.DrawMesh(renderList[j].meshF.sharedMesh, mx, p.projectionMat, LayerMask.NameToLayer("Default"));
                    }
                }
            }
        }
    }