SetMatrix() public méthode

Set a named matrix for the shader.

public SetMatrix ( int nameID, Matrix4x4 matrix ) : void
nameID int Property name ID, use Shader.PropertyToID to get it.
matrix Matrix4x4 Matrix value to set.
Résultat void
Exemple #1
0
 static public int SetMatrix(IntPtr l)
 {
     try{
         if (matchType(l, 2, typeof(System.String), typeof(UnityEngine.Matrix4x4)))
         {
             UnityEngine.Material self = (UnityEngine.Material)checkSelf(l);
             System.String        a1;
             checkType(l, 2, out a1);
             UnityEngine.Matrix4x4 a2;
             checkType(l, 3, out a2);
             self.SetMatrix(a1, a2);
             return(0);
         }
         else if (matchType(l, 2, typeof(System.Int32), typeof(UnityEngine.Matrix4x4)))
         {
             UnityEngine.Material self = (UnityEngine.Material)checkSelf(l);
             System.Int32         a1;
             checkType(l, 2, out a1);
             UnityEngine.Matrix4x4 a2;
             checkType(l, 3, out a2);
             self.SetMatrix(a1, a2);
             return(0);
         }
         LuaDLL.luaL_error(l, "No matched override function to call");
         return(0);
     }
     catch (Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return(0);
     }
 }
    static int SetMatrix(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 3 && TypeChecker.CheckTypes(L, 1, typeof(UnityEngine.Material), typeof(int), typeof(UnityEngine.Matrix4x4)))
            {
                UnityEngine.Material obj = (UnityEngine.Material)ToLua.ToObject(L, 1);
                int arg0 = (int)LuaDLL.lua_tonumber(L, 2);
                UnityEngine.Matrix4x4 arg1 = (UnityEngine.Matrix4x4)ToLua.ToObject(L, 3);
                obj.SetMatrix(arg0, arg1);
                return(0);
            }
            else if (count == 3 && TypeChecker.CheckTypes(L, 1, typeof(UnityEngine.Material), typeof(string), typeof(UnityEngine.Matrix4x4)))
            {
                UnityEngine.Material obj = (UnityEngine.Material)ToLua.ToObject(L, 1);
                string arg0 = ToLua.ToString(L, 2);
                UnityEngine.Matrix4x4 arg1 = (UnityEngine.Matrix4x4)ToLua.ToObject(L, 3);
                obj.SetMatrix(arg0, arg1);
                return(0);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: UnityEngine.Material.SetMatrix"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
Exemple #3
0
 static public int SetMatrix(IntPtr l)
 {
     try {
         int argc = LuaDLL.lua_gettop(l);
         if (matchType(l, argc, 2, typeof(int), typeof(UnityEngine.Matrix4x4)))
         {
             UnityEngine.Material self = (UnityEngine.Material)checkSelf(l);
             System.Int32         a1;
             checkType(l, 2, out a1);
             UnityEngine.Matrix4x4 a2;
             checkValueType(l, 3, out a2);
             self.SetMatrix(a1, a2);
             pushValue(l, true);
             return(1);
         }
         else if (matchType(l, argc, 2, typeof(string), typeof(UnityEngine.Matrix4x4)))
         {
             UnityEngine.Material self = (UnityEngine.Material)checkSelf(l);
             System.String        a1;
             checkType(l, 2, out a1);
             UnityEngine.Matrix4x4 a2;
             checkValueType(l, 3, out a2);
             self.SetMatrix(a1, a2);
             pushValue(l, true);
             return(1);
         }
         pushValue(l, false);
         LuaDLL.lua_pushstring(l, "No matched override function to call");
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Exemple #4
0
 public static void RenderDistortion(Material material, RenderTexture source, RenderTexture destination, float angle, Vector2 center, Vector2 radius)
 {
     bool flag = source.texelSize.y < 0f;
     if (flag)
     {
         center.y = 1f - center.y;
         angle = -angle;
     }
     Matrix4x4 matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(0f, 0f, angle), Vector3.one);
     material.SetMatrix("_RotationMatrix", matrix);
     material.SetVector("_CenterRadius", new Vector4(center.x, center.y, radius.x, radius.y));
     material.SetFloat("_Angle", angle * 0.0174532924f);
     Graphics.Blit(source, destination, material);
 }
    public static void RenderDistortion(Material material, RenderTexture source, RenderTexture destination, float angle, Vector2 center, Vector2 radius)
    {
        bool invertY = source.texelSize.y < 0.0f;
        if (invertY)
        {
            center.y = 1.0f - center.y;
            angle = -angle;
        }

        Matrix4x4 rotationMatrix = Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(0, 0, angle), Vector3.one);

        material.SetMatrix("_RotationMatrix", rotationMatrix);
        material.SetVector("_CenterRadius", new Vector4(center.x, center.y, radius.x, radius.y));
        material.SetFloat("_Angle", angle * Mathf.Deg2Rad);

        Graphics.Blit(source, destination, material);
    }
    public void UpdateMaterial(RaycastHit hit)
    {
        var hitGO = hit.transform;
        if (hitGO!=null) {
          if (!RemoveWhenDisable) Destroy(gameObject, RemoveAfterTime);
          fadeInOutShaderColor = GetComponents<FadeInOutShaderColor>();
          fadeInOutShaderFloat = GetComponents<FadeInOutShaderFloat>();
          uvTextureAnimator = GetComponent<UVTextureAnimator>();
          renderParent = transform.parent.GetComponent<Renderer>();

          var materials = renderParent.sharedMaterials;
          var length = materials.Length + 1;
          var newMaterials = new Material[length];

          materials.CopyTo(newMaterials, 0);
          renderParent.material = Material;
          instanceMat = renderParent.material;
          newMaterials[length - 1] = instanceMat;
          renderParent.sharedMaterials = newMaterials;

          if (UsePointMatrixTransform) {
        var m = Matrix4x4.TRS(hit.transform.InverseTransformPoint(hit.point), Quaternion.Euler(180, 180, 0f), TransformScale);
        //m *= transform.localToWorldMatrix;
        instanceMat.SetMatrix("_DecalMatr", m);
          }
          if (materialQueue!=-1)
        instanceMat.renderQueue = materialQueue;

          if (fadeInOutShaderColor!=null) {
        foreach (var inOutShaderColor in fadeInOutShaderColor) {
          inOutShaderColor.UpdateMaterial(instanceMat);
        }
          }

          if (fadeInOutShaderFloat!=null) {
        foreach (var inOutShaderFloat in fadeInOutShaderFloat) {
          inOutShaderFloat.UpdateMaterial(instanceMat);
        }
          }

          if (uvTextureAnimator!=null)
        uvTextureAnimator.SetInstanceMaterial(instanceMat, hit.textureCoord);
        }
    }
        private void convolve_internal(Texture dstTex, Texture srcCube, bool dstRGBM, bool srcRGBM, bool linear, Camera cam, Material skyMat, Matrix4x4 matrix)
        {
            bool prevHDR = cam.hdr;
            CameraClearFlags prevFlags = cam.clearFlags;
            int prevMask = cam.cullingMask;
            cam.clearFlags = CameraClearFlags.Skybox;
            cam.cullingMask = 0;
            cam.hdr = !dstRGBM; // might need HDR camera buffer when we're not rendering to RGBM encoded pixels

            skyMat.name = "Internal Convolve Skybox";
            skyMat.shader = Shader.Find("Hidden/Marmoset/RGBM Convolve");

            //toggleKeywordPair("MARMO_LINEAR", "MARMO_GAMMA", linear);
            toggleKeywordPair("MARMO_RGBM_INPUT_ON", "MARMO_RGBM_INPUT_OFF", srcRGBM);
            toggleKeywordPair("MARMO_RGBM_OUTPUT_ON", "MARMO_RGBM_OUTPUT_OFF", dstRGBM);

            skyMat.SetMatrix("_SkyMatrix", matrix);
            skyMat.SetTexture("_CubeHDR", srcCube);
            bindRandomValueTable(skyMat,"_PhongRands", srcCube.width);

            Material prevSkyMat = UnityEngine.RenderSettings.skybox;
            UnityEngine.RenderSettings.skybox = skyMat;

            Cubemap dstCube = dstTex as Cubemap;
            RenderTexture dstRT = dstTex as RenderTexture;

            if( dstCube ) {
                if( generateMipChain ) {
                    int mipCount = mset.QPow.Log2i(dstCube.width) - 1;
                    int mip = highestMipIsMirror ? 1 : 0;
                    for( ; mip<mipCount; ++mip ) {
                        int mipSize = 1 << (mipCount-mip);
                        float mipExp = mset.QPow.clampedDownShift(this.maxExponent, highestMipIsMirror ? (mip-1) : mip, 1);
                        skyMat.SetFloat("_SpecularExp", mipExp);
                        skyMat.SetFloat ("_SpecularScale", this.convolutionScale);
                        Cubemap mipCube = new Cubemap(mipSize, dstCube.format, false);
                        cam.RenderToCubemap(mipCube);

                        for(int f=0; f<6; ++f) {
                            CubemapFace face = (CubemapFace)f;
                            dstCube.SetPixels(mipCube.GetPixels(face), face, mip);
                        }
                        Cubemap.DestroyImmediate(mipCube);
                    }
                    dstCube.Apply(false);
                } else {
                    skyMat.SetFloat("_SpecularExp", this.maxExponent);
                    skyMat.SetFloat ("_SpecularScale", this.convolutionScale);
                    cam.RenderToCubemap(dstCube);
                }
            } else if(dstRT) {
                skyMat.SetFloat("_SpecularExp", this.maxExponent);
                skyMat.SetFloat ("_SpecularScale", this.convolutionScale);
                cam.RenderToCubemap(dstRT);
            }

            cam.clearFlags = prevFlags;
            cam.cullingMask = prevMask;
            cam.hdr = prevHDR;
            UnityEngine.RenderSettings.skybox = prevSkyMat;
        }
        public void Apply(CloudsMaterial material, float radius, Transform parent)
        {
            Remove();
            particleMaterial.MaxScale = size.y;
            particleMaterial.MaxTrans = maxTranslation;
            particleMaterial.NoiseScale =  new Vector3(noiseScale.x, noiseScale.y, noiseScale.z / radius);
            ParticleMaterial = new Material(ParticleCloudShader);
            particleMaterial.ApplyMaterialProperties(ParticleMaterial);
            material.ApplyMaterialProperties(ParticleMaterial);
            ParticleMaterial.EnableKeyword("SOFT_DEPTH_ON");

            volumeHolder = new GameObject();
            //Add the renderer here so othe rentities (shadows)
            //can easily access it.
            Renderer r = volumeHolder.AddComponent<MeshRenderer>();
            r.material = ParticleMaterial;
            ParticleMaterial.SetMatrix(ShaderProperties._ShadowBodies_PROPERTY, Matrix4x4.zero);
            ParticleMaterial.renderQueue = (int)Tools.Queue.Transparent + 2;

            r.enabled = false;
            volumeHolder.transform.parent = parent;
            volumeHolder.transform.localPosition = Vector3.zero;
            volumeHolder.transform.localScale = Vector3.one;
            volumeHolder.transform.localRotation = Quaternion.identity;
            volumeHolder.layer = (int)Tools.Layer.Local;
            volumeManager = new VolumeManager(radius, size, ParticleMaterial, volumeHolder.transform, area.x, (int)area.y);
            
        }
	void SetFrustumRays(Material material)
	{
		Matrix4x4 frustumRays;
		Vector3 cameraPosLocal;
		GetFrustumRays(out frustumRays, out cameraPosLocal);
		material.SetVector("_CameraPosLocal", cameraPosLocal);
		material.SetMatrix("_FrustumRays", frustumRays);
		material.SetFloat("_FrustumApex", GetFrustumApex());
	}
Exemple #10
0
        public void SetUniforms(Material mat)
        {
            //Sets uniforms that this or other gameobjects may need
            if (mat == null) return;

            mat.SetFloat("_Extinction_Cutoff", ExtinctionCutoff);
            if (!MapView.MapIsEnabled) {
            mat.SetFloat("_Alpha_Global", alphaGlobal);
            mat.SetFloat("_Extinction_Tint", extinctionTint);
            mat.SetFloat("extinctionMultiplier", extinctionMultiplier);
            } else {
            mat.SetFloat("_Alpha_Global", mapAlphaGlobal);
            mat.SetFloat("_Extinction_Tint", mapExtinctionTint);
            mat.SetFloat("extinctionMultiplier", mapExtinctionMultiplier);
            }

            mat.SetFloat("scale", atmosphereGlobalScale);
            mat.SetFloat("Rg", Rg * atmosphereGlobalScale);
            mat.SetFloat("Rt", Rt * atmosphereGlobalScale);
            mat.SetFloat("RL", RL * atmosphereGlobalScale);

            //						if (debugSettings [5])
            if (!MapView.MapIsEnabled) {
            mat.SetFloat("_Globals_ApparentDistance", 1f);
            } else {
            mat.SetFloat("_Globals_ApparentDistance", (float)((parentCelestialBody.Radius / 100.2f) / MapViewScale));
            //				mat.SetFloat ("_Globals_ApparentDistance", MapViewScale);
            }

            //						if (debugSettings[1])
            if (!MapView.MapIsEnabled) {

            mat.SetMatrix("_Globals_WorldToCamera", farCamera.worldToCameraMatrix);
            mat.SetMatrix("_Globals_CameraToWorld", farCamera.worldToCameraMatrix.inverse);
            } else {
            mat.SetMatrix("_Globals_WorldToCamera", scaledSpaceCamera.worldToCameraMatrix);
            mat.SetMatrix("_Globals_CameraToWorld", scaledSpaceCamera.worldToCameraMatrix.inverse);
            }

            mat.SetVector("betaR", m_betaR / 1000.0f);
            mat.SetFloat("mieG", Mathf.Clamp(m_mieG, 0.0f, 0.99f));
            mat.SetTexture("_Sky_Transmittance", m_transmit);
            mat.SetTexture("_Sky_Inscatter", m_inscatter);
            mat.SetTexture("_Sky_Irradiance", m_irradiance);
            mat.SetFloat("_Sun_Intensity", 100f);
            mat.SetVector("_Sun_WorldSunDir", m_manager.getDirectionToSun().normalized);
            //			mat.SetVector("_Sun_WorldSunDir", m_manager.getDirectionToSun());

            //			//copied from m_manager's set uniforms

            //Matrix4x4 p;
            //						if (debugSettings [2])
            if (!MapView.MapIsEnabled) {
            p = farCamera.projectionMatrix;
            } else {
            p = scaledSpaceCamera.projectionMatrix;
            }

            m_cameraToScreenMatrix = new Matrix4x4d(p);
            mat.SetMatrix("_Globals_CameraToScreen", m_cameraToScreenMatrix.ToMatrix4x4());
            mat.SetMatrix("_Globals_ScreenToCamera", m_cameraToScreenMatrix.Inverse().ToMatrix4x4());

            //						if (debugSettings [3])
            if (!MapView.MapIsEnabled) {
            mat.SetVector("_Globals_WorldCameraPos", farCamera.transform.position);
            } else {
            mat.SetVector("_Globals_WorldCameraPos", scaledSpaceCamera.transform.position);
            }
            //			else
            //			{
            //				Vector3 newpos= ScaledSpace.ScaledToLocalSpace(scaledSpaceCamera.transform.position);
            //				//				m_skyMaterial.SetVector ("_Globals_WorldCameraPos", scaledSpaceCamera.transform.position);
            //				mat.SetVector ("_Globals_WorldCameraPos", newpos);
            //			}
            //
            //						if (debugSettings [4])
            if (!MapView.MapIsEnabled) {
            mat.SetVector("_Globals_Origin", parentCelestialBody.transform.position);

            } else {

            //				celestialTransform = ScaledSpace.Instance.scaledSpaceTransforms.Single(t => t.name == parentCelestialBody.name);
            celestialTransform = ParentPlanetTransform;
            //				idek =celestialTransform.position;
            idek = celestialTransform.position - scaledSpaceCamera.transform.position;
            mat.SetVector("_Globals_Origin", idek);

            }

            if (!MapView.MapIsEnabled) {
            mat.SetFloat("_Exposure", m_HDRExposure);
            } else {
            mat.SetFloat("_Exposure", mapExposure);
            }

            //			int childCnt = 0;
            //			Transform scaledSunTransform=ScaledSpace.Instance.scaledSpaceTransforms.Single(t => t.name == "Sun");
            //			foreach (Transform child in scaledSunTransform)
            //			{
            //				print(childCnt);
            //				print(child.gameObject.name);
            //				childCnt++;
            //				MeshRenderer temp;
            //				temp = child.gameObject.GetComponent<MeshRenderer>();
            ////				temp.enabled=false;
            //				print(temp.enabled);
            //			}
        }
Exemple #11
0
        /**
        * Sets the shader uniforms that are necessary to project on screen the
        * TerrainQuad of the given TerrainNode. This method can set the uniforms
        * that are common to all the quads of the given terrain.
        */
        public virtual void SetUniforms(TerrainNode node, Material mat)
        {
            if(mat == null || node == null) return;

            float d1 = node.GetSplitDist() + 1.0f;
            float d2 = 2.0f * node.GetSplitDist();
            mat.SetVector(m_uniforms.blending, new Vector2(d1, d2 - d1));

            m_localToCamera = node.GetView().GetWorldToCamera() * node.GetLocalToWorld();
            m_localToScreen = node.GetView().GetCameraToScreen() * m_localToCamera;

            Vector3d2 localCameraPos = node.GetLocalCameraPos();
            Vector3d2 worldCamera = node.GetView().GetWorldCameraPos();

            Matrix4x4d A = LocalToDeformedDifferential(localCameraPos);
            Matrix4x4d B = DeformedToTangentFrame(worldCamera);

            Matrix4x4d ltot = B * node.GetLocalToWorld() * A;

            m_localToTangent = new Matrix3x3d(	ltot.m[0,0], ltot.m[0,1], ltot.m[0,3],
                                              ltot.m[1,0], ltot.m[1,1], ltot.m[1,3],
                                              ltot.m[3,0], ltot.m[3,1], ltot.m[3,3]);

            mat.SetMatrix(m_uniforms.localToScreen, m_localToScreen.ToMatrix4x4());
            mat.SetMatrix(m_uniforms.localToWorld, node.GetLocalToWorld().ToMatrix4x4());
        }
Exemple #12
0
    public static void RenderDistortion(Material material, RenderTexture source, RenderTexture destination, float angle, Vector2 center, Vector2 radius)
    {
        Matrix4x4 rotationMatrix = Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(0, 0, angle), Vector3.one);

        material.SetMatrix("_RotationMatrix", rotationMatrix);
        material.SetVector("_CenterRadius", new Vector4(center.x,center.y,radius.x,radius.y) );
        material.SetFloat("_Angle", angle * Mathf.Deg2Rad);

        ImageEffects.BlitWithMaterial( material, source, destination );
    }
        private void ApplyCache(Material material, float scale = 1.0f)
        {
            foreach (KeyValuePair<object,object> field in cache)
            {
                object obj = field.Value;
                float scaleValue = 1f;
                if (obj != null && obj.GetType() == typeof(ScaledValue))
                {
                    obj = ((ScaledValue)obj).obj;
                    scaleValue = scale;
                }
                else if (obj != null && obj.GetType() == typeof(InverseScaledValue))
                {
                    obj = ((InverseScaledValue)obj).obj;
                    scaleValue = 1 / scale;
                }

                if (obj.GetType() == typeof(TextureWrapper))
                {
                    TextureWrapper value = (TextureWrapper)obj;
                    value.ApplyTexture(material, (String)field.Key);
                }
                //float
                else if (obj.GetType() == typeof(float))
                {
                    float value = (float)obj;
                    material.SetFloat((int)field.Key, value * scaleValue);
                }
                //Color
                else if (obj.GetType() == typeof(Color))
                {
                    Color value = (Color)obj;
                    material.SetColor((int)field.Key, value/256f);
                }
                //Color32
                else if (obj.GetType() == typeof(Color32))
                {
                    Color32 value = (Color32)obj;
                    material.SetColor((int)field.Key, value);
                }//Vector2
                else if (obj.GetType() == typeof(Vector2))
                {
                    Vector2 value = (Vector2)obj;
                    material.SetVector((int)field.Key, value * scaleValue);
                }
                //Vector3
                else if (obj.GetType() == typeof(Vector3))
                {
                    Vector3 value = (Vector3)obj;
                    material.SetVector((int)field.Key, value * scaleValue);
                }
                //Vector4
                else if (obj.GetType() == typeof(Vector4))
                {
                    Vector4 value = (Vector4)obj;
                    material.SetVector((int)field.Key, value * scaleValue);
                }
                //Matrix
                else if (obj.GetType() == typeof(Matrix4x4))
                {
                    Matrix4x4 value = (Matrix4x4)obj;
                    material.SetMatrix((int)field.Key, value);
                }
                //bool
                else if (obj.GetType() == typeof(bool))
                {
                    bool value = (bool)obj;
                    if (value)
                    {
                        material.EnableKeyword((String)field.Key);
                    }
                    else
                    {
                        material.DisableKeyword((String)field.Key);
                    }
                }
                //enum
                else if (obj.GetType().IsEnum)
                {
                    String value = Enum.GetName(obj.GetType(), obj);
                    material.EnableKeyword(value);
                }

            }
        }
    public static void ComputeColorComposition(Camera camera, Material colorCompositeMaterial, RenderTexture dst, RenderTexture instanceIdBuffer, RenderTexture atomIdBuffer, RenderTexture depthBuffer)
    {
        var temp1 = new DisplayInfo[CPUBuffers.Get.IngredientsDisplayInfo.Count];
        var temp2 = new DisplayInfo[CPUBuffers.Get.IngredientGroupsDisplayInfo.Count];

        GPUBuffers.Get.IngredientsColorInfo.GetData(temp1);
        GPUBuffers.Get.IngredientGroupsColorInfo.GetData(temp2);

        CPUBuffers.Get.IngredientsDisplayInfo = temp1.ToList();
        CPUBuffers.Get.IngredientGroupsDisplayInfo = temp2.ToList();

        //Debug.Log(temp2[5].ToString());

        /**************/

        //colorCompositeMaterial.SetFloat("_depth", ColorManager.Get.depthSlider);
        colorCompositeMaterial.SetFloat("_UseHCL", Convert.ToInt32(ColorManager.Get.UseHCL));
        colorCompositeMaterial.SetFloat("_ShowAtoms", Convert.ToInt32(ColorManager.Get.ShowAtoms));
        colorCompositeMaterial.SetFloat("_ShowChains", Convert.ToInt32(ColorManager.Get.ShowChains));
        colorCompositeMaterial.SetFloat("_ShowResidues", Convert.ToInt32(ColorManager.Get.ShowResidues));
        colorCompositeMaterial.SetFloat("_ShowSecondaryStructures", Convert.ToInt32(ColorManager.Get.ShowSecondaryStructures));
        
        colorCompositeMaterial.SetFloat("_AtomDistance", ColorManager.Get.AtomDistance);
        colorCompositeMaterial.SetFloat("_ChainDistance", ColorManager.Get.ChainDistance);
        colorCompositeMaterial.SetFloat("_ResidueDistance", ColorManager.Get.ResidueDistance);
        colorCompositeMaterial.SetFloat("_SecondaryStructureDistance", ColorManager.Get.SecondaryStructureDistance);

        // LOD infos

        var rangeValues = Matrix4x4.zero;
        
        int distAcc = 0;
        for (int i = 0; i < ColorManager.Get.LevelRanges.Length; i++)
        {
            distAcc += (int)(ColorManager.Get.LevelRanges[i] * ColorManager.Get.DistanceMax);
            rangeValues[i] = distAcc;
        }
        rangeValues[ColorManager.Get.LevelRanges.Length] = ColorManager.Get.DistanceMax;

        var selectionSphere = (Vector4)SelectionManager.Instance.SelectionGameObject.transform.position;
        selectionSphere.w = SelectionManager.Instance.SelectionGameObject.GetComponent<SphereCollider>().radius;

        colorCompositeMaterial.SetVector("_FocusSphere", selectionSphere);
        colorCompositeMaterial.SetMatrix("_ProjectionMatrix", camera.projectionMatrix);
        colorCompositeMaterial.SetMatrix("_InverseViewMatrix", camera.cameraToWorldMatrix);

        colorCompositeMaterial.SetInt("_UseDistanceLevels", Convert.ToInt32(ColorManager.Get.UseDistanceLevels));
        
        colorCompositeMaterial.SetInt("_NumLevelMax", ColorManager.Get.NumLevelMax);
        colorCompositeMaterial.SetInt("_DistanceMax", ColorManager.Get.DistanceMax);
        colorCompositeMaterial.SetMatrix("_LevelRanges", rangeValues);

        //*****//
        colorCompositeMaterial.SetFloat("_LevelLerpFactor", ColorManager.Get.LevelLerpFactor);
        colorCompositeMaterial.SetInt("_NumPixels", instanceIdBuffer.width * instanceIdBuffer.height);

        //*****//
        colorCompositeMaterial.SetTexture("_DepthBuffer", depthBuffer);
        colorCompositeMaterial.SetTexture("_AtomIdBuffer", atomIdBuffer);
        colorCompositeMaterial.SetTexture("_InstanceIdBuffer", instanceIdBuffer);

        // Properties
        colorCompositeMaterial.SetBuffer("_ProteinAtomInfos", GPUBuffers.Get.ProteinAtomInfo);
        colorCompositeMaterial.SetBuffer("_ProteinAtomInfos2", GPUBuffers.Get.ProteinAtomInfo2);
        colorCompositeMaterial.SetBuffer("_ProteinInstanceInfo", GPUBuffers.Get.ProteinInstancesInfo);
        colorCompositeMaterial.SetBuffer("_LipidAtomInfos", GPUBuffers.Get.LipidAtomPositions);
        colorCompositeMaterial.SetBuffer("_LipidInstancesInfo", GPUBuffers.Get.LipidInstancesInfo);

        colorCompositeMaterial.SetBuffer("_IngredientsInfo", GPUBuffers.Get.IngredientsInfo);
        colorCompositeMaterial.SetBuffer("_IngredientGroupsColorInfo", GPUBuffers.Get.IngredientGroupsColorInfo);
        colorCompositeMaterial.SetBuffer("_ProteinIngredientsColorInfo", GPUBuffers.Get.IngredientsColorInfo);

        // Predifined colors 
        colorCompositeMaterial.SetBuffer("_AtomColors", GPUBuffers.Get.AtomColors);
        colorCompositeMaterial.SetBuffer("_AminoAcidColors", GPUBuffers.Get.AminoAcidColors);
        colorCompositeMaterial.SetBuffer("_IngredientsColors", GPUBuffers.Get.IngredientsColors);
        colorCompositeMaterial.SetBuffer("_IngredientsChainColors", GPUBuffers.Get.IngredientsChainColors);
        colorCompositeMaterial.SetBuffer("_IngredientGroupsColor", GPUBuffers.Get.IngredientGroupsColor);

        // Values for color generation on the fly 
        colorCompositeMaterial.SetBuffer("_IngredientGroupsLerpFactors", GPUBuffers.Get.IngredientGroupsLerpFactors);
        colorCompositeMaterial.SetBuffer("_IngredientGroupsColorValues", GPUBuffers.Get.IngredientGroupsColorValues);
        colorCompositeMaterial.SetBuffer("_IngredientGroupsColorRanges", GPUBuffers.Get.IngredientGroupsColorRanges);
        colorCompositeMaterial.SetBuffer("_ProteinIngredientsRandomValues", GPUBuffers.Get.ProteinIngredientsRandomValues);

        Graphics.Blit(null, dst, colorCompositeMaterial, 0);
    }
