Пример #1
0
        void DecodeFloat(int w, int h, int c, float min, float max, RenderTexture tex, IntPtr colorMap)
        {
            Texture2D mapR = new Texture2D(w, h, TextureFormat.ARGB32, false, true);

            mapR.filterMode = FilterMode.Point;
            mapR.wrapMode   = TextureWrapMode.Clamp;
            loadEncodedChannelAndSetPixels(0, w, h, c, mapR, colorMap);

            Texture2D mapG = new Texture2D(w, h, TextureFormat.ARGB32, false, true);

            mapG.filterMode = FilterMode.Point;
            mapG.wrapMode   = TextureWrapMode.Clamp;
            loadEncodedChannelAndSetPixels(1, w, h, c, mapG, colorMap);

            Texture2D mapB = new Texture2D(w, h, TextureFormat.ARGB32, false, true);

            mapB.filterMode = FilterMode.Point;
            mapB.wrapMode   = TextureWrapMode.Clamp;
            loadEncodedChannelAndSetPixels(2, w, h, c, mapB, colorMap);

            Texture2D mapA = new Texture2D(w, h, TextureFormat.ARGB32, false, true);

            mapA.filterMode = FilterMode.Point;
            mapA.wrapMode   = TextureWrapMode.Clamp;
            loadEncodedChannelAndSetPixels(3, w, h, c, mapA, colorMap);

            Marshal.FreeHGlobal(colorMap);

            mapR.Apply();
            mapG.Apply();
            mapB.Apply();
            mapA.Apply();
//
//
            if (m_decodeToFloat == null)
            {
                m_decodeToFloat = new Material(ShaderTool.GetMatFromShader2("CompiledDecodedToFloat.shader"));


                if (m_decodeToFloat == null)
                {
                    Debug.Log("EncodeFloat::WriteIntoRenderTexture2D - could not find shader EncodeFloat/DecodeToFloat. Did you change the shaders name?");
                    return;
                }
            }

            m_decodeToFloat.SetFloat("_Max", max);
            m_decodeToFloat.SetFloat("_Min", min);
            m_decodeToFloat.SetTexture("_TexR", mapR);
            m_decodeToFloat.SetTexture("_TexG", mapG);
            m_decodeToFloat.SetTexture("_TexB", mapB);
            m_decodeToFloat.SetTexture("_TexA", mapA);
            Graphics.Blit(null, tex, m_decodeToFloat);


            UnityEngine.Object.Destroy(mapR);
            UnityEngine.Object.Destroy(mapG);
            UnityEngine.Object.Destroy(mapB);
            UnityEngine.Object.Destroy(mapA);
        }
Пример #2
0
        //		protected override void Start()
        public override void Start()
        {
            base.Start();

            m_initJacobiansMat       = new Material(ShaderTool.GetMatFromShader2("CompiledInitJacobians.shader"));
            m_whiteCapsPrecomputeMat = new Material(ShaderTool.GetMatFromShader2("CompiledWhiteCapsPrecompute.shader"));


            m_initJacobiansMat.SetTexture("_Spectrum01", m_spectrum01);
            m_initJacobiansMat.SetTexture("_Spectrum23", m_spectrum23);
            m_initJacobiansMat.SetTexture("_WTable", m_WTable);
            m_initJacobiansMat.SetVector("_Offset", m_offset);
            m_initJacobiansMat.SetVector("_InverseGridSizes", m_inverseGridSizes);
        }
