예제 #1
0
        public void ApplyCorrectSky(Renderer rend)
        {
            //filter by ignored layers
            bool localCube = false;

            //if the anchor is a direct link to a sky, ignore applicators all together
            mset.SkyAnchor anchor = rend.GetComponent <SkyAnchor>();
            if (anchor && anchor.BindType == SkyAnchor.AnchorBindType.TargetSky)
            {
                anchor.Apply();
                localCube = true;
            }

            //look for localized applicators to bind this renderer to
            foreach (mset.SkyApplicator app in skyApplicators)
            {
                if (localCube)
                {
                    app.RemoveRenderer(rend);
                }
                else if (app.RendererInside(rend))
                {
                    localCube = true;
                }
            }

            //no local applicator found, but we have a global sky
            if (!localCube && _GlobalSky != null)
            {
                if (anchor != null)
                {
                    if (anchor.CurrentApplicator != null)
                    {
                        anchor.CurrentApplicator.RemoveRenderer(rend);
                        anchor.CurrentApplicator = null;
                    }
                    //start last blend to global sky and tell the anchor it's gone global
                    anchor.BlendToGlobalSky(_GlobalSky);
                }
                else
                {
                    //HACK: no applying to renderers outside of a sky anchor! it leaks memory.
                    //_GlobalSky.Apply(rend,0);
                }

                if (!globalSkyChildren.Contains(rend))
                {
                    globalSkyChildren.Add(rend);
                }
            }

            //if a local cube was found or there is no global sky, remove rend
            if (localCube || _GlobalSky == null)
            {
                if (globalSkyChildren.Contains(rend))
                {
                    globalSkyChildren.Remove(rend);
                }
            }
        }
예제 #2
0
 //pulls the appropriate material reference from the renderer for sky binding
 private static Material[] getTargetMaterials(Renderer target)
 {
     mset.SkyAnchor anchor = target.gameObject.GetComponent <mset.SkyAnchor>();
     if (anchor != null)
     {
         return(anchor.materials);
     }
     //shared materials are now used everywhere except SkyAnchor, or we're leaking memory
     return(target.sharedMaterials);
 }
예제 #3
0
        public bool RendererInside(Renderer rend)
        {
            //direct binding
            mset.SkyAnchor anchor = rend.gameObject.GetComponent <mset.SkyAnchor>();
            if (anchor &&
                anchor.BindType == mset.SkyAnchor.AnchorBindType.TargetSky)
            {
                if (anchor.AnchorSky == TargetSky)
                {
                    AddRenderer(rend);
                    anchor.Apply();
                    return(true);
                }
            }

            //trigger volume binding
            if (!TriggerIsActive)
            {
                return(false);
            }

            foreach (SkyApplicator childApp in Children)
            {
                if (childApp.RendererInside(rend))
                {
                    return(true);
                }
            }

            if (anchor == null)
            {
                anchor = rend.gameObject.AddComponent(typeof(mset.SkyAnchor)) as mset.SkyAnchor;
            }

            anchor.GetCenter(ref _center);
            _center = transform.worldToLocalMatrix.MultiplyPoint(_center);

            if (TriggerDimensions.Contains(_center))
            {
                if (!AffectedRenderers.Contains(rend))
                {
                    AddRenderer(rend);
                    if (!anchor.HasLocalSky)
                    {
                        //set the  anchor up to blend from the most current global sky in its local blender
                        anchor.SnapToSky(mset.SkyManager.Get().GlobalSky);
                    }
                    anchor.BlendToSky(TargetSky);
                }
                return(true);
            }

            RemoveRenderer(rend);
            return(false);
        }
예제 #4
0
 public void RemoveRenderer(Renderer rend)
 {
     if (AffectedRenderers.Contains(rend))
     {
         AffectedRenderers.Remove(rend);
         mset.SkyAnchor anchor = rend.GetComponent <mset.SkyAnchor>();
         if (anchor && anchor.CurrentApplicator == this)
         {
             anchor.CurrentApplicator = null;
         }
     }
 }
예제 #5
0
 public void AddRenderer(Renderer rend)
 {
     mset.SkyAnchor anchor = rend.GetComponent <mset.SkyAnchor>();
     if (anchor != null)
     {
         if (anchor.CurrentApplicator != null)
         {
             anchor.CurrentApplicator.RemoveRenderer(rend);
         }
         anchor.CurrentApplicator = this;
     }
     AffectedRenderers.Add(rend);
 }