Exemple #15
0
		private void ApplyToMaterial(Material mat, ShaderIDs bids) {
			mat.SetVector(bids.exposureIBL,	this.exposures);
			mat.SetVector(bids.exposureLM,	this.exposuresLM);			
			mat.SetMatrix(bids.skyMatrix,		this.skyMatrix);
			mat.SetMatrix(bids.invSkyMatrix,	this.invMatrix);

			mat.SetVector(bids.skyMin, skyMin);
			mat.SetVector(bids.skyMax, skyMax);
					
			if(specularCube) mat.SetTexture(bids.specCubeIBL,	this.specularCube);
			else 			 mat.SetTexture(bids.specCubeIBL,	this.blackCube);
			if(skyboxCube)	 mat.SetTexture(bids.skyCubeIBL, 	this.skyboxCube);
			for(int i=0; i<9; ++i) {
				mat.SetVector(bids.SH[i], this.SH.cBuffer[i]);
			}
		}
Exemple #16
0
        void UpdatePostProcessMaterial(Material mat)
        {
            //mat.SetFloat ("atmosphereGlobalScale", atmosphereGlobalScale);
            //			mat.SetFloat ("Rg", Rg*atmosphereGlobalScale*postProcessingScale);
            //			mat.SetFloat("Rt", Rt*atmosphereGlobalScale*postProcessingScale);
            //			mat.SetFloat("Rl", RL*atmosphereGlobalScale*postProcessingScale);

            float totalscale  = 1;
            float totalscale2 = 1;
            for (int j=0; j<5; j++)
            {
                totalscale=totalscale*additionalScales[j];
            }

            for (int j=6; j<10; j++)
            {
                totalscale2=totalscale2*additionalScales[j];
            }

            mat.SetFloat ("Rg", Rg*atmosphereGlobalScale*totalscale);
            mat.SetFloat("Rt", Rt*atmosphereGlobalScale*totalscale);
            mat.SetFloat("Rl", RL*atmosphereGlobalScale*totalscale);

            //mat.SetFloat("_inscatteringCoeff", inscatteringCoeff);
            mat.SetFloat("_extinctionCoeff", extinctionCoeff);
            mat.SetFloat("_global_alpha", postProcessingAlpha);
            mat.SetFloat("_Exposure", postProcessExposure);
            mat.SetFloat("_global_depth", postProcessDepth);
            mat.SetFloat("_global_depth2", totalscale2);

            mat.SetFloat("_Scale", postProcessingScale);
            //			mat.SetFloat("_Scale", 1);

            //			mat.SetMatrix ("_Globals_CameraToWorld", cams [0].worldToCameraMatrix.inverse);
            if (debugSettings [1]) {
                mat.SetMatrix ("_Globals_CameraToWorld", farCamera.worldToCameraMatrix.inverse);
            }
            else
            {
                mat.SetMatrix ("_Globals_CameraToWorld", scaledSpaceCamera.worldToCameraMatrix.inverse);
            }

            if (debugSettings [2]) {
                mat.SetVector ("_CameraForwardDirection", farCamera.transform.forward);
            } else {
                mat.SetVector ("_CameraForwardDirection", scaledSpaceCamera.transform.forward);
            }

            if (debugSettings [3]) {
                mat.SetVector ("_Globals_Origin", /*Vector3.zero-*/parentCelestialBody.transform.position);
            } else

            {

                Transform celestialTransform = ScaledSpace.Instance.scaledSpaceTransforms.Single(t => t.name == parentCelestialBody.name);
                Vector3 idek =celestialTransform.position;
                mat.SetVector ("_Globals_Origin", /*Vector3.zero-*/ idek);
            }

            //mat.SetVector("betaR", m_betaR / (Rg / m_radius));
            //			mat.SetVector("betaR", m_betaR / (postProcessDepth));
            mat.SetVector("betaR", new Vector4(2.9e-3f, 0.675e-2f, 1.655e-2f, 0.0f));
            mat.SetFloat("mieG", 0.4f);
            mat.SetVector("SUN_DIR", /*Vector3.zero-*/m_manager.GetSunNodeDirection());
            mat.SetFloat("SUN_INTENSITY", sun_intensity);
        }