Пример #3
0
        //		protected override void Start()
        public override void Start()
        {
            base.Start();

            m_initJacobiansMat = new Material(ShaderTool.GetMatFromShader2("CompiledInitJacobians.shader"));
//			m_whiteCapsPrecomputeMat = new Material(ShaderTool.GetMatFromShader2("CompiledWhiteCapsPrecompute.shader")); //original shader
            m_whiteCapsPrecomputeMat = new Material(ShaderTool.GetMatFromShader2("CompiledWhiteCapsPrecompute0.shader"));            //shader with two passes, to fix black ocean bug


            m_initJacobiansMat.SetTexture(ShaderProperties._Spectrum01_PROPERTY, m_spectrum01);
            m_initJacobiansMat.SetTexture(ShaderProperties._Spectrum23_PROPERTY, m_spectrum23);
            m_initJacobiansMat.SetTexture(ShaderProperties._WTable_PROPERTY, m_WTable);
            m_initJacobiansMat.SetVector(ShaderProperties._Offset_PROPERTY, m_offset);
            m_initJacobiansMat.SetVector(ShaderProperties._InverseGridSizes_PROPERTY, m_inverseGridSizes);
        }
        void OnPreRender()
        {
//		if (!enabled || !gameObject.active) return;

            if (!_depthCam)
            {
                _depthCam = new GameObject("CustomDepthCamera");
                _depthCam.AddComponent <Camera>();
                _depthCam.camera.enabled = true;
                //_depthCam.hideFlags = HideFlags.HideAndDontSave;
//			_depthCam.camera.depthTextureMode = DepthTextureMode.None;

                depthShader = ShaderTool.GetShader2("CompiledDepthTexture.shader");

                viewCustomBufferShader = ShaderTool.GetMatFromShader2("CompiledviewCustomDepthTexture.shader");
                viewCustomBufferShader.SetTexture("_DepthTex", _depthTex);
            }

            _depthCam.camera.CopyFrom(inCamera);
            //_depthCam.camera.backgroundColor = new Color(0,0,0,0);
            //_depthCam.camera.clearFlags = CameraClearFlags.SolidColor;
            //_depthCam.camera.cullingMask = 1 << LayerMask.NameToLayer("Character1") |
            //	1 << LayerMask.NameToLayer("Character2");



            //inCamera.camera.SetReplacementShader(depthShader,"RenderType");

            //disable rendering of the custom depth buffer when away from PQS
            if (incore.pqsEnabled)
            {
                _depthCam.camera.targetTexture = _depthTex;

                _depthCam.camera.SetReplacementShader(depthShader, "RenderType");

                _depthCam.camera.RenderWithShader(depthShader, "RenderType");
            }
        }