예제 #6
0
        //Directly applies sky to renderers within the bounds of this applicator or its Children
        //For editor use.
        public bool ApplyInside(Renderer rend)
        {
            if (this.TargetSky == null || !TriggerIsActive)
            {
                return(false);
            }
            mset.SkyAnchor anchor = rend.gameObject.GetComponent <mset.SkyAnchor>();
            if (anchor)
            {
                //TODO: is this necessary? this was never running before
                if (anchor.BindType == mset.SkyAnchor.AnchorBindType.TargetSky && anchor.AnchorSky == TargetSky)
                {
                    this.TargetSky.Apply(rend, 0);
                    anchor.Apply();
                    return(true);
                }
            }

            //TODO: a bounds check against fat, child-inclusive bounds here could early-out before recursion
            //recurse
            foreach (SkyApplicator childApp in Children)
            {
                if (childApp.ApplyInside(rend))
                {
                    return(true);
                }
            }

            Vector3 rendCenter = rend.bounds.center;

            if (anchor)
            {
                anchor.GetCenter(ref rendCenter);
            }
            rendCenter = transform.worldToLocalMatrix.MultiplyPoint(rendCenter);

            if (TriggerDimensions.Contains(rendCenter))
            {
                this.TargetSky.Apply(rend, 0);
                return(true);
            }
            return(false);
        }
예제 #7
0
        public void GameApplySkies(bool forceApply)
        {
            GlobalBlender.ApplyToTerrain();
            GlobalBlender.Apply();
            if (_SkyboxMaterial)
            {
                GlobalBlender.Apply(_SkyboxMaterial);
            }

            if (this.GameAutoApply || forceApply)
            {
                if (seekTimer <= 0 || forceApply)
                {
                    SeekNewRenderers();
                    seekTimer = 0.5f;
                }

                List <mset.SkyApplicator> skiesToRemove = new List <mset.SkyApplicator>();
                foreach (mset.SkyApplicator app in skyApplicators)
                {
                    if (app == null || app.gameObject == null)
                    {
                        skiesToRemove.Add(app);                                                           //clear deleted skys (if that ever happens...)
                    }
                }
                foreach (mset.SkyApplicator app in skiesToRemove)
                {
                    skyApplicators.Remove(app);
                }

                if (GlobalBlender.IsBlending || GlobalBlender.CurrentSky.Dirty || GlobalBlender.WasBlending(Time.deltaTime))
                {
                    foreach (Renderer rend in globalSkyChildren)
                    {
                        if (!rend)
                        {
                            continue;
                        }
                        mset.SkyAnchor anchor = rend.GetComponent <mset.SkyAnchor>();
                        if (anchor != null)
                        {
                            GlobalBlender.Apply(rend, anchor.materials);
                        }
                        //HACK: Even sharedMaterials apply is not safe here, in the editor that modifies project assets permanently
                        //else              GlobalBlender.Apply(rend, rend.sharedMaterials);
                    }
                }

                int             renderCheckCount = 0;
                int             currentIterator  = 0;
                List <Renderer> rendsToRemove    = new List <Renderer>();
                foreach (Renderer rend in dynamicRenderers)
                {
                    currentIterator++;
                    if (!forceApply && currentIterator < renderCheckIterator)
                    {
                        continue;
                    }

                    if (rend == null || rend.gameObject == null)
                    {
                        rendsToRemove.Add(rend);                         //clear deleted renderers (this will totally happen)
                        continue;
                    }

                    if (!rend.gameObject.activeInHierarchy)
                    {
                        continue;
                    }

                    renderCheckIterator++;
                    if (!forceApply && renderCheckCount > 50)
                    {
                        renderCheckCount = 0;
                        renderCheckIterator--;
                        break;
                    }

                    mset.SkyAnchor anchor = rend.GetComponent <mset.SkyAnchor>();
                    if (anchor.HasChanged)
                    {
                        renderCheckCount++;
                        anchor.HasChanged = false;
                        if (this.AutoMaterial)
                        {
                            anchor.UpdateMaterials();
                        }
                        ApplyCorrectSky(rend);
                    }
                }
                foreach (Renderer rend in rendsToRemove)
                {
                    dynamicRenderers.Remove(rend);
                }

                if (renderCheckIterator >= dynamicRenderers.Count)
                {
                    renderCheckIterator = 0;
                }
            }

            _GlobalSky.Dirty = false;
        }