Exemple #17
0
        /// <summary>
        /// Sets the simulation upscaling correction paramters to the given material.
        /// </summary>
        /// <param name="mat"></param>
        protected void SetSimulationTransformCorrection(Material mat)
        {
            mat.SetMatrix("_TFX_World2Object", Matrix4x4.TRS(this.transform.position, this.transform.rotation, Vector3.one).inverse); // this.transform.worldToLocalMatrix);
            mat.SetMatrix("_TFX_ScaleMatrix", Matrix4x4.Scale(this.transform.localScale));
            mat.SetMatrix("_TFX_Object2World", Matrix4x4.TRS(this.transform.position, this.transform.rotation, Vector3.one)); // this.transform.localToWorldMatrix);

            Vector3 scale = new Vector3
            (
                1 / this.transform.lossyScale.x,
                1 / this.transform.lossyScale.y,
                1 / this.transform.lossyScale.z
            );
            mat.SetVector("_TFX_PositionOffset", Vector3.Scale(this.transform.position, scale) - this.transform.position);
        }
Exemple #18
0
        public void SetUniforms(Material mat)
        {
            //Sets uniforms that this or other gameobjects may need
            if(mat == null) return;
            //mat.SetFloat ("atmosphereGlobalScale", atmosphereGlobalScale);

            mat.SetFloat ("_Alpha_Cutoff", alphaCutoff);
            mat.SetFloat ("_Alpha_Global", alphaGlobal);

            mat.SetFloat("scale",atmosphereGlobalScale);
            mat.SetFloat("Rg", Rg*atmosphereGlobalScale);
            mat.SetFloat("Rt", Rt*atmosphereGlobalScale);
            mat.SetFloat("RL", RL*atmosphereGlobalScale);

            //			if (debugSettings [5])
            if(!MapView.MapIsEnabled)
            {
                mat.SetFloat ("_Globals_ApparentDistance", apparentDistance);
            }
            else
            {
                mat.SetFloat("_Globals_ApparentDistance", (float)(parentCelestialBody.Radius/100.2f));
            }

            //			if (debugSettings[1])
            if(!MapView.MapIsEnabled)
            {

                mat.SetMatrix ("_Globals_WorldToCamera", farCamera.worldToCameraMatrix);
                mat.SetMatrix ("_Globals_CameraToWorld", farCamera.worldToCameraMatrix.inverse);
            }

            else
            {
                mat.SetMatrix ("_Globals_WorldToCamera", scaledSpaceCamera.worldToCameraMatrix);
                mat.SetMatrix ("_Globals_CameraToWorld", scaledSpaceCamera.worldToCameraMatrix.inverse);
            }

            mat.SetVector("betaR", m_betaR / 1000.0f);
            mat.SetFloat("mieG", Mathf.Clamp(m_mieG, 0.0f, 0.99f));
            mat.SetTexture("_Sky_Transmittance", m_transmit);
            mat.SetTexture("_Sky_Inscatter", m_inscatter);
            mat.SetTexture("_Sky_Irradiance", m_irradiance);
            //			mat.SetTexture("_Sky_Map", m_skyMap);
            mat.SetFloat("_Sun_Intensity", sun_intensity);
            mat.SetVector("_Sun_WorldSunDir", m_manager.getDirectionToSun().normalized);
            //			mat.SetVector("_Sun_WorldSunDir", m_manager.getDirectionToSun());

            //			//copied from m_manager's set uniforms

            Matrix4x4 p;
            //			if (debugSettings [2])
            if(!MapView.MapIsEnabled)
            {
                p = farCamera.projectionMatrix;
            }
            else
            {
                p = scaledSpaceCamera.projectionMatrix;
            }

            m_cameraToScreenMatrix = new Matrix4x4d (p);
            mat.SetMatrix ("_Globals_CameraToScreen", m_cameraToScreenMatrix.ToMatrix4x4 ());
            mat.SetMatrix ("_Globals_ScreenToCamera", m_cameraToScreenMatrix.Inverse ().ToMatrix4x4 ());

            //			if (debugSettings [3])
            {
                mat.SetVector ("_Globals_WorldCameraPos", farCamera.transform.position);
            }
            //			else
            //			{
            //				Vector3 newpos= ScaledSpace.ScaledToLocalSpace(scaledSpaceCamera.transform.position);
            //				//				m_skyMaterial.SetVector ("_Globals_WorldCameraPos", scaledSpaceCamera.transform.position);
            //				mat.SetVector ("_Globals_WorldCameraPos", newpos);
            //			}

            //			if (debugSettings [4])
            if(!MapView.MapIsEnabled)
            {
                mat.SetVector ("_Globals_Origin", parentCelestialBody.transform.position);
            }
            else
            {

                Transform celestialTransform = ScaledSpace.Instance.scaledSpaceTransforms.Single(t => t.name == parentCelestialBody.name);
                Vector3 idek =celestialTransform.position;
                mat.SetVector ("_Globals_Origin", idek);

            }

            mat.SetFloat ("_Exposure", m_HDRExposure);
        }
        private void WriteUiforms <TValue>(EditorImporter importer, UnityEngine.Material material, SeinMaterialUniform <TValue>[] uniforms)
        {
            foreach (SeinMaterialUniform <TValue> uniform in uniforms)
            {
                var name = uniform.name;
                switch (uniform.type)
                {
                case (ESeinMaterialUniformType.FLOAT):
                    material.SetFloat(name, (uniform as SeinMaterialUniformFloat).value);
                    break;

                case (ESeinMaterialUniformType.INT):
                    material.SetInt(name, (uniform as SeinMaterialUniformInt).value);
                    break;

                case (ESeinMaterialUniformType.SAMPLER_2D):
                    var tex = importer.GetTexture((uniform as SeinMaterialUniformTexture).id.Id);
                    material.SetTexture(name, tex);
                    break;

                // todo: support cubemap
                case (ESeinMaterialUniformType.SAMPLER_CUBE):
                    break;

                case (ESeinMaterialUniformType.FLOAT_VEC2):
                    var fv2 = (uniform as SeinMaterialUniformFloatVec2).value;
                    material.SetFloatArray(name, new List <float> {
                        fv2.x, fv2.y
                    });
                    break;

                case (ESeinMaterialUniformType.FLOAT_VEC3):
                    var fv3 = (uniform as SeinMaterialUniformFloatVec3).value;
                    material.SetFloatArray(name, new List <float> {
                        fv3.x, fv3.y, fv3.z
                    });
                    break;

                case (ESeinMaterialUniformType.FLOAT_VEC4):
                    if (uniform.GetType() == typeof(SeinMaterialUniformColor))
                    {
                        material.SetColor(name, (uniform as SeinMaterialUniformColor).value);
                    }
                    material.SetVector(name, (uniform as SeinMaterialUniformFloatVec4).value);
                    break;

                case (ESeinMaterialUniformType.FLOAT_MAT2):
                    material.SetMatrix(name, (uniform as SeinMaterialUniformFloatMat2).value);
                    break;

                case (ESeinMaterialUniformType.FLOAT_MAT3):
                    material.SetMatrix(name, (uniform as SeinMaterialUniformFloatMat3).value);
                    break;

                case (ESeinMaterialUniformType.FLOAT_MAT4):
                    material.SetMatrix(name, (uniform as SeinMaterialUniformFloatMat4).value);
                    break;

                default:
                    break;
                }
            }
        }
	public void SetValues(Material m, IEnumerable<StoredValue> values)
	{
		foreach(var v in values)
		{
			switch(v.Property.type)
			{
			case MaterialProperty.PropertyType.color:
				m.SetColor(v.Property.name, (Color)v.Value);
				break;
			case MaterialProperty.PropertyType.real:
				m.SetFloat(v.Property.name, (float)v.Value);
				break;
			case MaterialProperty.PropertyType.texture:
				m.SetTexture(v.Property.name, (Texture)v.Value);
				break;
			case MaterialProperty.PropertyType.vector:
				m.SetVector(v.Property.name, (Vector4)v.Value);
				break;
			case MaterialProperty.PropertyType.textureOffset:
				m.SetTextureOffset(v.Property.name, (Vector2)v.Value);
				break;
			case MaterialProperty.PropertyType.textureScale:
				m.SetTextureScale(v.Property.name, (Vector2)v.Value);
				break;
			case MaterialProperty.PropertyType.matrix:
				m.SetMatrix(v.Property.name, (Matrix4x4)v.Value);
				break;
			}
		}
	}
 private void DrawField(Material material)
 {
     material.SetPass(0);
     material.SetMatrix("object_to_world", transform.localToWorldMatrix);
     Graphics.DrawProcedural(MeshTopology.Points, PointCount);
 }