Пример #5
0
        public virtual void UpdateNode()
        {
            if ((m_manager.m_skyNode.farCamera))
            {
                if (!oceanupdater)
                {
                    oceanupdater                   = (OceanUpdateAtCameraRythm)m_manager.m_skyNode.farCamera.gameObject.AddComponent(typeof(OceanUpdateAtCameraRythm));
                    oceanupdater.m_oceanNode       = this;
                    oceanupdater.farCamera         = m_manager.m_skyNode.farCamera;
                    oceanupdater.nearCamera        = m_manager.m_skyNode.nearCamera;
                    oceanupdater.oceanMaterialFar  = m_oceanMaterialFar;
                    oceanupdater.oceanMaterialNear = m_oceanMaterialNear;
                    oceanupdater.m_manager         = m_manager;
                }
            }


            m_drawOcean = m_manager.m_skyNode.trueAlt < fakeOceanAltitude;

//			if (!MapView.MapIsEnabled && !m_core.stockOcean && !m_manager.m_skyNode.inScaledSpace && (m_manager.m_skyNode.trueAlt < fakeOceanAltitude)) {
            if (!MapView.MapIsEnabled && !m_core.stockOcean && !m_manager.m_skyNode.inScaledSpace && m_drawOcean)
            {
                foreach (Mesh mesh in m_screenGrids)
                {
//					Graphics.DrawMesh(mesh, Vector3.zero, Quaternion.identity, m_oceanMaterialFar, 15, m_manager.m_skyNode.farCamera);
//					Graphics.DrawMesh(mesh, Vector3.zero, Quaternion.identity, m_oceanMaterialNear, 15, m_manager.m_skyNode.nearCamera);


                    Graphics.DrawMesh(mesh, Vector3.zero, Quaternion.identity, m_oceanMaterialFar, 15,
                                      m_manager.m_skyNode.farCamera, 0, null, false, false);

                    Graphics.DrawMesh(mesh, Vector3.zero, Quaternion.identity, m_oceanMaterialNear, 15,
                                      m_manager.m_skyNode.nearCamera, 0, null, false, false);
                }

//				Graphics.DrawMesh (fakeOceanMesh, Vector3.zero, Quaternion.identity, newMat, 15,
//				                   m_manager.m_skyNode.farCamera, 0, null, false, false);
            }


            if (!ocean && stockOceanExists)
            {
                PQS pqs = m_manager.parentCelestialBody.pqsController;
//
////				Debug.Log("PQS.childspheres count"+pqs.ChildSpheres.Length);
//
//
//				Debug.Log ("childspheres length"+pqs.ChildSpheres.Length.ToString());

                if (pqs.ChildSpheres [0])
                {
//					Debug.Log("pqs.ChildSpheres [0] found");
                    ocean         = pqs.ChildSpheres [0];
                    emptyMaterial = new Material(ShaderTool.GetMatFromShader2("EmptyShader.shader"));

//					fakeOceanMaterial = new Material (ShaderTool.GetMatFromShader2 ("CompiledFakeOcean.shader"));


//					m_manager.m_skyNode.InitUniforms(fakeOceanMaterial);
//					m_manager.m_skyNode.InitPostprocessMaterial(fakeOceanMaterial);

//					Debug.Log ("fake ocean mat set");
                    ocean.surfaceMaterial  = emptyMaterial;
                    ocean.fallbackMaterial = emptyMaterial;

//					ocean.surfaceMaterial = fakeOceanMaterial;
//					ocean.fallbackMaterial = fakeOceanMaterial;

                    ocean.useSharedMaterial = false;


//					oceanPC = new SimplePostProcessCube (20000, fakeOceanMaterial);
//					fakeOceanObject = oceanPC.GameObject;
//					fakeOceanObject.layer = 15;
//					fakeOceanMR = oceanPC.GameObject.GetComponent < MeshRenderer > ();
//					fakeOceanMR.material = fakeOceanMaterial;
//					oceanPC.GameObject.GetComponent < MeshFilter > ().mesh.Clear();
//					oceanPC.GameObject.GetComponent < MeshFilter > ().mesh = isosphere.Create(10000);
//
//					///Thanks to rbray89 for this snippet that disables the stock ocean in a clean way
//					GameObject container = ocean.gameObject;
//
//					FakeOceanPQS fakeOcean1 = new GameObject().AddComponent<FakeOceanPQS>();
//
//					fakeOcean1.CloneFrom(ocean);
//					Destroy(ocean);
//
//					FakeOceanPQS fakeOcean = container.AddComponent<FakeOceanPQS>();
//					fakeOcean.CloneFrom(fakeOcean1);
//
//					Destroy(fakeOcean1);
//
//					FieldInfo field = typeof(PQS).GetFields(BindingFlags.Instance | BindingFlags.NonPublic).First(
//						f => f.FieldType == typeof(PQS[]));
//					field.SetValue(pqs, new PQS[] {fakeOcean });
//
//					PQSMod_CelestialBodyTransform cbt = pqs.GetComponentsInChildren<PQSMod_CelestialBodyTransform>()[0];
//					cbt.secondaryFades = new PQSMod_CelestialBodyTransform.AltitudeFade[] { };

                    stockOceanExists = false;
                }
                else
                {
                    stockOceanExists = false;
                    Debug.Log("[Scatterer] Stock ocean doesn't exist for " + m_manager.parentCelestialBody.name);
                }
            }

            if (ocean)
            {
                ocean.surfaceMaterial   = emptyMaterial;
                ocean.fallbackMaterial  = emptyMaterial;
                ocean.useSharedMaterial = false;

//				ocean.surfaceMaterial = fakeOceanMaterial;
//				ocean.fallbackMaterial = fakeOceanMaterial;
//				ocean.useSharedMaterial = false;

//				fakeOceanMaterial.SetVector ("_planetPos", m_manager.parentCelestialBody.transform.position);
//				fakeOceanMaterial.SetVector ("_cameraPos", m_manager.GetCore().farCamera.transform.position - m_manager.parentCelestialBody.transform.position);
//				fakeOceanMaterial.SetVector ("_Ocean_Color", new Color (m_oceanUpwellingColor.x, m_oceanUpwellingColor.y, m_oceanUpwellingColor.z) * 0.1f);
//				fakeOceanMaterial.SetFloat ("_Ocean_Sigma", GetMaxSlopeVariance ());
////				fakeOceanMaterial.SetMatrix ("_PlanetToWorld", m_manager.parentCelestialBody.transform.localToWorldMatrix);
//
//
//
//
//
////				fakeOceanMaterial.SetMatrix ("_PlanetToWorld", camToLocal.ToMatrix4x4());
//				fakeOceanMaterial.SetMatrix ("_WorldToPlanet", m_manager.parentCelestialBody.transform.worldToLocalMatrix);
//
//
////				fakeOceanMaterial.SetVector ("SUN_DIR", m_manager.GetSunNodeDirection ());
//				m_manager.m_skyNode.SetUniforms(fakeOceanMaterial);
//				m_manager.m_skyNode.InitPostprocessMaterial(fakeOceanMaterial);
//				m_manager.m_skyNode.UpdatePostProcessMaterial(fakeOceanMaterial);
//
//
//				fakeOceanObject.transform.position= FlightGlobals.ActiveVessel.transform.position;
            }



            m_oceanMaterialNear.renderQueue = m_manager.GetCore().oceanRenderQueue;
            m_oceanMaterialFar.renderQueue  = m_manager.GetCore().oceanRenderQueue;



            if (stockOceanExists)
            {
                //This causes problems later on
//				ocean.quadAllowBuild = false;
//				int deletedQuads=ocean.quads.Length;
//
//				if (deletedQuads>0){
//
//					for (int i=0;i<ocean.quads.Length;i++)
//					{
//						if (ocean.quads[i])
//							UnityEngine.Object.Destroy(ocean.quads[i]);
//					}
//
//					ocean.quads = Array.FindAll(ocean.quads, PQisNotNull);
////					deletedQuads-=ocean.quads.Length;
//
//						Debug.Log("[Scatterer] Destroyed "+deletedQuads.ToString()+" stock ocean quads on "
//					              +m_manager.parentCelestialBody.name);
//
//				}


//				ocean.quads= new PQ[10];

//				ocean.DeactivateSphere();
//				ocean.DisableSphere();
//				ocean.surfaceMaterial=new Material(ShaderTool.GetMatFromShader2("EmptyShader.shader"));
//				Debug.Log("ocean.subdivisionThreshold"+ ocean.subdivisionThreshold.ToString());
//				Debug.Log("ocean.maxDetailDistance"+ ocean.maxDetailDistance.ToString());
            }

//
////				ocean.quadAllowBuild=false;
//				Debug.Log("ocean.visRad"+ ocean.visRad);
//				Debug.Log("ocean.visibleRadius"+ ocean.visibleRadius.ToString());
//				Debug.Log("ocean.visibleAltitude"+ ocean.visibleAltitude.ToString());
////				Debug.Log("ocean.useSharedMaterial"+ ocean.useSharedMaterial.ToString());
////				Debug.Log("ocean.surfaceMaterial"+ ocean.surfaceMaterial.ToString());
//				Debug.Log("ocean.subdivisionThresholds"+ ocean.subdivisionThresholds.ToString());
//				Debug.Log("ocean.subdivisionThreshold"+ ocean.subdivisionThreshold.ToString());
////				Debug.Log("ocean.radiusMi"+ ocean.radiusMin.ToString());
////				Debug.Log("ocean.radiusMax"+ ocean.radiusMax.ToString());
////				Debug.Log("ocean.quadAllowBuild"+ ocean.quadAllowBuild.ToString());
//				Debug.Log("ocean.maxDetailDistance"+ ocean.maxDetailDistance.ToString());
//				Debug.Log("ocean.detailAltitudeMax"+ ocean.detailAltitudeMax.ToString());
////						}



//						ocean.isDisabled = true;
//						ocean.DisableSphere ();
//						ocean.isDisabled = !m_core.stockOcean;
//
//						if (!m_core.stockOcean)
//						{
//							ocean.DisableSphere ();
//						}
//						else
//						{
//							ocean.EnableSphere ();
//						}


//						for(int i = 0; i < numGrids; i++)
//						{
//							waterMeshRenderersNear[i].enabled=!m_core.stockOcean && !MapView.MapIsEnabled;
//							waterMeshRenderersFar[i].enabled=!m_core.stockOcean && !MapView.MapIsEnabled ;
//						}
        }
