コード例 #1
0
    public void Init()
    {
        var unityAPIInit = UnityAPICaller.Instance;

        _geometryBuffer?.Release();
        _gi?.Release();
        SceneParamater.InitLightmapSetting();
        Debug.Log("GI Init Begin");

        var meshRenderers = GameObject.FindObjectsOfType <MeshRenderer>();

        //gen mesh collider

        /*
         * foreach (var go in meshRenderers)
         * {
         *  if (go.GetComponent<MeshCollider>() == null)
         *  {
         *      go.gameObject.AddComponent<MeshCollider>();
         *  }
         * }*/
        Debug.LogWarning("Has Added MeshCollider");
        var boxColliders = meshRenderers.Select(x => x.bounds).ToList();
        var sceneAABB    = boxColliders[0];

        foreach (var obj in boxColliders)
        {
            sceneAABB.Encapsulate(obj);
        }

        _geometryBuffer = new UnityLmGBuffer(CollectGeomerty, LightMapSize);
        _geometryBuffer.PrepareGeometry(SaveGBufferTexture);
        ImprefectShadowMap ism;

        switch (ISMType)
        {
        case ISMGenType.TS:
            ism = new ISM_TS(ShadowMapSize, _geometryBuffer);
            break;

        case ISMGenType.CS:
            ism = new ISM_CS(IsmPass, ShadowMapSize, _geometryBuffer);
            break;

        default:
            throw new ArgumentOutOfRangeException();
        }
        _gi = new VplWithIsm(_geometryBuffer, ism, LightMapSize, TotalSampleCount, Bounce,
                             RenderTextureFormat.ARGBFloat,
                             DirectLightPass, IndirectLightPass, AccumlatePass, SpeID);
        _gi.EncodeRgbmCS        = EncodeRgbm;
        _gi.DirectLightWeight   = DirectWight;
        _gi.IndirectLightWeight = IndirectWight;


        _gi.BuildFinish = false;

        _gi.Init();
        List <GILightBase> lights = new List <GILightBase>();

        lights.AddRange(FindObjectsOfType <GIPointLight>());
        lights.AddRange(FindObjectsOfType <GIAreaLight>());
        lights.AddRange(FindObjectsOfType <GIDirectionalLight>());

        _gi.EmitVPL(lights);
        //1.准备G-buffer
        //3.聚类成polygonlight

        _gi.Cluster2Polygon();

        ShadowMapParams param = new ShadowMapParams();

        param.ShadowSlopeFactor = SceneParamater.ShadowSlopeFactor;
        param.ShadowBias        = SceneParamater.ShadowBias;
        _gi.ShadowMapParam      = param;
        _gi.BuildLightMap(BuildDirectLight, BuildIndirectLight);

        Debug.Log("GI Finish");
    }
コード例 #2
0
ファイル: Baker.cs プロジェクト: 6453Zafir/LightLayout
    public void Init()
    {
        var unityAPIInit = UnityAPICaller.Instance;

        _geometryBuffer?.Release();
        _gi?.Release();
        SceneParamater.InitLightmapSetting();
        Debug.Log("GI Init Begin");

        var meshRenderers = GameObject.FindObjectsOfType <MeshRenderer>();

        //gen mesh collider

        /*
         * foreach (var go in meshRenderers)
         * {
         *  if (go.GetComponent<MeshCollider>() == null)
         *  {
         *      go.gameObject.AddComponent<MeshCollider>();
         *  }
         * }*/
        Debug.LogWarning("Has Added MeshCollider");
        var boxColliders = meshRenderers.Select(x => x.bounds).ToList();
        var sceneAABB    = boxColliders[0];

        foreach (var obj in boxColliders)
        {
            sceneAABB.Encapsulate(obj);
        }

        _geometryBuffer = new UnityLmGBuffer(CollectGeomerty, LightMapSize);
        _geometryBuffer.PrepareGeometry(SaveGBufferTexture);

        _gi = new VplUseUnityLm(_geometryBuffer, LightMapSize, ShadowmapSize, TotalSampleCount, Bounce,
                                RenderTextureFormat.ARGBFloat,
                                DirectLightPass, IndirectLightPass, AccumlatePass);
        _gi.EncodeRgbmCS        = EncodeRgbm;
        _gi.DirectLightWeight   = DirectWight;
        _gi.IndirectLightWeight = IndirectWight;
        _gi.ShadowSlopeFactor   = SceneParamater.ShadowSlopeFactor;
        _gi.ShadowBias          = SceneParamater.ShadowBias;
        _gi.BuildFinish         = false;

        _gi.Init();
        List <GILightBase> lights = new List <GILightBase>();

        lights.AddRange(FindObjectsOfType <GIPointLight>());
        lights.AddRange(FindObjectsOfType <GIAreaLight>());
        lights.AddRange(FindObjectsOfType <GIDirectionalLight>());
        _gi.EmitVPL(lights);
        //1.准备G-buffer
        //3.聚类成polygonlight
        _gi.Cluster2Polygon();

        //  ThreadPool.QueueUserWorkItem((state) =>
        //   {
        _gi.BuildLightMap(BuildDirectLight, BuildIndirectLight);

        Debug.Log("GI Init Finish");
        //  });
    }