예제 #8
0
        private void EditorApplyToList(object[] renderers, mset.SkyApplicator[] apps, bool forceApply)
        {
            foreach (object mr in renderers)
            {
                Renderer rend = (Renderer)mr;

                //filter by ignored layers
                int layerFlag = 1 << rend.gameObject.layer;
                if ((IgnoredLayerMask & layerFlag) != 0)
                {
                    continue;
                }
                if (!rend.gameObject.activeInHierarchy)
                {
                    continue;
                }

                                #if USE_PROPERTY_BLOCKS
                //HACK: force clear all property blocks just in case
                if (forceApply)
                {
                    MaterialPropertyBlock pb = new MaterialPropertyBlock();
                    pb.Clear();
                    rend.SetPropertyBlock(pb);
                }
                                #endif
                //mset.Sky.ScrubKeywords(rend.sharedMaterials);

                mset.SkyAnchor anchor = rend.gameObject.GetComponent <mset.SkyAnchor>();
                if (anchor && !anchor.enabled)
                {
                    anchor = null;
                }

                bool rendHasChanged = rend.transform.hasChanged || (anchor && anchor.HasChanged);
                bool localFound     = false;

                if (anchor && anchor.BindType == mset.SkyAnchor.AnchorBindType.TargetSky)
                {
                    anchor.Apply();
                    localFound = true;
                }
                //trigger stuff is only processed if the game will auto apply as well
                if (GameAutoApply && !localFound)
                {
                    foreach (mset.SkyApplicator app in apps)
                    {
                        if (!app.gameObject.activeInHierarchy)
                        {
                            continue;
                        }
                        if (app.TargetSky)
                        {
                            if (forceApply || app.HasChanged || app.TargetSky.Dirty || rendHasChanged)
                            {
                                localFound         |= app.ApplyInside(rend);
                                app.TargetSky.Dirty = false;
                            }
                        }
                        app.HasChanged = false;
                    }
                }

                if (!localFound && _GlobalSky)
                {
                    if (forceApply || _GlobalSky.Dirty || rendHasChanged)
                    {
                        _GlobalSky.Apply(rend, 0);
                    }
                }
                //HACK: we are checking and clearing hasChanged in a weird place during the editor loop. Hopefully that won't conflict with other plugins?
                rend.transform.hasChanged = false;
                if (anchor)
                {
                    anchor.HasChanged = false;
                }
            }

            //this is always called in EditorUpdate, only run if forced externally
            if (forceApply && _GlobalSky)
            {
                _GlobalSky.Apply(0);
                if (_SkyboxMaterial)
                {
                    _GlobalSky.Apply(_SkyboxMaterial, 0);
                }
                _GlobalSky.Dirty = false;
            }
        }
예제 #9
0
 public void OnEnable()
 {
     myanchor = (mset.SkyAnchor)target;
 }
예제 #10
0
		public void OnEnable() {
			myanchor = (mset.SkyAnchor)target;
		}
예제 #11
0
        public string GetDebugString()
        {
            string   str = "<b>SkyDebug Info - " + this.name + "</b>\n";
            Material mat = null;

            if (Application.isPlaying)
            {
                mat = GetComponent <Renderer>().material;
            }
            else
            {
                mat = GetComponent <Renderer>().sharedMaterial;
            }

            str += mat.shader.name + "\n";
            str += "is supported: " + mat.shader.isSupported + "\n";
            mset.ShaderIDs[] bids = { new mset.ShaderIDs(), new mset.ShaderIDs() };
            bids[0].Link();
            bids[1].Link("1");

            str += "\n<b>Anchor</b>\n";
            mset.SkyAnchor anchor = this.GetComponent <mset.SkyAnchor>();
            if (anchor != null)
            {
                str += "Curr. sky: " + anchor.CurrentSky.name + "\n";
                str += "Prev. sky: " + anchor.PreviousSky.name + "\n";
            }
            else
            {
                str += "none\n";
            }

            str += "\n<b>Property Block</b>\n";
            if (block == null)
            {
                block = new MaterialPropertyBlock();
            }
            block.Clear();
            this.GetComponent <Renderer>().GetPropertyBlock(block);

            for (int i = 0; i < 2; ++i)
            {
                str += "Renderer Property block - blend ID " + i;

                if (printDetails)
                {
                    str += "\nexposureIBL  " + block.GetVector(bids[i].exposureIBL);
                    str += "\nexposureLM   " + block.GetVector(bids[i].exposureLM);

                    str += "\nskyMin       " + block.GetVector(bids[i].skyMin);
                    str += "\nskyMax       " + block.GetVector(bids[i].skyMax);

                    str += "\ndiffuse SH\n";
                    for (int j = 0; j < 4; ++j)
                    {
                        str += block.GetVector(bids[i].SH[j]) + "\n";
                    }
                    str += "...\n";
                }

                Texture spec = block.GetTexture(bids[i].specCubeIBL);
                Texture sky  = block.GetTexture(bids[i].skyCubeIBL);
                str += "\nspecCubeIBL  "; if (spec)
                {
                    str += spec.name;
                }
                else
                {
                    str += "none";
                }
                str += "\nskyCubeIBL   "; if (sky)
                {
                    str += sky.name;
                }
                else
                {
                    str += "none";
                }

                if (printDetails)
                {
                    str += "\nskyMatrix\n" + block.GetMatrix(bids[i].skyMatrix);
                    str += "\ninvSkyMatrix\n" + block.GetMatrix(bids[i].invSkyMatrix);
                }

                if (i == 0)
                {
                    str += "\nblendWeightIBL " + block.GetFloat(bids[i].blendWeightIBL);
                }
                str += "\n\n";
            }
            return(str);
        }