Пример #6
0
        // Use this for initialization
        public virtual void Start()
        {
            m_cameraToWorldMatrix = Matrix4x4d.Identity();

            //using different materials for both the far and near cameras because they have different projection matrixes
            //the projection matrix in the shader has to match that of the camera or the projection will be wrong and the ocean will
            //appear to "shift around"
            m_oceanMaterialNear = new Material(ShaderTool.GetMatFromShader2("CompiledOceanWhiteCaps.shader"));
            m_oceanMaterialFar  = new Material(ShaderTool.GetMatFromShader2("CompiledOceanWhiteCaps.shader"));

            m_manager.GetSkyNode().InitUniforms(m_oceanMaterialNear);
            m_manager.GetSkyNode().InitUniforms(m_oceanMaterialFar);

            m_oldlocalToOcean = Matrix4x4d.Identity();
            m_oldworldToOcean = Matrix4x4d.Identity();
            m_offset          = Vector3d2.Zero();

            //Create the projected grid. The resolution is the size in pixels
            //of each square in the grid. If the squares are small the size of
            //the mesh will exceed the max verts for a mesh in Unity. In this case
            //split the mesh up into smaller meshes.

            m_resolution = Mathf.Max(1, m_resolution);
            //The number of squares in the grid on the x and y axis
            int NX = Screen.width / m_resolution;
            int NY = Screen.height / m_resolution;

            numGrids = 1;

            //			const int MAX_VERTS = 65000;
            //The number of meshes need to make a grid of this resolution
            if (NX * NY > MAX_VERTS)
            {
                numGrids += (NX * NY) / MAX_VERTS;
            }

            m_screenGrids = new Mesh[numGrids];

//			waterGameObjectsNear = new GameObject[numGrids];
//			waterMeshRenderersNear = new MeshRenderer[numGrids];
//			waterMeshFiltersNear = new MeshFilter[numGrids];
//
//			waterGameObjectsFar = new GameObject[numGrids];
//			waterMeshRenderersFar = new MeshRenderer[numGrids];
//			waterMeshFiltersFar = new MeshFilter[numGrids];

            //Make the meshes. The end product will be a grid of verts that cover
            //the screen on the x and y axis with the z depth at 0. This grid is then
            //projected as the ocean by the shader
            for (int i = 0; i < numGrids; i++)
            {
                NY = Screen.height / numGrids / m_resolution;

                m_screenGrids [i]        = MakePlane(NX, NY, (float)i / (float)numGrids, 1.0f / (float)numGrids);
                m_screenGrids [i].bounds = new Bounds(Vector3.zero, new Vector3(1e8f, 1e8f, 1e8f));


                //bad idea, the meshes still render arbitrarily to the near and far camera and end up drawing over everything
                //to get around this I use drawmesh further down
                //seems to have better performance also

//								waterGameObjectsNear[i] = new GameObject();
//								waterGameObjectsNear[i].transform.parent=m_manager.parentCelestialBody.transform;
//								waterMeshFiltersNear[i] = waterGameObjectsNear[i].AddComponent<MeshFilter>();
//								waterMeshFiltersNear[i].mesh.Clear ();
//								waterMeshFiltersNear[i].mesh = m_screenGrids[i];
//								waterGameObjectsNear[i].layer = 15;
//
//								waterMeshRenderersNear[i] = waterGameObjectsNear[i].AddComponent<MeshRenderer>();
//
//								waterMeshRenderersNear[i].sharedMaterial = m_oceanMaterialNear;
//								waterMeshRenderersNear[i].material =m_oceanMaterialNear;
//
//								waterMeshRenderersNear[i].castShadows = false;
//								waterMeshRenderersNear[i].receiveShadows = false;
//
//								waterMeshRenderersNear[i].enabled=true;
//
//
//				waterGameObjectsFar[i] = new GameObject();
//				waterGameObjectsFar[i].transform.parent=m_manager.parentCelestialBody.transform;
//				waterMeshFiltersFar[i] = waterGameObjectsFar[i].AddComponent<MeshFilter>();
//				waterMeshFiltersFar[i].mesh.Clear ();
//				waterMeshFiltersFar[i].mesh = m_screenGrids[i];
//				waterGameObjectsFar[i].layer = 15;
//
//				waterMeshRenderersFar[i] = waterGameObjectsFar[i].AddComponent<MeshRenderer>();
//
//				waterMeshRenderersFar[i].sharedMaterial = m_oceanMaterialFar;
//				waterMeshRenderersFar[i].material =m_oceanMaterialFar;
//
//				waterMeshRenderersFar[i].castShadows = false;
//				waterMeshRenderersFar[i].receiveShadows = false;
//
//				waterMeshRenderersFar[i].enabled=true;
            }

//			PQS pqs = m_manager.parentCelestialBody.pqsController;
//
//			if (pqs.ChildSpheres[0])
//				UnityEngine.Object.Destroy (pqs.ChildSpheres [0]);

//			if (ocean)
//			{
//				UnityEngine.Object.Destroy (ocean);
//			}



            //				Debug.Log("PQS.childspheres count"+pqs.ChildSpheres.Length);

//			PQS pqs = m_manager.parentCelestialBody.pqsController;
//			if (pqs.ChildSpheres [0]) {
//				ocean = pqs.ChildSpheres [0];
//				//					ocean.surfaceMaterial = new Material (ShaderTool.GetMatFromShader2 ("EmptyShader.shader"));
//
//				///Thanks to rbray89 for this snippet that disables the stock ocean in a clean way
//				GameObject container = ocean.gameObject;
//
//				FakeOceanPQS fakeOcean1 = new GameObject ().AddComponent<FakeOceanPQS> ();
//
//				fakeOcean1.CloneFrom (ocean);
//				Destroy (ocean);
//
//				FakeOceanPQS fakeOcean = container.AddComponent<FakeOceanPQS> ();
//				fakeOcean.CloneFrom (fakeOcean1);
//
//				Destroy (fakeOcean1);
//
//				FieldInfo field = typeof(PQS).GetFields (BindingFlags.Instance | BindingFlags.NonPublic).First (
//					f => f.FieldType == typeof(PQS[]));
//				field.SetValue (pqs, new PQS[] {fakeOcean });
//
//				PQSMod_CelestialBodyTransform cbt = pqs.GetComponentsInChildren<PQSMod_CelestialBodyTransform> () [0];
//				cbt.secondaryFades = new PQSMod_CelestialBodyTransform.AltitudeFade[] { };
//			}


//			fakeOceanMesh = isosphere.Create (m_manager.GetRadius());
//
//
//			fakeOcean = new GameObject ();
//			fakeOceanMF = fakeOcean.AddComponent<MeshFilter>();
//			fakeOceanMF.mesh = fakeOceanMesh;
//			fakeOcean.layer = 15;
//
//
//			fakeOcean.transform.parent = m_manager.parentCelestialBody.transform;
//
//			fakeOceanMR = fakeOcean.AddComponent<MeshRenderer>();
//
//			newMat = new Material (ShaderTool.GetMatFromShader2 ("BlackShader.shader"));
//			fakeOceanMR.sharedMaterial = newMat;
//			fakeOceanMR.material =newMat;
//
//			fakeOceanMR.castShadows = false;
//			fakeOceanMR.receiveShadows = false;
        }