Exemple #22
0
		public void updateStuff (Material oceanMaterial, Camera inCamera)
		{
			//Calculates the required data for the projected grid
			
			// compute ltoo = localToOcean transform, where ocean frame = tangent space at
			// camera projection on sphere radius in local space
			
			Matrix4x4 ctol1 = inCamera.cameraToWorldMatrix;
			
			//position relative to kerbin
//			Vector3d tmp = (inCamera.transform.position) - m_manager.parentCelestialBody.transform.position;
			
			
			Matrix4x4d cameraToWorld = new Matrix4x4d (ctol1.m00, ctol1.m01, ctol1.m02, ctol1.m03,
			                                          ctol1.m10, ctol1.m11, ctol1.m12, ctol1.m13,
			                                          ctol1.m20, ctol1.m21, ctol1.m22, ctol1.m23,
			                                          ctol1.m30, ctol1.m31, ctol1.m32, ctol1.m33);
			
			
			//Looking back, I have no idea how I figured this crap out
			Vector4 translation = m_manager.parentCelestialBody.transform.worldToLocalMatrix.inverse.GetColumn (3);
			
			Matrix4x4d worldToLocal = new Matrix4x4d (1, 0, 0, -translation.x,
			                                         0, 1, 0, -translation.y,
			                                         0, 0, 1, -translation.z,
			                                         0, 0, 0, 1);

			Matrix4x4d camToLocal = worldToLocal * cameraToWorld;


			// camera in local space relative to planet's origin
			Vector3d2 cl = new Vector3d2 ();
			cl = camToLocal * Vector3d2.Zero ();
			
//			double radius = m_manager.GetRadius ();
			double radius = m_manager.GetRadius ()+m_oceanLevel;

//			Vector3d2 ux, uy, uz, oo;
			
			uz = cl.Normalized (); // unit z vector of ocean frame, in local space
			
			if (m_oldlocalToOcean != Matrix4x4d.Identity ()) {
				ux = (new Vector3d2 (m_oldlocalToOcean.m [1, 0], m_oldlocalToOcean.m [1, 1], m_oldlocalToOcean.m [1, 2])).Cross (uz).Normalized ();
			} else {
				ux = Vector3d2.UnitZ ().Cross (uz).Normalized ();
			}

			uy = uz.Cross (ux); // unit y vector
			
			oo = uz * (radius); // origin of ocean frame, in local space
			
			
			//local to ocean transform
			//computed from oo and ux, uy, uz should be correct
			Matrix4x4d localToOcean = new Matrix4x4d (
				ux.x, ux.y, ux.z, -ux.Dot (oo),
				uy.x, uy.y, uy.z, -uy.Dot (oo),
				uz.x, uz.y, uz.z, -uz.Dot (oo),
				0.0, 0.0, 0.0, 1.0);


			Matrix4x4d cameraToOcean = localToOcean * camToLocal;


			//Couldn't figure out how to change the wind's direction in all that math so I tried to do the easy thing
			//And Rotated the ocean and the sun
			//This didn't work

			//deleted rotation code here



			
			Vector3d2 delta = new Vector3d2 (0, 0, 0);
			
			if (m_oldlocalToOcean != Matrix4x4d.Identity ()) {
				delta = localToOcean * (m_oldlocalToOcean.Inverse () * Vector3d2.Zero ());
				m_offset += delta;
			}
			
			m_oldlocalToOcean = localToOcean;
			
			Matrix4x4d ctos = ModifiedProjectionMatrix (inCamera);
			Matrix4x4d stoc = ctos.Inverse ();
			
			Vector3d2 oc = cameraToOcean * Vector3d2.Zero ();
			
			h = oc.z;
			
			Vector4d stoc_w = (stoc * Vector4d.UnitW ()).XYZ0 ();
			Vector4d stoc_x = (stoc * Vector4d.UnitX ()).XYZ0 ();
			Vector4d stoc_y = (stoc * Vector4d.UnitY ()).XYZ0 ();
			
			Vector3d2 A0 = (cameraToOcean * stoc_w).XYZ ();
			Vector3d2 dA = (cameraToOcean * stoc_x).XYZ ();
			Vector3d2 B = (cameraToOcean * stoc_y).XYZ ();
			
			Vector3d2 horizon1, horizon2;
			
//			Vector3d2 offset = new Vector3d2 (-m_offset.x, -m_offset.y, h);
			offset = new Vector3d2 (-m_offset.x, -m_offset.y, h);
//			Vector3d2 offset = new Vector3d2 (0f, 0f, h);
			
			double h1 = h * (h + 2.0 * radius);
			double h2 = (h + radius) * (h + radius);
			double alpha = B.Dot (B) * h1 - B.z * B.z * h2;
			
			double beta0 = (A0.Dot (B) * h1 - B.z * A0.z * h2) / alpha;
			double beta1 = (dA.Dot (B) * h1 - B.z * dA.z * h2) / alpha;
			
			double gamma0 = (A0.Dot (A0) * h1 - A0.z * A0.z * h2) / alpha;
			double gamma1 = (A0.Dot (dA) * h1 - A0.z * dA.z * h2) / alpha;
			double gamma2 = (dA.Dot (dA) * h1 - dA.z * dA.z * h2) / alpha;
			
			horizon1 = new Vector3d2 (-beta0, -beta1, 0.0);
			horizon2 = new Vector3d2 (beta0 * beta0 - gamma0, 2.0 * (beta0 * beta1 - gamma1), beta1 * beta1 - gamma2);
			
			Vector3d2 sunDir = new Vector3d2 (m_manager.getDirectionToSun ().normalized);
			Vector3d2 oceanSunDir = localToOcean.ToMatrix3x3d () * sunDir;
			
			oceanMaterial.SetVector ("_Ocean_SunDir", oceanSunDir.ToVector3 ());
			
			oceanMaterial.SetVector ("_Ocean_Horizon1", horizon1.ToVector3 ());
			oceanMaterial.SetVector ("_Ocean_Horizon2", horizon2.ToVector3 ());
			
			oceanMaterial.SetMatrix ("_Ocean_CameraToOcean", cameraToOcean.ToMatrix4x4 ());
			oceanMaterial.SetMatrix ("_Ocean_OceanToCamera", cameraToOcean.Inverse ().ToMatrix4x4 ());
			
			oceanMaterial.SetMatrix ("_Globals_CameraToScreen", ctos.ToMatrix4x4 ());
			oceanMaterial.SetMatrix ("_Globals_ScreenToCamera", stoc.ToMatrix4x4 ());
			
			oceanMaterial.SetVector ("_Ocean_CameraPos", offset.ToVector3 ());
			
			oceanMaterial.SetVector ("_Ocean_Color", new Color(m_oceanUpwellingColor.x,m_oceanUpwellingColor.y,m_oceanUpwellingColor.z) /*  *0.1f   */);
			oceanMaterial.SetVector ("_Ocean_ScreenGridSize", new Vector2 ((float)m_resolution / (float)Screen.width, (float)m_resolution / (float)Screen.height));
			oceanMaterial.SetFloat ("_Ocean_Radius", (float)radius);
			
			//			oceanMaterial.SetFloat("scale", 1);
			oceanMaterial.SetFloat ("scale", oceanScale);

			oceanMaterial.SetFloat ("_OceanAlpha", oceanAlpha);
			oceanMaterial.SetFloat ("alphaRadius", alphaRadius);


			oceanMaterial.SetFloat ("sunReflectionMultiplier", sunReflectionMultiplier);
			oceanMaterial.SetFloat ("skyReflectionMultiplier", skyReflectionMultiplier);
			oceanMaterial.SetFloat ("seaRefractionMultiplier", seaRefractionMultiplier);


			m_manager.GetSkyNode ().SetOceanUniforms (oceanMaterial);
			
		}
        /// <summary>
        /// Sets the self shadowmapping parameters of this light to the specified evaluation material.
        /// </summary>
        /// <param name="evalMaterial"></param>
        public void SetSelfShadowParameters(Material evalMaterial)
        {
            if (this.shadowMappingCamera == null)
            {
                Debug.LogError("SetSelfShadowParameters was called on a light which does not cast self shadows!");
                return;
            }

            // Far-/near clipping plane
            evalMaterial.SetVector("_SelfShadowFarNear", new Vector2(this.shadowMappingCamera.farClipPlane, this.shadowMappingCamera.nearClipPlane));

            // Calculate shadow matrix

            // Set shadow matrix
            evalMaterial.SetMatrix("_SelfShadowMatrix", GetShadowMatrix());

            // Set other parameters
            evalMaterial.SetTexture("_SelfShadowMap", this.selfShadowMap);
            evalMaterial.SetFloat("_SelfShadowFiberSpacing", fiberSpacing); // TODO
        }
