//[Header("烘培贴图法线加强")] //[Range(0, 1)] //public float _BakedNormalPower = 0.4f; //[Header("烘培贴图亮度")] //[Range(0, 3)] //public float _BakedNormalBright = 1.5f; // Use this for initialization void Start() { curData = null; //Shader.SetGlobalVector("_HitData0", new Vector4(-10000f, -10000f, -10000f, 0.001f)); setSH9Global(); }
private void setSH9Global() { if (data != null && curData != data) { curData = data; for (int i = 0; i < 9; ++i) { string param = "g_sph" + i.ToString(); Shader.SetGlobalVector(param, data.coefficients[i]); } } }
private void setSH9Global() { //VirtualDirectLight0 if (data != null && curData != data) { curData = data; for (int i = 0; i < 9; ++i) { string param = "g_sph" + i.ToString(); Shader.SetGlobalVector(param, data.coefficients[i]); } } var v = Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(new Vector3(VirtualDirectLight0.x, VirtualDirectLight0.y, VirtualDirectLight0.z)), Vector3.one).MultiplyVector(Vector3.back); v.Normalize(); //Vector3.forward Shader.SetGlobalVector("VirtualDirectLight0", v); Shader.SetGlobalFloat("_DifSC", _DifSC); Shader.SetGlobalColor("_BackColor", _BackColor); Shader.SetGlobalFloat("sss_scatter0", sss_scatter0); Shader.SetGlobalFloat("_CullSepe", _CullSepe); }
private void OnGUI() { modle = EditorGUILayout.Toggle("CubeMap", modle); if (modle) { input_cubemap = EditorGUILayout.ObjectField("Input Cubemap", input_cubemap, typeof(Cubemap), true) as Cubemap; isCopyNew = EditorGUILayout.Toggle("从环境球获取", isCopyNew); if (input_cubemap != null) { EditorGUILayout.Space(); if (GUILayout.Button("CPU Uniform 9 Coefficients")) { Cubemap cm = input_cubemap; if (isCopyNew) { test = cm = CopyFromEnvMap(); } ModifyTextureReadable(); coefficients = new Vector4[9]; if (SphericalHarmonics.CPU_Project_Uniform_9Coeff(cm, coefficients)) { setSH9Global(); } if (isCopyNew) { GameObject.DestroyImmediate(cm, true); } } EditorGUILayout.Space(); if (GUILayout.Button("CPU Monte Carlo 9 Coefficients")) { Cubemap cm = input_cubemap; if (isCopyNew) { cm = CopyFromEnvMap(); } ModifyTextureReadable(); coefficients = new Vector4[9]; if (SphericalHarmonics.CPU_Project_MonteCarlo_9Coeff(cm, coefficients, 4096)) { setSH9Global(); } if (isCopyNew) { GameObject.DestroyImmediate(cm, true); } } EditorGUILayout.Space(); if (GUILayout.Button("GPU Uniform 9 Coefficients")) { Cubemap cm = input_cubemap; if (isCopyNew) { input_cubemap = cm = CopyFromEnvMap(); } ModifyTextureReadable(); coefficients = new Vector4[9]; if (SphericalHarmonics.GPU_Project_Uniform_9Coeff(cm, coefficients)) { setSH9Global(); } if (isCopyNew) { GameObject.DestroyImmediate(cm, true); } } EditorGUILayout.Space(); if (GUILayout.Button("GPU Monte Carlo 9 Coefficients")) { Cubemap cm = input_cubemap; if (isCopyNew) { cm = CopyFromEnvMap(); } ModifyTextureReadable(); coefficients = new Vector4[9]; if (SphericalHarmonics.GPU_Project_MonteCarlo_9Coeff(cm, coefficients)) { setSH9Global(); } if (isCopyNew) { GameObject.DestroyImmediate(cm, true); } } EditorGUILayout.Space(); } } else { env_map = EditorGUILayout.ObjectField("360环境球", env_map, typeof(Texture2D), true) as Texture2D; if (env_map) { sun = EditorGUILayout.Toggle("太阳", sun); } enableLight = EditorGUILayout.Toggle("灯光", enableLight); if (enableLight) { GUILayout.BeginHorizontal(); if (GUILayout.Button("+")) { lights.Add(null); } if (GUILayout.Button("-")) { if (lights.Count > 0) { lights.RemoveAt(lights.Count - 1); } } GUILayout.EndHorizontal(); for (int i = 0; i < lights.Count; i++) { lights[i] = EditorGUILayout.ObjectField("360环境球", lights[i], typeof(Light), true) as Light; } } bool hasLight = false; for (int i = 0; i < lights.Count; i++) { if (lights [i] != null) { hasLight = true; break; } } //lights if (hasLight || env_map != null) { EditorGUILayout.Space(); if (GUILayout.Button("CPU Uniform 9 Coefficients")) { ModifyTextureReadable(env_map); List <Light> ls = new List <Light> (); foreach (Light l in lights) { if (l != null) { ls.Add(l); } } coefficients = new Vector4[9]; if (SphericalHarmonics.CPU_Project_360HJQ(env_map, coefficients, 4096, sun, ls.ToArray())) { setSH9Global(); } } } } if (coefficients != null && coefficients.Length == 9) { if (GUILayout.Button("保存")) { SH9Data data = SH9Data.CreateInstance <SH9Data> (); data.coefficients = coefficients; string path = EditorUtility.SaveFilePanelInProject("Save SH9 Data", "ibl.asset", "asset", "Please enter a file name to save the texture to"); if (path.Length != 0) { if (System.IO.File.Exists(path)) { /*if (EditorUtility.DisplayDialog("目标已存在", "替换", "取消")) * { * * }*/ data.test = new Vector4(1, 0, 0, 1); data = AssetDatabase.LoadAssetAtPath <SH9Data> (path); data.coefficients = coefficients; AssetDatabase.SaveAssets(); } else { data.test = Vector4.one; AssetDatabase.CreateAsset(data, path); AssetDatabase.ImportAsset(path); } } } EditorGUILayout.Space(); for (int i = 0; i < 9; ++i) { EditorGUILayout.LabelField("c_" + i.ToString() + ": " + coefficients[i].ToString("f4")); } } EditorGUILayout.Space(); if (tmp != null) { GUILayout.Label(tmp); } }
// Use this for initialization void Start() { curData = null; setSH9Global(); }
private void setSH9Global() { if (oldFog) { Shader.DisableKeyword("ENABLE_NEW_FOG"); } else { Shader.EnableKeyword("ENABLE_NEW_FOG"); } //Shader.SetGlobalFloat("fog_b", fog_b* fog_b* fog_b); Shader.SetGlobalVector("FogInfo", new Vector4(fog_b * fog_b * fog_b, fog_end_in_view, fog_height, fog_begin_in_height)); Shader.SetGlobalColor("FogColor", new Color(FogColor.r, FogColor.g, FogColor.b, fog_dis_density)); //Shader.SetGlobalColor("FogColor2", new Color(FogColor2.r, FogColor2.g, FogColor2.b, fog_dis_density)); Shader.SetGlobalVector("FarSceneInfo", new Vector4(env_b * env_b * env_b, env_end_in_view, 0, 0)); Shader.SetGlobalColor("FarSceneColor", new Color(farSceneColor.r, farSceneColor.g, farSceneColor.b, env_dis_density)); Shader.SetGlobalVector("global_fog_max", new Vector4(fog_max, fog_max1, fog_max2, 1)); Shader.SetGlobalFloat("back_dis_density", back_dis_density * 2); Shader.SetGlobalVector("FogBackInfor", new Vector4((1f - height_fog_back_dis_density) * 0.5f, (1f - back_dis_density) * 0.5f, (1f - fog_back_dis_density) * 0.5f)); //Shader.SetGlobalFloat("back_dis_density", back_dis_density * 2); //public float fog_back_dis_density = 1f; //public float height_fog_back_dis_density = 1f; Shader.SetGlobalVector("HeightFogInfo", new Vector4(fog_height_density, fog_b * fog_b * fog_b, fog_hight_b, fog_max)); Shader.SetGlobalFloat("height_fog_end_in_view", height_fog_end_in_view); Shader.SetGlobalFloat("height_fog_height_a", 1f - height_fog_height_a); //VirtualDirectLight0 if (data != null && curData != data) { curData = data; for (int i = 0; i < 9; ++i) { string param = "g_sph" + i.ToString(); Shader.SetGlobalVector(param, data.coefficients[i]); } } if (farEvn != null && curFarEnv != farEvn) { curFarEnv = farEvn; for (int i = 0; i < 9; ++i) { string param = "evn_sph" + i.ToString(); Shader.SetGlobalVector(param, farEvn.coefficients[i]); } } float _density = density / Mathf.Sqrt(Mathf.Log(2)); float _densityH = densityH / Mathf.Sqrt(Mathf.Log(2)); float _color_density = color_density / Mathf.Sqrt(Mathf.Log(2)); //Shader.SetGlobalFloat("color_density", _color_density); Shader.SetGlobalFloat("env_density", _density); Shader.SetGlobalFloat("height_density", _densityH); Shader.SetGlobalFloat("color_density", color_density); Shader.SetGlobalFloat("globalEnvOffset", globalEnvOffset); //_POW_FOG_ON /*if (enable_dis) * { * Shader.EnableKeyword("_POW_FOG_ON"); * } * else * { * Shader.DisableKeyword("_POW_FOG_ON"); * }*/ /*if (enable_env) * { * Shader.EnableKeyword("ENABLE_DISTANCE_ENV"); * } * else * { * Shader.DisableKeyword("ENABLE_DISTANCE_ENV"); * }*/ if (enable_back_light) { Shader.EnableKeyword("ENABLE_BACK_LIGHT"); } else { Shader.DisableKeyword("ENABLE_BACK_LIGHT"); } if (farEvn) { Shader.EnableKeyword("GLOBAL_ENV_SH9"); } else { Shader.DisableKeyword("GLOBAL_ENV_SH9"); } Shader.SetGlobalFloat("fog_height_power", fog_height_power); var v = Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(new Vector3(VirtualDirectLight0.x, VirtualDirectLight0.y, VirtualDirectLight0.z)), Vector3.one).MultiplyVector(Vector3.back); v.Normalize(); //Vector3.forward Shader.SetGlobalVector("VirtualDirectLight0", v); Shader.SetGlobalVector("VirtualDirectLightColor0", new Vector4(virtualDirectLightColor0.r, virtualDirectLightColor0.g, virtualDirectLightColor0.b, virtualDirectLightColor0Intensity)); //virtualSceneDirectLightColor0 var v2 = Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(new Vector3(VirtualSceneDirectLight0.x, VirtualSceneDirectLight0.y, VirtualSceneDirectLight0.z)), Vector3.one).MultiplyVector(Vector3.back); v2.Normalize(); Shader.SetGlobalVector("VirtualDirectSceneLight0", v2); Shader.SetGlobalVector("VirtualScenDirectLightColor0", new Vector4(virtualSceneDirectLightColor0.r, virtualSceneDirectLightColor0.g, virtualSceneDirectLightColor0.b, virtualSceneDirectLightColor0Intensity)); // VirtualSceneDirectLight0 ;VirtualSceneDirectLight0; Shader.SetGlobalFloat("_DifSC", _DifSC); Shader.SetGlobalColor("_BackColor", _BackColor); Shader.SetGlobalFloat("sss_scatter0", sss_scatter0); Shader.SetGlobalFloat("_CullSepe", _CullSepe); //var v3 = Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(new Vector3(0f,140f, 0f)), Vector3.one).MultiplyVector(Vector3.back); //v3.Normalize(); //Debug.LogError(_BackColor); /*if (heightFog) * { * Shader.EnableKeyword("_HEIGHT_FOG_ON"); * //Shader.SetGlobalFloat("heightFogHeight", heightFogHeight); * //Shader.SetGlobalFloat("heightFogHeight2", heightFogHeight2); * //Shader.SetGlobalColor("farSceneColor", farSceneColor); * } * else * { * Shader.DisableKeyword("_HEIGHT_FOG_ON"); * }*/ }
// Use this for initialization void Start() { curData = null; curFarEnv = null; setSH9Global(); }
private void setSH9Global() { Shader.SetGlobalColor("GlobalTotalColor", GlobalTotalColor); Shader.SetGlobalFloat("GlobalHeightEffectPower", GlobalHeightEffectPower); //VirtualDirectLight0 if (data != null && curData != data) { curData = data; for (int i = 0; i < 9; ++i) { Shader.SetGlobalVector(g_sphs[i], data.coefficients[i]); } } var v = Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(new Vector3(VirtualDirectLight0.x, VirtualDirectLight0.y, VirtualDirectLight0.z)), Vector3.one).MultiplyVector(Vector3.back); v.Normalize(); //Vector3.forward Shader.SetGlobalVector("VirtualDirectLight0", v); Shader.SetGlobalVector("VirtualDirectLightColor0", new Vector4(virtualDirectLightColor0.r, virtualDirectLightColor0.g, virtualDirectLightColor0.b, virtualDirectLightColor0Intensity)); //virtualSceneDirectLightColor0 var v2 = Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(new Vector3(VirtualSceneDirectLight0.x, VirtualSceneDirectLight0.y, VirtualSceneDirectLight0.z)), Vector3.one).MultiplyVector(Vector3.back); v2.Normalize(); Shader.SetGlobalVector("VirtualDirectSceneLight0", v2); Shader.SetGlobalVector("VirtualScenDirectLightColor0", new Vector4(virtualSceneDirectLightColor0.r, virtualSceneDirectLightColor0.g, virtualSceneDirectLightColor0.b, virtualSceneDirectLightColor0Intensity)); // VirtualSceneDirectLight0 ;VirtualSceneDirectLight0; Shader.SetGlobalFloat("_DifSC", _DifSC); Shader.SetGlobalColor("_BackColor", _BackColor); Shader.SetGlobalFloat("sss_scatter0", sss_scatter0); Shader.SetGlobalFloat("_CullSepe", _CullSepe); Shader.SetGlobalColor("GlobalIntensityColor", GlobalIntensityColor); //var v3 = Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(new Vector3(0f,140f, 0f)), Vector3.one).MultiplyVector(Vector3.back); //v3.Normalize(); //Debug.LogError(_BackColor); /*if (heightFog) * { * Shader.EnableKeyword("_HEIGHT_FOG_ON"); * //Shader.SetGlobalFloat("heightFogHeight", heightFogHeight); * //Shader.SetGlobalFloat("heightFogHeight2", heightFogHeight2); * //Shader.SetGlobalColor("farSceneColor", farSceneColor); * } * else * { * Shader.DisableKeyword("_HEIGHT_FOG_ON"); * }*/ //Shader.SetGlobalFloat("_BakedNormalPower", _BakedNormalPower); //Shader.SetGlobalFloat("_BakedNormalBright", _BakedNormalBright); //public float _BakedNormalPower = 0.5f; //[Header("烘培后亮度")] //[Range(0, 1)] //public float _BakedNormalBright = 1.0f; }