Пример #7
0
 void Start()
 {
     toneMappingMaterial = ShaderTool.GetMatFromShader2("CompiledToneMapper.shader");
     //		GetComponent<Camera>().depthTextureMode |= DepthTextureMode.DepthNormals;
     GetComponent <Camera> ().hdr = true;
 }
Пример #8
0
        // Use this for initialization
        public virtual void Start()
        {
//			m_cameraToWorldMatrix = Matrix4x4d.Identity ();
//
            //using different materials for both the far and near cameras because they have different projection matrixes
            //the projection matrix in the shader has to match that of the camera or the projection will be wrong and the ocean will
            //appear to "shift around"
//			m_oceanMaterialNear = new Material (ShaderTool.GetMatFromShader2 ("CompiledOceanWhiteCaps.shader"));

            if (m_core.oceanPixelLights)
            {
                m_oceanMaterialFar = new Material(ShaderTool.GetMatFromShader2("CompiledOceanWhiteCapsPixelLights.shader"));
            }
            else
            {
                m_oceanMaterialFar = new Material(ShaderTool.GetMatFromShader2("CompiledOceanWhiteCaps.shader"));
            }

            if (m_core.oceanSkyReflections)
            {
                m_oceanMaterialFar.EnableKeyword("SKY_REFLECTIONS_ON");
                m_oceanMaterialFar.DisableKeyword("SKY_REFLECTIONS_OFF");
            }
            else
            {
                m_oceanMaterialFar.EnableKeyword("SKY_REFLECTIONS_OFF");
                m_oceanMaterialFar.DisableKeyword("SKY_REFLECTIONS_ON");
            }


//			m_manager.GetSkyNode ().InitUniforms (m_oceanMaterialNear);
            m_manager.GetSkyNode().InitUniforms(m_oceanMaterialFar);

            m_oldlocalToOcean = Matrix4x4d.Identity();
//			m_oldworldToOcean = Matrix4x4d.Identity ();
            m_offset = Vector3d2.Zero();

            //Create the projected grid. The resolution is the size in pixels
            //of each square in the grid. If the squares are small the size of
            //the mesh will exceed the max verts for a mesh in Unity. In this case
            //split the mesh up into smaller meshes.

            m_resolution = Mathf.Max(1, m_resolution);
            //The number of squares in the grid on the x and y axis
            int NX = Screen.width / m_resolution;
            int NY = Screen.height / m_resolution;

            numGrids = 1;

            //			const int MAX_VERTS = 65000;
            //The number of meshes need to make a grid of this resolution
            if (NX * NY > MAX_VERTS)
            {
                numGrids += (NX * NY) / MAX_VERTS;
            }

            m_screenGrids = new Mesh[numGrids];

            waterGameObjects   = new GameObject[numGrids];
            waterMeshRenderers = new MeshRenderer[numGrids];
            waterMeshFilters   = new MeshFilter[numGrids];

            //Make the meshes. The end product will be a grid of verts that cover
            //the screen on the x and y axis with the z depth at 0. This grid is then
            //projected as the ocean by the shader
            for (int i = 0; i < numGrids; i++)
            {
                NY = Screen.height / numGrids / m_resolution;

                m_screenGrids [i]        = MakePlane(NX, NY, (float)i / (float)numGrids, 1.0f / (float)numGrids);
                m_screenGrids [i].bounds = new Bounds(Vector3.zero, new Vector3(1e8f, 1e8f, 1e8f));


                waterGameObjects[i] = new GameObject();
                waterGameObjects[i].transform.parent = m_manager.parentCelestialBody.transform;               //might be redundant
                waterMeshFilters[i] = waterGameObjects[i].AddComponent <MeshFilter>();
                waterMeshFilters[i].mesh.Clear();
                waterMeshFilters[i].mesh = m_screenGrids[i];

                waterGameObjects[i].layer = 15;
                waterMeshRenderers[i]     = waterGameObjects[i].AddComponent <MeshRenderer>();


                waterMeshRenderers[i].sharedMaterial = m_oceanMaterialFar;
                waterMeshRenderers[i].material       = m_oceanMaterialFar;

                waterMeshRenderers[i].shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
                waterMeshRenderers[i].receiveShadows    = false;

//				CommandBufferModifiedProjectionMatrix tmp = waterGameObjects[i].AddComponent<CommandBufferModifiedProjectionMatrix>();
//				tmp.m_core=m_core;

                waterMeshRenderers[i].enabled = true;
            }

            cbProjectionMat        = waterGameObjects[0].AddComponent <CommandBufferModifiedProjectionMatrix>();
            cbProjectionMat.m_core = m_core;
        }