Exemple #24
0
    public static void RenderDistortion(Material material, RenderTexture source, RenderTexture destination, float angle, Vector3 center, float radius, int subdivisions)
    {
        RenderTexture.active = destination;

        angle *= Mathf.Deg2Rad;
        Matrix4x4 rotationMatrix = Matrix4x4.TRS(Vector3.zero, Quaternion.EulerAngles (0, 0, angle), Vector3.one);
        Vector4 pixelCenter = new Vector4 (source.width * center.x, source.height * center.y, 1, 1);
        radius *= source.height;

        material.SetMatrix("_RotationMatrix", rotationMatrix);
        material.SetVector("_Center", pixelCenter);
        material.SetFloat("_Radius", radius);
        material.SetFloat("_Angle", angle);
        material.SetTexture("_MainTex", source);

        GL.PushMatrix ();
        GL.LoadOrtho ();

        for (int i = 0; i < material.passCount; i++) {
            material.SetPass (i);
            ImageEffects.DrawGrid(subdivisions, subdivisions);
        }
        GL.PopMatrix ();
    }
Exemple #25
0
 private void InitMaterial(Material mat)
 {
     mat.SetVector("_SunDir", this.SunDir);
     mat.SetMatrix("_Moon_wtl", this.getMoonMatrix);
     mat.SetVector("_betaR", this.betaR_RayleighOffset);
     mat.SetVector("_betaM", this.BetaM);
     mat.SetVector("_SkyMultiplier", this.skyMultiplier);
     mat.SetFloat("_SunSize", 32f / this.SunSize);
     mat.SetVector("_mieConst", this.mieConst);
     mat.SetVector("_miePhase_g", this.miePhase_g);
     mat.SetVector("_GroundColor", this.bottomTint);
     mat.SetVector("_NightHorizonColor", this.getNightHorizonColor);
     mat.SetVector("_NightZenithColor", this.getNightZenithColor);
     mat.SetVector("_MoonInnerCorona", this.getMoonInnerCorona);
     mat.SetVector("_MoonOuterCorona", this.getMoonOuterCorona);
     mat.SetFloat("_MoonSize", this.MoonSize);
     mat.SetVector("_colorCorrection", this.ColorCorrection);
     if (this.Tonemapping)
     {
     }
     mat.SetFloat("_OuterSpaceIntensity", this.OuterSpaceIntensity);
     if (this.starMaterial != null)
     {
         this.starMaterial.SetFloat("StarIntensity", this.starBrightness);
     }
 }
Exemple #26
0
    void InitMaterial(Material mat)
    {
        mat.SetVector ("_SunDir", SunDir);
        mat.SetMatrix ("_Moon_wtl", getMoonMatrix);

        mat.SetVector ("_betaR", BetaR);
        mat.SetVector ("_betaM", BetaM);

        // x = Sunset, y = Day, z = Rayleigh, w = Night
        mat.SetVector ("_SkyMultiplier", skyMultiplier);

        mat.SetFloat ("_SunSize", 24.0f / SunSize);
        mat.SetVector ("_mieConst", mieConst);
        mat.SetVector ("_miePhase_g", miePhase_g);
        mat.SetVector ("_SkyTint", skyTint);
        mat.SetVector ("_GroundColor", bottomTint);
        mat.SetVector ("_NightHorizonColor", NightHorizonColor * nt);
        mat.SetVector ("_NightZenithColor", getNightZenithColor);
        mat.SetVector ("_MoonInnerCorona", getMoonInnerCorona);
        mat.SetVector ("_MoonOuterCorona", getMoonOuterCorona);
        mat.SetFloat ("_MoonSize", MoonSize);
        mat.SetVector ("_colorCorrection", ColorCorrection);

        mat.shaderKeywords = hdrMode.ToArray ();

        if (EnableNightSky)
            mat.DisableKeyword("NIGHTSKY_OFF");
        else
            mat.EnableKeyword("NIGHTSKY_OFF");

        mat.SetFloat ("_OuterSpaceIntensity", OuterSpaceIntensity);
        starMaterial.SetFloat ("StarIntensity", starBrightness);
    }
        private void copy_internal(Texture dstCube, Texture srcCube, bool dstRGBM, bool srcRGBM, bool linear, Camera cam, Material skyMat, Matrix4x4 matrix)
        {
            bool prevHDR = cam.hdr;
            CameraClearFlags prevFlags = cam.clearFlags;
            int prevMask = cam.cullingMask;
            cam.clearFlags = CameraClearFlags.Skybox;
            cam.cullingMask = 0;
            cam.hdr = !dstRGBM; // might need HDR camera buffer when we're not rendering to RGBM encoded pixels

            skyMat.name = "Internal HDR to RGBM Skybox";
            skyMat.shader = Shader.Find("Hidden/Marmoset/RGBM Cube");

            //toggleKeywordPair("MARMO_LINEAR", "MARMO_GAMMA", linear);
            toggleKeywordPair("MARMO_RGBM_INPUT_ON", "MARMO_RGBM_INPUT_OFF", srcRGBM);
            toggleKeywordPair("MARMO_RGBM_OUTPUT_ON", "MARMO_RGBM_OUTPUT_OFF", dstRGBM);

            skyMat.SetMatrix("_SkyMatrix", matrix);
            skyMat.SetTexture("_CubeHDR", srcCube);

            Material prevSkyMat = UnityEngine.RenderSettings.skybox;
            UnityEngine.RenderSettings.skybox = skyMat;

            RenderTexture RT = dstCube as RenderTexture;
            Cubemap cube = dstCube as Cubemap;
            if(RT)  		cam.RenderToCubemap(RT);
            else if(cube)	cam.RenderToCubemap(cube);

            cam.hdr = prevHDR;
            cam.clearFlags = prevFlags;
            cam.cullingMask = prevMask;
            UnityEngine.RenderSettings.skybox = prevSkyMat;
        }