Пример #9
0
        public void start()
        {
            sunglareMaterial = new Material(ShaderTool.GetMatFromShader2("CompiledSunGlare.shader"));

            //Size is loaded automatically from the files
            sunSpikes = new Texture2D(1, 1);
            sunFlare  = new Texture2D(1, 1);
            sunGhost1 = new Texture2D(1, 1);
            sunGhost2 = new Texture2D(1, 1);
            sunGhost3 = new Texture2D(1, 1);


            sunSpikes.LoadImage(System.IO.File.ReadAllBytes(String.Format("{0}/{1}", inCore.path + "/sunflare", "sunSpikes.png")));
            sunSpikes.wrapMode = TextureWrapMode.Clamp;
            sunFlare.LoadImage(System.IO.File.ReadAllBytes(String.Format("{0}/{1}", inCore.path + "/sunflare", "sunFlare.png")));
            sunFlare.wrapMode = TextureWrapMode.Clamp;
            sunGhost1.LoadImage(System.IO.File.ReadAllBytes(String.Format("{0}/{1}", inCore.path + "/sunflare", "Ghost1.png")));
            sunGhost1.wrapMode = TextureWrapMode.Clamp;
            sunGhost2.LoadImage(System.IO.File.ReadAllBytes(String.Format("{0}/{1}", inCore.path + "/sunflare", "Ghost2.png")));
            sunGhost2.wrapMode = TextureWrapMode.Clamp;
            sunGhost3.LoadImage(System.IO.File.ReadAllBytes(String.Format("{0}/{1}", inCore.path + "/sunflare", "Ghost3.png")));
            sunGhost3.wrapMode = TextureWrapMode.Clamp;

//			sunglareMaterial.SetTexture ("_Sun_Glare", sunGlare);
            sunglareMaterial.SetTexture("sunSpikes", sunSpikes);
            sunglareMaterial.SetTexture("sunFlare", sunFlare);
            sunglareMaterial.SetTexture("sunGhost1", sunGhost1);
            sunglareMaterial.SetTexture("sunGhost2", sunGhost2);
            sunglareMaterial.SetTexture("sunGhost3", sunGhost3);

            sunglareMaterial.SetTexture("_customDepthTexture", inCore.customDepthBufferTexture);

            sunglareMaterial.renderQueue = 3100;

            screenMesh        = MeshFactory.MakePlane(2, 2, MeshFactory.PLANE.XY, false, false);
            screenMesh.bounds = new Bounds(Vector4.zero, new Vector3(Mathf.Infinity, Mathf.Infinity, Mathf.Infinity));

            Sun.Instance.sunFlare.enabled = false;


            loadConfigNode();

            //didn't want to serialize the matrices directly as the result is pretty unreadable
            //sorry about the mess, I'll make a cleaner way later
            //ghost 1
            Matrix4x4 ghost1Settings1 = Matrix4x4.zero;

            for (int i = 0; i < ghost1SettingsList1.Count; i++)
            {
                ghost1Settings1.SetRow(i, ghost1SettingsList1[i]);
            }
            Matrix4x4 ghost1Settings2 = Matrix4x4.zero;

            for (int i = 0; i < ghost1SettingsList2.Count; i++)
            {
                ghost1Settings2.SetRow(i, ghost1SettingsList2[i]);
            }

            //ghost 2
            Matrix4x4 ghost2Settings1 = Matrix4x4.zero;

            for (int i = 0; i < ghost2SettingsList1.Count; i++)
            {
                ghost2Settings1.SetRow(i, ghost2SettingsList1[i]);
            }
            Matrix4x4 ghost2Settings2 = Matrix4x4.zero;

            for (int i = 0; i < ghost2SettingsList2.Count; i++)
            {
                ghost2Settings2.SetRow(i, ghost2SettingsList2[i]);
            }

            //ghost 3
            Matrix4x4 ghost3Settings1 = Matrix4x4.zero;

            for (int i = 0; i < ghost3SettingsList1.Count; i++)
            {
                ghost3Settings1.SetRow(i, ghost3SettingsList1[i]);
            }
            Matrix4x4 ghost3Settings2 = Matrix4x4.zero;

            for (int i = 0; i < ghost3SettingsList2.Count; i++)
            {
                ghost3Settings2.SetRow(i, ghost3SettingsList2[i]);
            }


            sunglareMaterial.SetVector("flareSettings", flareSettings);
            sunglareMaterial.SetVector("spikesSettings", spikesSettings);

            sunglareMaterial.SetMatrix("ghost1Settings1", ghost1Settings1);
            sunglareMaterial.SetMatrix("ghost1Settings2", ghost1Settings2);

            sunglareMaterial.SetMatrix("ghost2Settings1", ghost2Settings1);
            sunglareMaterial.SetMatrix("ghost2Settings2", ghost2Settings2);

            sunglareMaterial.SetMatrix("ghost3Settings1", ghost3Settings1);
            sunglareMaterial.SetMatrix("ghost3Settings2", ghost3Settings2);

            Debug.Log("[Scatterer] added custom sun flare");
        }
Пример #10
0
 void Start()
 {
     toneMappingMaterial = new Material(ShaderTool.GetMatFromShader2("CompiledToneMapper.shader"));
 }
Пример #11
0
        void Start()
        {
            m_depthBufferShader = ShaderTool.GetMatFromShader2("CompiledViewDepthBuffer.shader");
//		GetComponent<Camera>().depthTextureMode |= DepthTextureMode.DepthNormals;
            GetComponent <Camera>().depthTextureMode |= DepthTextureMode.Depth;
        }