Exemple #28
0
        void UpdatePostProcessMaterial(Material mat)
        {
            //mat.SetFloat ("atmosphereGlobalScale", atmosphereGlobalScale);
            //			mat.SetFloat ("Rg", Rg*atmosphereGlobalScale*postProcessingScale);
            //			mat.SetFloat("Rt", Rt*atmosphereGlobalScale*postProcessingScale);
            //			mat.SetFloat("Rl", RL*atmosphereGlobalScale*postProcessingScale);

            totalscale = 1;
            totalscale2 = 1;
            for (int j = 0; j < 5; j++) {
            totalscale = totalscale * additionalScales[j];
            }

            for (int j = 6; j < 10; j++) {
            totalscale2 = totalscale2 * additionalScales[j];
            }

            mat.SetFloat("Rg", Rg * atmosphereGlobalScale * totalscale);
            mat.SetFloat("Rt", Rt * atmosphereGlobalScale * totalscale);
            mat.SetFloat("Rl", RL * atmosphereGlobalScale * totalscale);

            //mat.SetFloat("_inscatteringCoeff", inscatteringCoeff);
            mat.SetFloat("_extinctionCoeff", extinctionCoeff);
            mat.SetFloat("_global_alpha", postProcessingAlpha);
            mat.SetFloat("_Exposure", postProcessExposure);
            mat.SetFloat("_global_depth", postProcessDepth);
            mat.SetFloat("_global_depth2", totalscale2);

            mat.SetFloat("terrain_reflectance", terrainReflectance);
            mat.SetFloat("_irradianceFactor", irradianceFactor);

            mat.SetFloat("_Scale", postProcessingScale);
            //			mat.SetFloat("_Scale", 1);

            mat.SetFloat("_Ocean_Sigma", oceanSigma);
            mat.SetFloat("_Ocean_Threshold", _Ocean_Threshold);

            //			mat.SetMatrix ("_Globals_CameraToWorld", cams [0].worldToCameraMatrix.inverse);
            if (debugSettings[1]) {
            mat.SetMatrix("_Globals_CameraToWorld", farCamera.worldToCameraMatrix.inverse);
            } else {
            mat.SetMatrix("_Globals_CameraToWorld", scaledSpaceCamera.worldToCameraMatrix.inverse);
            }

            if (debugSettings[2]) {
            mat.SetVector("_CameraForwardDirection", farCamera.transform.forward);
            } else {
            mat.SetVector("_CameraForwardDirection", scaledSpaceCamera.transform.forward);
            }

            if (debugSettings[3]) {
            mat.SetVector("_Globals_Origin", /*Vector3.zero-*/ parentCelestialBody.transform.position);
            } else

            {

            //				celestialTransform = ScaledSpace.Instance.scaledSpaceTransforms.Single(t => t.name == parentCelestialBody.name);
            celestialTransform = ParentPlanetTransform;
            idek = celestialTransform.position;
            mat.SetVector("_Globals_Origin", /*Vector3.zero-*/ idek);
            }

            //mat.SetVector("betaR", m_betaR / (Rg / m_radius));
            //			mat.SetVector("betaR", m_betaR / (postProcessDepth));
            mat.SetVector("betaR", new Vector4(2.9e-3f, 0.675e-2f, 1.655e-2f, 0.0f));
            mat.SetFloat("mieG", 0.4f);
            mat.SetVector("SUN_DIR", m_manager.GetSunNodeDirection());
            mat.SetFloat("SUN_INTENSITY", sunIntensity);

            Matrix4x4 ctol1 = farCamera.cameraToWorldMatrix;
            Vector3d tmp = (farCamera.transform.position) - m_manager.parentCelestialBody.transform.position;

            Matrix4x4d viewMat = new Matrix4x4d(ctol1.m00, ctol1.m01, ctol1.m02, tmp.x,
                                            ctol1.m10, ctol1.m11, ctol1.m12, tmp.y,
                                            ctol1.m20, ctol1.m21, ctol1.m22, tmp.z,
                                            ctol1.m30, ctol1.m31, ctol1.m32, ctol1.m33);

            //			print ("viewmat");
            //			print (viewMat.ToMatrix4x4());

            //			Matrix4x4 viewMat = farCamera.worldToCameraMatrix;
            viewMat = viewMat.Inverse();
            Matrix4x4 projMat = GL.GetGPUProjectionMatrix(farCamera.projectionMatrix, false);

            //			projMat.m23 = projMat.m23 * 0.5f;

            //			print ("projmat");
            //			print (projMat);

            Matrix4x4 viewProjMat = (projMat * viewMat.ToMatrix4x4());
            mat.SetMatrix("_ViewProjInv", viewProjMat.inverse);

            //			mat.SetMatrix("_ViewToWorld", viewMat.ToMatrix4x4());
            //
            //			var lpoints = RecalculateFrustrumPoints(farCamera);
            //			mat.SetVector("_FrustrumPoints", new Vector4(
            //				lpoints[4].x,lpoints[5].x,lpoints[5].y,lpoints[6].y));
            //
            //			mat.SetFloat("_CameraFar", farCamera.farClipPlane);
        }