public static void RefreshScene2(Scene scene, ftLightmapsStorage storage) { MeshRenderer r; int id; for (int i = 0; i < storage.bakedRenderers.Count; i++) { r = storage.bakedRenderers[i]; if (r == null) { continue; } id = storage.bakedIDs[i]; r.lightmapIndex = (id < 0 || id >= storage.idremap.Length) ? id : storage.idremap[id]; } Terrain r2; for (int i = 0; i < storage.bakedRenderersTerrain.Count; i++) { r2 = storage.bakedRenderersTerrain[i]; if (r2 == null) { continue; } id = storage.bakedIDsTerrain[i]; r2.lightmapIndex = (id < 0 || id >= storage.idremap.Length) ? id : storage.idremap[id]; } }
/* public static void RefreshScene(int sceneID, ref List<LightmapData> lmaps, int lmCounter) { * RefreshScene(scene); * }*/ static Texture2D GetEmptyDirectionTex(ftLightmapsStorage storage) { #if UNITY_EDITOR if (storage.emptyDirectionTex == null) { storage.emptyDirectionTex = AssetDatabase.LoadAssetAtPath("Assets/Bakery/emptyDirection.tga", typeof(Texture2D)) as Texture2D; } #endif return(storage.emptyDirectionTex); }
/* public static void RefreshScene(int sceneID, ref List<LightmapData> lmaps, int lmCounter) { * RefreshScene(scene); * }*/ static Texture2D GetEmptyDirectionTex(ftLightmapsStorage storage) { #if UNITY_EDITOR if (storage.emptyDirectionTex == null) { var bakeryRuntimePath = GetRuntimePath(); storage.emptyDirectionTex = AssetDatabase.LoadAssetAtPath(bakeryRuntimePath + "emptyDirection.tga", typeof(Texture2D)) as Texture2D; } #endif return(storage.emptyDirectionTex); }
public void CopySettings(ftLightmapsStorage src, ftLightmapsStorage dest) { dest.renderSettingsBounces = src.renderSettingsBounces; dest.renderSettingsGISamples = src.renderSettingsGISamples; dest.renderSettingsGIBackFaceWeight = src.renderSettingsGIBackFaceWeight; dest.renderSettingsTileSize = src.renderSettingsTileSize; dest.renderSettingsPriority = src.renderSettingsPriority; dest.renderSettingsTexelsPerUnit = src.renderSettingsTexelsPerUnit; dest.renderSettingsForceRefresh = src.renderSettingsForceRefresh; dest.renderSettingsForceRebuildGeometry = src.renderSettingsForceRebuildGeometry; dest.renderSettingsPerformRendering = src.renderSettingsPerformRendering; dest.renderSettingsUserRenderMode = src.renderSettingsUserRenderMode; dest.renderSettingsDistanceShadowmask = src.renderSettingsDistanceShadowmask; dest.renderSettingsSettingsMode = src.renderSettingsSettingsMode; dest.renderSettingsFixSeams = src.renderSettingsFixSeams; dest.renderSettingsDenoise = src.renderSettingsDenoise; dest.renderSettingsEncode = src.renderSettingsEncode; dest.renderSettingsEncodeMode = src.renderSettingsEncodeMode; dest.renderSettingsOverwriteWarning = src.renderSettingsOverwriteWarning; dest.renderSettingsAutoAtlas = src.renderSettingsAutoAtlas; dest.renderSettingsUnwrapUVs = src.renderSettingsUnwrapUVs; dest.renderSettingsMaxAutoResolution = src.renderSettingsMaxAutoResolution; dest.renderSettingsMinAutoResolution = src.renderSettingsMinAutoResolution; dest.renderSettingsUnloadScenes = src.renderSettingsUnloadScenes; dest.renderSettingsGILODMode = src.renderSettingsGILODMode; dest.renderSettingsGILODModeEnabled = src.renderSettingsGILODModeEnabled; dest.renderSettingsCheckOverlaps = src.renderSettingsCheckOverlaps; dest.renderSettingsSkipOutOfBoundsUVs = src.renderSettingsSkipOutOfBoundsUVs; dest.renderSettingsHackEmissiveBoost = src.renderSettingsHackEmissiveBoost; dest.renderSettingsHackIndirectBoost = src.renderSettingsHackIndirectBoost; dest.renderSettingsTempPath = src.renderSettingsTempPath; dest.renderSettingsOutPath = src.renderSettingsOutPath; dest.renderSettingsHackAOIntensity = src.renderSettingsHackAOIntensity; dest.renderSettingsHackAOSamples = src.renderSettingsHackAOSamples; dest.renderSettingsHackAORadius = src.renderSettingsHackAORadius; dest.renderSettingsShowAOSettings = src.renderSettingsShowAOSettings; dest.renderSettingsShowTasks = src.renderSettingsShowTasks; dest.renderSettingsShowTasks2 = src.renderSettingsShowTasks2; dest.renderSettingsShowPaths = src.renderSettingsShowPaths; dest.renderSettingsOcclusionProbes = src.renderSettingsOcclusionProbes; dest.renderSettingsTexelsPerMap = src.renderSettingsTexelsPerMap; dest.renderSettingsTexelsColor = src.renderSettingsTexelsColor; dest.renderSettingsTexelsMask = src.renderSettingsTexelsMask; dest.renderSettingsTexelsDir = src.renderSettingsTexelsDir; dest.renderSettingsShowDirWarning = src.renderSettingsShowDirWarning; dest.renderSettingsRenderDirMode = src.renderSettingsRenderDirMode; dest.renderSettingsShowCheckerSettings = src.renderSettingsShowCheckerSettings; dest.renderSettingsSamplesWarning = src.renderSettingsSamplesWarning; dest.renderSettingsPrefabWarning = src.renderSettingsPrefabWarning; dest.renderSettingsSplitByScene = src.renderSettingsSplitByScene; dest.renderSettingsUVPaddingMax = src.renderSettingsUVPaddingMax; dest.renderSettingsBeepOnFinish = src.renderSettingsBeepOnFinish; }
public static void CopySettings(ftGlobalStorage src, ftLightmapsStorage dest) { dest.renderSettingsBounces = src.renderSettingsBounces; dest.renderSettingsGISamples = src.renderSettingsGISamples; dest.renderSettingsGIBackFaceWeight = src.renderSettingsGIBackFaceWeight; dest.renderSettingsTileSize = src.renderSettingsTileSize; dest.renderSettingsPriority = src.renderSettingsPriority; dest.renderSettingsTexelsPerUnit = src.renderSettingsTexelsPerUnit; dest.renderSettingsForceRefresh = src.renderSettingsForceRefresh; dest.renderSettingsForceRebuildGeometry = src.renderSettingsForceRebuildGeometry; dest.renderSettingsPerformRendering = src.renderSettingsPerformRendering; dest.renderSettingsUserRenderMode = src.renderSettingsUserRenderMode; dest.renderSettingsDistanceShadowmask = src.renderSettingsDistanceShadowmask; dest.renderSettingsSettingsMode = src.renderSettingsSettingsMode; dest.renderSettingsFixSeams = src.renderSettingsFixSeams; dest.renderSettingsDenoise = src.renderSettingsDenoise; dest.renderSettingsDenoise2x = src.renderSettingsDenoise2x; dest.renderSettingsEncode = src.renderSettingsEncode; dest.renderSettingsEncodeMode = src.renderSettingsEncodeMode; dest.renderSettingsOverwriteWarning = src.renderSettingsOverwriteWarning; dest.renderSettingsAutoAtlas = src.renderSettingsAutoAtlas; dest.renderSettingsUnwrapUVs = src.renderSettingsUnwrapUVs; dest.renderSettingsForceDisableUnwrapUVs = src.renderSettingsForceDisableUnwrapUVs; dest.renderSettingsMaxAutoResolution = src.renderSettingsMaxAutoResolution; dest.renderSettingsMinAutoResolution = src.renderSettingsMinAutoResolution; dest.renderSettingsUnloadScenes = src.renderSettingsUnloadScenes; dest.renderSettingsAdjustSamples = src.renderSettingsAdjustSamples; dest.renderSettingsGILODMode = src.renderSettingsGILODMode; dest.renderSettingsGILODModeEnabled = src.renderSettingsGILODModeEnabled; dest.renderSettingsCheckOverlaps = src.renderSettingsCheckOverlaps; dest.renderSettingsSkipOutOfBoundsUVs = src.renderSettingsSkipOutOfBoundsUVs; dest.renderSettingsHackEmissiveBoost = src.renderSettingsHackEmissiveBoost; dest.renderSettingsHackIndirectBoost = src.renderSettingsHackIndirectBoost; dest.renderSettingsTempPath = src.renderSettingsTempPath; dest.renderSettingsOutPath = src.renderSettingsOutPath; dest.renderSettingsUseScenePath = src.renderSettingsUseScenePath; dest.renderSettingsHackAOIntensity = src.renderSettingsHackAOIntensity; dest.renderSettingsHackAOSamples = src.renderSettingsHackAOSamples; dest.renderSettingsHackAORadius = src.renderSettingsHackAORadius; dest.renderSettingsShowAOSettings = src.renderSettingsShowAOSettings; dest.renderSettingsShowTasks = src.renderSettingsShowTasks; dest.renderSettingsShowTasks2 = src.renderSettingsShowTasks2; dest.renderSettingsShowPaths = src.renderSettingsShowPaths; dest.renderSettingsShowNet = src.renderSettingsShowNet; dest.renderSettingsOcclusionProbes = src.renderSettingsOcclusionProbes; dest.renderSettingsTexelsPerMap = src.renderSettingsTexelsPerMap; dest.renderSettingsTexelsColor = src.renderSettingsTexelsColor; dest.renderSettingsTexelsMask = src.renderSettingsTexelsMask; dest.renderSettingsTexelsDir = src.renderSettingsTexelsDir; dest.renderSettingsShowDirWarning = src.renderSettingsShowDirWarning; dest.renderSettingsRenderDirMode = src.renderSettingsRenderDirMode; dest.renderSettingsShowCheckerSettings = src.renderSettingsShowCheckerSettings; dest.renderSettingsSamplesWarning = src.renderSettingsSamplesWarning; dest.renderSettingsPrefabWarning = src.renderSettingsPrefabWarning; dest.renderSettingsSplitByScene = src.renderSettingsSplitByScene; dest.renderSettingsUVPaddingMax = src.renderSettingsUVPaddingMax; dest.renderSettingsPostPacking = src.renderSettingsPostPacking; dest.renderSettingsHoleFilling = src.renderSettingsHoleFilling; dest.renderSettingsBeepOnFinish = src.renderSettingsBeepOnFinish; dest.renderSettingsExportTerrainAsHeightmap = src.renderSettingsExportTerrainAsHeightmap; dest.renderSettingsRTXMode = src.renderSettingsRTXMode; dest.renderSettingsLightProbeMode = src.renderSettingsLightProbeMode; dest.renderSettingsClientMode = src.renderSettingsClientMode; dest.renderSettingsServerAddress = src.renderSettingsServerAddress; dest.renderSettingsUnwrapper = src.renderSettingsUnwrapper; dest.renderSettingsDenoiserType = src.renderSettingsDenoiserType; dest.renderSettingsExportTerrainTrees = src.renderSettingsExportTerrainTrees; dest.renderSettingsShowPerf = src.renderSettingsShowPerf; dest.renderSettingsSampleDiv = src.renderSettingsSampleDiv; dest.renderSettingsBatchPoints = src.renderSettingsBatchPoints; dest.renderSettingsRTPVExport = src.renderSettingsRTPVExport; dest.renderSettingsRTPVSceneView = src.renderSettingsRTPVSceneView; dest.renderSettingsRTPVWidth = src.renderSettingsRTPVWidth; dest.renderSettingsRTPVHeight = src.renderSettingsRTPVHeight; dest.renderSettingsAtlasPacker = src.renderSettingsAtlasPacker; dest.renderSettingsAutoAtlas = src.renderSettingsAutoAtlas; }
public override void OnInspectorGUI() { { serializedObject.Update(); TestPreviewRefreshProperty(ref texCached, ftraceLightTexture.objectReferenceValue); EditorGUILayout.PropertyField(ftraceLightColor, new GUIContent("Color", "Sky color. Multiplies texture color.")); EditorGUILayout.PropertyField(ftraceLightIntensity, new GUIContent("Intensity", "Color multiplier")); EditorGUILayout.PropertyField(ftraceLightTexture, new GUIContent("Sky texture", "Cubemap")); if (ftraceLightTexture.objectReferenceValue != null) { var angles = (target as BakerySkyLight).transform.eulerAngles; EditorGUILayout.LabelField("Cubemap angles: " + angles.x + ", " + angles.y + ", " + angles.z); EditorGUILayout.LabelField("Rotate this GameObject to change cubemap angles."); EditorGUILayout.Space(); } EditorGUILayout.PropertyField(ftraceLightSamples, new GUIContent("Samples", "The amount of rays tested for this light. Rays are emitted hemispherically.")); EditorGUILayout.PropertyField(ftraceLightHemi, new GUIContent("Hemispherical", "Only emit light from upper hemisphere")); //ftraceLightBitmask.intValue = EditorGUILayout.MaskField(new GUIContent("Bitmask", "Lights only affect renderers with overlapping bits"), ftraceLightBitmask.intValue, selStrings); int prevVal = ftraceLightBitmask.intValue; int newVal = EditorGUILayout.MaskField(new GUIContent("Bitmask", "Lights only affect renderers with overlapping bits"), ftraceLightBitmask.intValue, selStrings); if (prevVal != newVal) { ftraceLightBitmask.intValue = newVal; } //EditorGUILayout.PropertyField(ftraceLightBakeToIndirect, new GUIContent("Bake to indirect", "Add direct contribution from this light to indirect-only lightmaps")); if (storage == null) { storage = ftRenderLightmap.FindRenderSettingsStorage(); } var rmode = storage.renderSettingsUserRenderMode; if (rmode != (int)ftRenderLightmap.RenderMode.FullLighting) { ftDirectLightInspector.BakeWhat contrib; if (ftraceLightBakeToIndirect.boolValue) { contrib = ftDirectLightInspector.BakeWhat.DirectAndIndirect; } else { contrib = ftDirectLightInspector.BakeWhat.IndirectOnly; } var prevContrib = contrib; contrib = (ftDirectLightInspector.BakeWhat)EditorGUILayout.Popup("Baked contribution", (int)contrib, directContributionOptions); if (prevContrib != contrib) { if (contrib == ftDirectLightInspector.BakeWhat.IndirectOnly) { ftraceLightBakeToIndirect.boolValue = false; } else { ftraceLightBakeToIndirect.boolValue = true; } } } EditorGUILayout.PropertyField(ftraceLightIndirectIntensity, new GUIContent("Indirect intensity", "Non-physical GI multiplier for this light")); showExperimental = EditorGUILayout.Foldout(showExperimental, "Experimental", EditorStyles.foldout); if (showExperimental) { EditorGUILayout.PropertyField(ftraceTangentSH, new GUIContent("Tangent-space SH", "Only affects single-color skylights. When baking in SH mode, harmonics will be in tangent space. Can be useful for implementing skinned model specular occlusion in custom shaders.")); } serializedObject.ApplyModifiedProperties(); } var skyMat = RenderSettings.skybox; bool match = false; bool skyboxValid = true; string why = ""; if (skyMat != null) { if (skyMat.HasProperty("_Tex") && skyMat.HasProperty("_Exposure") && skyMat.HasProperty("_Tint")) { if (skyMat.GetTexture("_Tex") == ftraceLightTexture.objectReferenceValue) { float exposure = skyMat.GetFloat("_Exposure"); bool exposureSRGB = skyMat.shader.name == "Skybox/Cubemap"; if (exposureSRGB) { exposure = Mathf.Pow(exposure, 2.2f); // can't detect [Gamma] keyword... exposure *= PlayerSettings.colorSpace == ColorSpace.Linear ? 4.59f : 2; // weird unity constant } if (Mathf.Abs(exposure - ftraceLightIntensity.floatValue) < 0.0001f) { if (skyMat.GetColor("_Tint") == ftraceLightColor.colorValue) { bool anglesMatch = true; var angles = (target as BakerySkyLight).transform.eulerAngles; Vector3 matMatrixX = Vector3.right; Vector3 matMatrixY = Vector3.up; Vector3 matMatrixZ = Vector3.forward; float matAngleY = 0; bool hasYAngle = skyMat.HasProperty("_Rotation"); bool hasXZAngles = skyMat.HasProperty("_MatrixRight"); if (hasYAngle) { matAngleY = skyMat.GetFloat("_Rotation"); } if (hasXZAngles) { matMatrixX = skyMat.GetVector("_MatrixRight"); matMatrixY = skyMat.GetVector("_MatrixUp"); matMatrixZ = skyMat.GetVector("_MatrixForward"); } if (angles.y != 0 && !hasYAngle) { anglesMatch = false; why = "no _Rotation property, but light is rotated"; } else if ((angles.x != 0 || angles.z != 0) && !hasXZAngles) { anglesMatch = false; why = "shader doesn't allow XZ rotation"; } else { var lightQuat = (target as BakerySkyLight).transform.rotation; Quaternion matQuat; if (hasXZAngles) { var mtx = new Matrix4x4(); mtx.SetColumn(0, new Vector4(matMatrixX.x, matMatrixX.y, matMatrixX.z, 0)); mtx.SetColumn(1, new Vector4(matMatrixY.x, matMatrixY.y, matMatrixY.z, 0)); mtx.SetColumn(2, new Vector4(matMatrixZ.x, matMatrixZ.y, matMatrixZ.z, 0)); matQuat = QuaternionFromMatrix(mtx); } else { matQuat = Quaternion.Euler(0, matAngleY, 0); } float diff = Quaternion.Angle(matQuat, lightQuat); //Debug.Log("d " + diff); if (Mathf.Abs(diff) > 0.01f) { anglesMatch = false; why = "angles don't match"; } } if (anglesMatch) { match = true; } } else { why = "color doesn't match"; } } else { why = "exposure doesn't match"; } } else { why = "texture doesn't match"; } } else { if (!skyMat.HasProperty("_Tex")) { why += "_Tex "; } if (!skyMat.HasProperty("_Exposure")) { why += "_Exposure "; } if (!skyMat.HasProperty("_Tint")) { why += "_Tint "; } why += "not defined"; skyboxValid = false; } } else { why = "no skybox set"; skyboxValid = false; } if (!match) { EditorGUILayout.Space(); EditorGUILayout.LabelField("Skylight doesn't match skybox: " + why); EditorGUILayout.Space(); if (skyboxValid) { if (GUILayout.Button("Match this light to scene skybox")) { ftraceLightTexture.objectReferenceValue = skyMat.GetTexture("_Tex"); float exposure = skyMat.GetFloat("_Exposure"); bool exposureSRGB = skyMat.shader.name == "Skybox/Cubemap"; if (exposureSRGB) { exposure = Mathf.Pow(exposure, 2.2f); // can't detect [Gamma] keyword... exposure *= PlayerSettings.colorSpace == ColorSpace.Linear ? 4.59f : 2; // weird unity constant } ftraceLightIntensity.floatValue = exposure; ftraceLightColor.colorValue = skyMat.GetColor("_Tint"); float matAngle = 0; if (skyMat.HasProperty("_Rotation")) { matAngle = skyMat.GetFloat("_Rotation"); } var matQuat = Quaternion.Euler(0, matAngle, 0); Undo.RecordObject((target as BakerySkyLight).transform, "Rotate skylight"); (target as BakerySkyLight).transform.rotation = matQuat; serializedObject.ApplyModifiedProperties(); } } if (GUILayout.Button("Match scene skybox to this light")) { var tform = (target as BakerySkyLight).transform; var angles = tform.eulerAngles; if (angles.x != 0 || angles.z != 0) { if (skyboxValid && !skyMat.HasProperty("_MatrixRight")) { skyboxValid = false; // only ftrace skybox can handle xz rotation for now } } if (angles.y != 0 && skyboxValid && !skyMat.HasProperty("_Rotation")) { skyboxValid = false; // needs _Rotation for Y angle } if (!skyboxValid) { var outputPath = ftRenderLightmap.outputPath; skyMat = new Material(Shader.Find(ftSkyboxShaderName)); if (!Directory.Exists("Assets/" + outputPath)) { Directory.CreateDirectory("Assets/" + outputPath); } AssetDatabase.CreateAsset(skyMat, "Assets/" + outputPath + "/" + SceneManager.GetActiveScene().name + "_skybox.asset"); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); } skyMat.SetTexture("_Tex", ftraceLightTexture.objectReferenceValue as Cubemap); skyMat.SetFloat("_NoTexture", ftraceLightTexture.objectReferenceValue == null ? 1 : 0); float exposure = ftraceLightIntensity.floatValue; bool exposureSRGB = skyMat.shader.name == "Skybox/Cubemap"; if (exposureSRGB) { exposure /= PlayerSettings.colorSpace == ColorSpace.Linear ? 4.59f : 2; // weird unity constant exposure = Mathf.Pow(exposure, 1.0f / 2.2f); // can't detect [Gamma] keyword... } skyMat.SetFloat("_Exposure", exposure); skyMat.SetColor("_Tint", ftraceLightColor.colorValue); if (skyMat.HasProperty("_Rotation")) { skyMat.SetFloat("_Rotation", angles.y); } if (skyMat.HasProperty("_MatrixRight")) { skyMat.SetVector("_MatrixRight", tform.right); } if (skyMat.HasProperty("_MatrixUp")) { skyMat.SetVector("_MatrixUp", tform.up); } if (skyMat.HasProperty("_MatrixForward")) { skyMat.SetVector("_MatrixForward", tform.forward); } RenderSettings.skybox = skyMat; EditorUtility.SetDirty(skyMat); } EditorGUILayout.Space(); EditorGUILayout.Space(); } }
public override void OnInspectorGUI() { //if (showFtrace) //{ OnEnable(); serializedObject.Update(); EditorGUILayout.PropertyField(ftraceLightColor, new GUIContent("Color", "Color of the light")); EditorGUILayout.PropertyField(ftraceLightIntensity, new GUIContent("Intensity", "Color multiplier (Lux / Pi)")); EditorGUILayout.PropertyField(ftraceLightShadowSpread, new GUIContent("Shadow spread", "Controls shadow blurriness from 0 to 1")); EditorGUILayout.PropertyField(ftraceLightSamples, new GUIContent("Shadow samples", "The amount of rays tested for this light. Rays are emitted from lightmap texel towards the light, distributed conically. Radius of the cone depends on Shadow Spread.")); //ftraceLightBitmask.intValue = EditorGUILayout.MaskField(new GUIContent("Bitmask", "Lights only affect renderers with overlapping bits"), ftraceLightBitmask.intValue, selStrings); int prevVal = ftraceLightBitmask.intValue; int newVal = EditorGUILayout.MaskField(new GUIContent("Bitmask", "Lights only affect renderers with overlapping bits"), ftraceLightBitmask.intValue, selStrings); if (prevVal != newVal) { ftraceLightBitmask.intValue = newVal; } /* * EditorGUILayout.PropertyField(ftraceLightBakeToIndirect, new GUIContent("Bake to indirect", "Add direct contribution from this light to indirect-only lightmaps")); * if (ftraceLightBakeToIndirect.boolValue && ftraceLightShadowmask.boolValue) ftraceLightShadowmask.boolValue = false; * * EditorGUILayout.PropertyField(ftraceLightShadowmask, new GUIContent("Shadowmask", "Enable mixed lighting. Static shadows from this light will be baked, and real-time light will cast shadows from dynamic objects.")); * if (ftraceLightBakeToIndirect.boolValue && ftraceLightShadowmask.boolValue) ftraceLightBakeToIndirect.boolValue = false; */ if (storage == null) { storage = ftRenderLightmap.FindRenderSettingsStorage(); } var rmode = storage.renderSettingsUserRenderMode; if (rmode != (int)ftRenderLightmap.RenderMode.FullLighting) { BakeWhat contrib; if (ftraceLightShadowmask.boolValue) { contrib = BakeWhat.IndirectAndShadowmask; } else if (ftraceLightBakeToIndirect.boolValue) { contrib = BakeWhat.DirectAndIndirect; } else { contrib = BakeWhat.IndirectOnly; } var prevContrib = contrib; if (rmode == (int)ftRenderLightmap.RenderMode.Indirect) { contrib = (BakeWhat)EditorGUILayout.Popup("Baked contribution", (int)contrib, directContributionIndirectOptions); } else if (rmode == (int)ftRenderLightmap.RenderMode.Shadowmask) { contrib = (BakeWhat)EditorGUILayout.EnumPopup("Baked contribution", contrib); } if (prevContrib != contrib) { if (contrib == BakeWhat.IndirectOnly) { ftraceLightShadowmask.boolValue = false; ftraceLightBakeToIndirect.boolValue = false; } else if (contrib == BakeWhat.IndirectAndShadowmask) { ftraceLightShadowmask.boolValue = true; ftraceLightBakeToIndirect.boolValue = false; } else { ftraceLightShadowmask.boolValue = false; ftraceLightBakeToIndirect.boolValue = true; } } if (ftraceLightShadowmask.boolValue) { EditorGUILayout.PropertyField(ftraceLightShadowmaskDenoise, new GUIContent("Denoise shadowmask", "Apply denoising to shadowmask texture. For sharp shadows it may be unnecessary.")); } } EditorGUILayout.PropertyField(ftraceLightIndirectIntensity, new GUIContent("Indirect intensity", "Non-physical GI multiplier for this light")); serializedObject.ApplyModifiedProperties(); //} bool showError = false; string why = ""; bool shadowmaskNoDynamicLight = false; foreach (BakeryDirectLight selectedLight in targets) { bool match = true; var light = selectedLight.GetComponent <Light>(); if (light == null) { if (ftraceLightShadowmask.boolValue) { shadowmaskNoDynamicLight = true; } continue; } if (!light.enabled) { if (ftraceLightShadowmask.boolValue) { shadowmaskNoDynamicLight = true; } } var so = new SerializedObject(selectedLight); InitSerializedProperties(so); if (light.type != LightType.Directional) { match = false; why = "real-time light is not direct"; } if (light.bounceIntensity != ftraceLightIndirectIntensity.floatValue) { match = false; why = "indirect intensity doesn't match"; } var clr = ftraceLightColor.colorValue; float eps = 1.0f / 255.0f; float lightR, lightG, lightB, lightInt; float fr, fg, fb; float fintensity = ftraceLightIntensity.floatValue; if (isHDRP) { fintensity *= Mathf.PI; } if (PlayerSettings.colorSpace == ColorSpace.Linear) { fr = clr.linear.r; // * fintensity; fg = clr.linear.g; // * fintensity; fb = clr.linear.b; // * fintensity; } else { fr = clr.r; fg = clr.g; fb = clr.b; } GetLinearLightParameters(light, out lightR, out lightG, out lightB, out lightInt); if (GraphicsSettings.lightsUseLinearIntensity || PlayerSettings.colorSpace != ColorSpace.Linear) { if (Mathf.Abs(lightR - fr) > eps || Mathf.Abs(lightG - fg) > eps || Mathf.Abs(lightB - fb) > eps) { match = false; why = "color doesn't match"; } else if (Mathf.Abs(lightInt - fintensity) > eps) { match = false; why = "intensity doesn't match"; } } else { eps *= Mathf.Max(lightInt, fintensity); if (Mathf.Abs(lightR * lightInt - fr * fintensity) > eps || Mathf.Abs(lightG * lightInt - fg * fintensity) > eps || Mathf.Abs(lightB * lightInt - fb * fintensity) > eps) { match = false; why = "intensity doesn't match"; } } if (!match) { showError = true; } } if (shadowmaskNoDynamicLight) { EditorGUILayout.Space(); EditorGUILayout.LabelField("Warning: shadowmask needs enabled real-time light to work"); } if (showError) { EditorGUILayout.Space(); EditorGUILayout.LabelField("Real-time light doesn't match lightmap: " + why); if (GUILayout.Button("Match lightmapped to real-time")) { foreach (BakeryDirectLight selectedLight in targets) { var light = selectedLight.GetComponent <Light>(); if (light == null) { continue; } //if (!light.enabled) continue; var so = new SerializedObject(selectedLight); InitSerializedProperties(so); if (PlayerSettings.colorSpace != ColorSpace.Linear) { ftraceLightColor.colorValue = light.color; ftraceLightIntensity.floatValue = light.intensity; } else if (!GraphicsSettings.lightsUseLinearIntensity) { float lightR, lightG, lightB, lightInt; GetLinearLightParameters(light, out lightR, out lightG, out lightB, out lightInt); ftraceLightColor.colorValue = new Color(lightR, lightG, lightB); ftraceLightIntensity.floatValue = lightInt; } else { ftraceLightColor.colorValue = light.color; ftraceLightIntensity.floatValue = light.intensity; } ftraceLightIndirectIntensity.floatValue = light.bounceIntensity; if (isHDRP) { ftraceLightIntensity.floatValue /= Mathf.PI; } so.ApplyModifiedProperties(); } } if (GUILayout.Button("Match real-time to lightmapped")) { foreach (BakeryDirectLight selectedLight in targets) { var light = selectedLight.GetComponent <Light>(); if (light == null) { continue; } //if (!light.enabled) continue; var so = new SerializedObject(selectedLight); InitSerializedProperties(so); Undo.RecordObject(light, "Change light"); if (PlayerSettings.colorSpace != ColorSpace.Linear) { light.color = ftraceLightColor.colorValue; light.intensity = ftraceLightIntensity.floatValue; } else if (!GraphicsSettings.lightsUseLinearIntensity) { float fr, fg, fb; float fintensity = ftraceLightIntensity.floatValue; var clr = ftraceLightColor.colorValue; fr = clr.linear.r; // * fintensity; fg = clr.linear.g; // * fintensity; fb = clr.linear.b; // * fintensity; fr = Mathf.Pow(fr * fintensity, 1.0f / 2.2f); fg = Mathf.Pow(fg * fintensity, 1.0f / 2.2f); fb = Mathf.Pow(fb * fintensity, 1.0f / 2.2f); float fint = Mathf.Max(Mathf.Max(fr, fg), fb); fr /= fint; fg /= fint; fb /= fint; light.color = new Color(fr, fg, fb); light.intensity = fint; } else { light.color = ftraceLightColor.colorValue; light.intensity = ftraceLightIntensity.floatValue; } light.type = LightType.Directional; light.bounceIntensity = ftraceLightIndirectIntensity.floatValue; if (isHDRP) { SetHDRPLight(light); } } } } if (PlayerSettings.colorSpace == ColorSpace.Linear) { if (!GraphicsSettings.lightsUseLinearIntensity) { EditorGUILayout.Space(); EditorGUILayout.LabelField("Warning: project is not set up to use linear light intensity."); EditorGUILayout.LabelField("GraphicsSettings.lightsUseLinearIntensity should be TRUE."); if (GUILayout.Button("Fix")) { GraphicsSettings.lightsUseLinearIntensity = true; } } else { EditorGUILayout.Space(); EditorGUILayout.LabelField("Project is using linear light intensity. This is nice."); if (GUILayout.Button("Change to non-linear")) { GraphicsSettings.lightsUseLinearIntensity = false; } } } }
public override void OnInspectorGUI() { //if (showFtrace) { OnEnable(); serializedObject.Update(); EditorGUILayout.PropertyField(ftraceLightColor, new GUIContent("Color", "Color of the light")); EditorGUILayout.PropertyField(ftraceLightIntensity, new GUIContent("Intensity", "Color multiplier")); EditorGUILayout.PropertyField(ftraceLightTexture, new GUIContent("Texture", "Texture")); EditorGUILayout.PropertyField(ftraceLightCutoff, new GUIContent("Cutoff", "Lighting distance limit. For maximum physical corectness set to a very high value. Using smaller values is useful for faster render times and to match real-time lights. Bakery uses Skyforge falloff to maintain balance between correct inverse-squared attenuation and practical limits (https://habr.com/company/mailru/blog/248873/)")); if (ftraceLightSelfShadow.boolValue) { EditorGUILayout.PropertyField(ftraceLightSamples2, new GUIContent("Samples Near", "The amount of rays traced hemispherically in the proximity of this mesh. Set to 0 to only trace with 'Samples Far'.")); } else { ftraceLightSamples2.intValue = 0; } EditorGUILayout.PropertyField(ftraceLightSamples, new GUIContent("Samples Far", "The amount of sample points generated on the surface of this mesh. Distant mesh lights are approximated as clouds of directed half-point lights.")); //ftraceLightBitmask.intValue = EditorGUILayout.MaskField(new GUIContent("Bitmask", "Lights only affect renderers with overlapping bits"), ftraceLightBitmask.intValue, selStrings); int prevVal = ftraceLightBitmask.intValue; int newVal = EditorGUILayout.MaskField(new GUIContent("Bitmask", "Lights only affect renderers with overlapping bits"), ftraceLightBitmask.intValue, selStrings); if (prevVal != newVal) { ftraceLightBitmask.intValue = newVal; } EditorGUILayout.PropertyField(ftraceLightSelfShadow, new GUIContent("Self shadow", "Determines if light mesh itself casts shadows.")); //EditorGUILayout.PropertyField(ftraceLightBakeToIndirect, new GUIContent("Bake to indirect", "Add direct contribution from this light to indirect-only lightmaps")); if (storage == null) { storage = ftRenderLightmap.FindRenderSettingsStorage(); } var rmode = storage.renderSettingsUserRenderMode; if (rmode != (int)ftRenderLightmap.RenderMode.FullLighting) { ftDirectLightInspector.BakeWhat contrib; if (ftraceLightBakeToIndirect.boolValue) { contrib = ftDirectLightInspector.BakeWhat.DirectAndIndirect; } else { contrib = ftDirectLightInspector.BakeWhat.IndirectOnly; } var prevContrib = contrib; contrib = (ftDirectLightInspector.BakeWhat)EditorGUILayout.Popup("Baked contribution", (int)contrib, ftSkyLightInspector.directContributionOptions); if (prevContrib != contrib) { if (contrib == ftDirectLightInspector.BakeWhat.IndirectOnly) { ftraceLightBakeToIndirect.boolValue = false; } else { ftraceLightBakeToIndirect.boolValue = true; } } } EditorGUILayout.PropertyField(ftraceLightIndirectIntensity, new GUIContent("Indirect intensity", "Non-physical GI multiplier for this light")); serializedObject.ApplyModifiedProperties(); } bool showError = false; string showErrorText = ""; bool isAreaLight = false; bool isMesh = false; var materialValid = new bool[targets.Length]; int iterator = -1; int numMaterialValid = targets.Length; foreach (BakeryLightMesh selectedLight in targets) { iterator++; var so = new SerializedObject(selectedLight); InitSerializedProperties(so); var mr = selectedLight.GetComponent <MeshRenderer>(); var mf = selectedLight.GetComponent <MeshFilter>(); var areaLight = selectedLight.GetComponent <Light>(); if (areaLight != null && areaLight.type != LightType.Area) { areaLight = null; } if (mr == null && areaLight == null) { showError = true; showErrorText = "Error: no mesh renderer"; continue; } if (mf == null && areaLight == null) { showError = true; showErrorText = "Error: no mesh filter"; continue; } float intensity = ftraceLightIntensity.floatValue; var clr = ftraceLightColor.colorValue; if (areaLight != null) { bool match = true; string why = ""; isAreaLight = true; float eps = 1.0f / 255.0f; float lightR, lightG, lightB, lightInt; float fr, fg, fb; if (UnityEditor.PlayerSettings.colorSpace == ColorSpace.Linear) { fr = clr.linear.r; // * fintensity; fg = clr.linear.g; // * fintensity; fb = clr.linear.b; // * fintensity; } else { fr = clr.r; fg = clr.g; fb = clr.b; } GetLinearLightParameters(areaLight, out lightR, out lightG, out lightB, out lightInt); if (GraphicsSettings.lightsUseLinearIntensity || UnityEditor.PlayerSettings.colorSpace != ColorSpace.Linear) { if (Mathf.Abs(lightR - fr) > eps || Mathf.Abs(lightG - fg) > eps || Mathf.Abs(lightB - fb) > eps) { match = false; why = "color doesn't match"; } else if (Mathf.Abs(lightInt - intensity) > eps) { match = false; why = "intensity doesn't match"; } } else { eps *= Mathf.Max(lightInt, intensity); if (Mathf.Abs(lightR * lightInt - fr * intensity) > eps || Mathf.Abs(lightG * lightInt - fg * intensity) > eps || Mathf.Abs(lightB * lightInt - fb * intensity) > eps) { match = false; why = "intensity doesn't match"; } } if (Mathf.Abs(ftraceLightCutoff.floatValue - areaLight.range * 1.5f) > 0.01f) { match = false; why = "range doesn't match"; } if (ftraceLightSelfShadow.boolValue) { match = false; why = "area light is not self-shadowed."; } if (areaLight.bounceIntensity != ftraceLightIndirectIntensity.floatValue) { match = false; why = "indirect intensity doesn't match"; } if (!match) { //EditorGUILayout.Space(); //EditorGUILayout.LabelField("Real-time light doesn't match lightmap: " + why); showError = true; showErrorText = "Area light doesn't match lightmap: " + why; } continue; } materialValid[iterator] = true; Material singleMat = null; var mats = mr.sharedMaterials; if (mats.Length == 0 || mats[0] == null) { showError = true; showErrorText = "Error: no materials set"; continue; } isMesh = true; for (int i = 0; i < mats.Length; i++) { var mat = mats[i]; if (singleMat == null) { singleMat = mat; } if (mat != null && mat != singleMat) { showError = true; showErrorText = "Error: different materials in mesh"; //match = false; materialValid[iterator] = false; numMaterialValid--; break; } if (mat == null) { showError = true; showErrorText = "Error: mesh doesn't have all materials set"; //match = false; materialValid[iterator] = false; numMaterialValid--; break; } bool usesftlight = mat.shader.name == ftLightShaderName; bool usesUnlitColor = mat.shader.name == "Unlit/Color"; bool usesUnlitTexture = mat.shader.name == "Unlit/Texture"; if (!usesftlight && !usesUnlitColor && !usesUnlitTexture) { showError = true; showErrorText = "Warning: material should output unlit color"; //match = false; materialValid[iterator] = false; numMaterialValid--; break; } if (intensity > 1 && !usesftlight) { showError = true; showErrorText = "Warning: intensity > 1, but not using Bakery Light shader"; //match = false; break; } var mclr = mat.HasProperty("_Color") ? mat.color : Color.white; float eps = 0.5f / 255.0f; if (Mathf.Abs(mclr.r - clr.r) > eps || Mathf.Abs(mclr.g - clr.g) > eps || Mathf.Abs(mclr.b - clr.b) > eps) { showError = true; showErrorText = "Error: light color doesn't match material color"; //match = false; break; } if (usesftlight && Mathf.Abs(mat.GetFloat("intensity") - intensity) > 0.001f) { showError = true; showErrorText = "Error: light intensity doesn't match material intensity"; //match = false; break; } if (ftraceLightTexture.objectReferenceValue == null && mat.HasProperty("_MainTex") && mat.GetTexture("_MainTex") != null) { showError = true; showErrorText = "Error: textures don't match"; //match = false; break; } if (ftraceLightTexture.objectReferenceValue != null && (!mat.HasProperty("_MainTex") || mat.GetTexture("_MainTex") != ftraceLightTexture.objectReferenceValue)) { showError = true; showErrorText = "Error: textures don't match"; //match = false; break; } } //if (match) return; } if (showError) { EditorGUILayout.Space(); EditorGUILayout.LabelField(showErrorText); EditorGUILayout.Space(); string txt; if (numMaterialValid > 0) { if (isMesh && !isAreaLight) { txt = "Match light to material"; } else if (!isMesh && isAreaLight) { txt = "Match lightmapped to area light"; } else { txt = "Match lights to meshes/area lights"; } if (GUILayout.Button(txt)) { //iterator = 0; foreach (BakeryLightMesh selectedLight in targets) { //iterator++; var so = new SerializedObject(selectedLight); InitSerializedProperties(so); var mr = selectedLight.GetComponent <MeshRenderer>(); var areaLight = selectedLight.GetComponent <Light>(); if (mr == null && areaLight == null) { continue; } if (areaLight != null) { if (UnityEditor.PlayerSettings.colorSpace != ColorSpace.Linear) { ftraceLightColor.colorValue = areaLight.color; ftraceLightIntensity.floatValue = areaLight.intensity; } else if (!GraphicsSettings.lightsUseLinearIntensity) { float lightR, lightG, lightB, lightInt; GetLinearLightParameters(areaLight, out lightR, out lightG, out lightB, out lightInt); ftraceLightColor.colorValue = new Color(lightR, lightG, lightB); ftraceLightIntensity.floatValue = lightInt; } else { ftraceLightColor.colorValue = areaLight.color; ftraceLightIntensity.floatValue = areaLight.intensity; } ftraceLightCutoff.floatValue = areaLight.range * 1.5f; ftraceLightSelfShadow.boolValue = false; ftraceLightIndirectIntensity.floatValue = areaLight.bounceIntensity; so.ApplyModifiedProperties(); continue; } var mats = mr.sharedMaterials; if (mats.Length == 0 || mats[0] == null) { continue; } var mat = mats[0]; if (mat.shader.name == ftLightShaderName) { ftraceLightTexture.objectReferenceValue = mat.mainTexture; ftraceLightColor.colorValue = mat.color; ftraceLightIntensity.floatValue = mat.GetFloat("intensity"); } else if (mat.shader.name == "Unlit/Color") { ftraceLightTexture.objectReferenceValue = null; ftraceLightColor.colorValue = mat.color; ftraceLightIntensity.floatValue = 1; } else if (mat.shader.name == "Unlit/Texture") { ftraceLightTexture.objectReferenceValue = mat.mainTexture; ftraceLightColor.colorValue = Color.white;//mat.color; ftraceLightIntensity.floatValue = 1; } so.ApplyModifiedProperties(); } } } //if (mats.Length == 0) return; //if (mats[0] == null) return; if (isMesh && !isAreaLight) { txt = "Match material to light"; } else if (!isMesh && isAreaLight) { txt = "Match area light to lightmapped"; } else { txt = "Match meshes/area lights to lightmapped"; } if (GUILayout.Button(txt)) { foreach (BakeryLightMesh selectedLight in targets) { //iterator++; var so = new SerializedObject(selectedLight); InitSerializedProperties(so); var mr = selectedLight.GetComponent <MeshRenderer>(); var areaLight = selectedLight.GetComponent <Light>(); if (mr == null && areaLight == null) { continue; } if (areaLight != null) { Undo.RecordObject(areaLight, "Change light"); if (UnityEditor.PlayerSettings.colorSpace != ColorSpace.Linear) { areaLight.color = ftraceLightColor.colorValue; areaLight.intensity = ftraceLightIntensity.floatValue; } else if (!GraphicsSettings.lightsUseLinearIntensity) { var clr = ftraceLightColor.colorValue; float fintensity = ftraceLightIntensity.floatValue; float fr = clr.linear.r; // * fintensity; float fg = clr.linear.g; // * fintensity; float fb = clr.linear.b; // * fintensity; fr = Mathf.Pow(fr * fintensity, 1.0f / 2.2f); fg = Mathf.Pow(fg * fintensity, 1.0f / 2.2f); fb = Mathf.Pow(fb * fintensity, 1.0f / 2.2f); float fint = Mathf.Max(Mathf.Max(fr, fg), fb); fr /= fint; fg /= fint; fb /= fint; areaLight.color = new Color(fr, fg, fb); areaLight.intensity = fint; } else { areaLight.color = ftraceLightColor.colorValue; areaLight.intensity = ftraceLightIntensity.floatValue; } areaLight.bounceIntensity = ftraceLightIndirectIntensity.floatValue; continue; } var mats = mr.sharedMaterials; if (mats.Length == 0 || mats[0] == null) { continue; } float intensity = ftraceLightIntensity.floatValue; var mat = mats[0]; if (intensity > 1) { if (mat.shader.name != ftLightShaderName) { mat.shader = Shader.Find(ftLightShaderName); } mat.color = ftraceLightColor.colorValue; mat.mainTexture = ftraceLightTexture.objectReferenceValue as Texture2D; mat.SetFloat("intensity", intensity); } else { if (ftraceLightTexture.objectReferenceValue == null) { if (mat.shader.name != ftLightShaderName && mat.shader.name != "Unlit/Color") { mat.shader = Shader.Find(ftLightShaderName); } } else { if (mat.shader.name != ftLightShaderName && mat.shader.name != "Unlit/Texture") { mat.shader = Shader.Find(ftLightShaderName); } } mat.mainTexture = ftraceLightTexture.objectReferenceValue as Texture2D; if (mat.shader.name == ftLightShaderName) { mat.color = ftraceLightColor.colorValue; mat.SetFloat("intensity", intensity); } else { mat.color = ftraceLightColor.colorValue * intensity; } } } } } if (UnityEditor.PlayerSettings.colorSpace == ColorSpace.Linear) { if (!GraphicsSettings.lightsUseLinearIntensity) { EditorGUILayout.Space(); EditorGUILayout.LabelField("Warning: project is not set up to use linear light intensity."); EditorGUILayout.LabelField("GraphicsSettings.lightsUseLinearIntensity should be TRUE."); if (GUILayout.Button("Fix")) { GraphicsSettings.lightsUseLinearIntensity = true; } } else { EditorGUILayout.Space(); EditorGUILayout.LabelField("Project is using linear light intensity. This is nice."); if (GUILayout.Button("Change to non-linear")) { GraphicsSettings.lightsUseLinearIntensity = false; } } } }
} // 0x0000000181EA51A0-0x0000000181EA5240 public static void u0925u091Bu091Cu091Eu0922u0923u0927u091Bu091Eu091Eu0920(Scene u0927u091Eu091Fu0924u0925u0923u0927u091Eu091Bu0923u0923, ftLightmapsStorage u0928u0920u091Du091Eu0929u091Au0927u0925u0924u091Fu091E) { } // 0x0000000181EABE60-0x0000000181EAC0A0
public override void OnInspectorGUI() { //if (showFtrace) { OnEnable(); serializedObject.Update(); TestPreviewRefreshProperty(ref projModeCached, ftraceLightProj.intValue); TestPreviewRefreshProperty(ref texCached, ftraceLightTexture.objectReferenceValue); TestPreviewRefreshProperty(ref tex2DCached, ftraceLightTexture2D.objectReferenceValue); TestPreviewRefreshProperty(ref iesCached, ftraceLightIES.objectReferenceValue); EditorGUILayout.PropertyField(ftraceLightColor, new GUIContent("Color", "Color of the light")); EditorGUILayout.PropertyField(ftraceLightIntensity, new GUIContent("Intensity", "Color multiplier (Candela / PI)")); EditorGUILayout.PropertyField(ftraceLightShadowSpread, new GUIContent("Shadow spread", "Controls shadow blurriness from 0 to 1")); EditorGUILayout.PropertyField(ftraceLightRealisticFalloff, new GUIContent("Physical falloff", "Use inverse-squared falloff instead of Unity falloff")); if (ftraceLightRealisticFalloff.boolValue) { EditorGUILayout.PropertyField(ftraceLightFalloffMinRadius, new GUIContent("Falloff min size", "As point lights don't have area, at zero distance 1/(d*d) will become infinity. This value avoids this issue by assuming the light to have some minimum radius and changing the formula to 1/(d*d+R*R).")); } EditorGUILayout.PropertyField(ftraceLightCutoff, new GUIContent("Range", "Lighting distance limit. When 'Physical falloff' is on, for maximum corectness set to a very high value. Using smaller values is useful for faster render times and to match real-time lights. Bakery uses Skyforge falloff to maintain balance between correct inverse-squared attenuation and practical limits (https://habr.com/company/mailru/blog/248873/)")); EditorGUILayout.PropertyField(ftraceLightSamples, new GUIContent("Samples", "The amount of sample points generated on the surface of this light. Point light shadows are traced towards points on a sphere (with radius = shadowSpread) around the light. ")); EditorGUILayout.PropertyField(ftraceLightProj, new GUIContent("Projection mask", "Determines additional light masking mode.")); switch (ftraceLightProj.enumValueIndex) { case (int)BakeryPointLight.ftLightProjectionMode.Cookie: EditorGUILayout.PropertyField(ftraceLightTexture2D, new GUIContent("Cookie texture", "Texture")); EditorGUILayout.Slider(ftraceLightAngle, 1, 179, new GUIContent("Angle", "Angle of projection (like in spotlights).")); break; case (int)BakeryPointLight.ftLightProjectionMode.Cone: EditorGUILayout.Slider(ftraceLightAngle, 1, 180, new GUIContent("Outer angle")); EditorGUILayout.Slider(ftraceLightInnerAngle, 0, 100, new GUIContent("Inner angle percent")); break; case (int)BakeryPointLight.ftLightProjectionMode.Cubemap: EditorGUILayout.PropertyField(ftraceLightTexture, new GUIContent("Projected cubemap", "Cubemap")); break; case (int)BakeryPointLight.ftLightProjectionMode.IES: ftraceLightIES.objectReferenceValue = EditorGUILayout.ObjectField("IES file", ftraceLightIES.objectReferenceValue, typeof(UnityEngine.Object), false); if (ftraceLightIES.objectReferenceValue != null) { var path = AssetDatabase.GetAssetPath(ftraceLightIES.objectReferenceValue); if (path.Length < 4 || path.Substring(path.Length - 4).ToLower() != ".ies") { EditorUtility.DisplayDialog("Bakery", "File must have IES extension.", "OK"); ftraceLightIES.objectReferenceValue = null; } } break; default: break; } int prevVal = ftraceLightBitmask.intValue; int newVal = EditorGUILayout.MaskField(new GUIContent("Bitmask", "Lights only affect renderers with overlapping bits"), ftraceLightBitmask.intValue, selStrings); if (prevVal != newVal) { ftraceLightBitmask.intValue = newVal; } /* * EditorGUILayout.PropertyField(ftraceLightBakeToIndirect, new GUIContent("Bake to indirect", "Add direct contribution from this light to indirect-only lightmaps")); * if (ftraceLightBakeToIndirect.boolValue && ftraceLightShadowmask.boolValue) ftraceLightShadowmask.boolValue = false; * * EditorGUILayout.PropertyField(ftraceLightShadowmask, new GUIContent("Shadowmask", "Enable mixed lighting. Static shadows from this light will be baked, and real-time light will cast shadows from dynamic objects.")); * if (ftraceLightBakeToIndirect.boolValue && ftraceLightShadowmask.boolValue) ftraceLightBakeToIndirect.boolValue = false; */ if (storage == null) { storage = ftRenderLightmap.FindRenderSettingsStorage(); } var rmode = storage.renderSettingsUserRenderMode; if (rmode != (int)ftRenderLightmap.RenderMode.FullLighting) { ftDirectLightInspector.BakeWhat contrib; if (ftraceLightShadowmask.boolValue) { contrib = ftDirectLightInspector.BakeWhat.IndirectAndShadowmask; } else if (ftraceLightBakeToIndirect.boolValue) { contrib = ftDirectLightInspector.BakeWhat.DirectAndIndirect; } else { contrib = ftDirectLightInspector.BakeWhat.IndirectOnly; } var prevContrib = contrib; if (rmode == (int)ftRenderLightmap.RenderMode.Indirect) { contrib = (ftDirectLightInspector.BakeWhat)EditorGUILayout.Popup("Baked contribution", (int)contrib, ftDirectLightInspector.directContributionIndirectOptions); } else if (rmode == (int)ftRenderLightmap.RenderMode.Shadowmask) { contrib = (ftDirectLightInspector.BakeWhat)EditorGUILayout.EnumPopup("Baked contribution", contrib); } if (prevContrib != contrib) { if (contrib == ftDirectLightInspector.BakeWhat.IndirectOnly) { ftraceLightShadowmask.boolValue = false; ftraceLightBakeToIndirect.boolValue = false; } else if (contrib == ftDirectLightInspector.BakeWhat.IndirectAndShadowmask) { ftraceLightShadowmask.boolValue = true; ftraceLightBakeToIndirect.boolValue = false; } else { ftraceLightShadowmask.boolValue = false; ftraceLightBakeToIndirect.boolValue = true; } } } EditorGUILayout.PropertyField(ftraceLightIndirectIntensity, new GUIContent("Indirect intensity", "Non-physical GI multiplier for this light")); serializedObject.ApplyModifiedProperties(); } bool showWarningCant = false; bool showError = false; string why = ""; bool shadowmaskNoDynamicLight = false; foreach (BakeryPointLight selectedLight in targets) { bool match = true; //string why = ""; var light = selectedLight.GetComponent <Light>(); if (light == null) { if (ftraceLightShadowmask.boolValue) { shadowmaskNoDynamicLight = true; } continue; } if (!light.enabled) { if (ftraceLightShadowmask.boolValue) { shadowmaskNoDynamicLight = true; } } if (isHDRP) { if (!ftraceLightRealisticFalloff.boolValue || Mathf.Abs(ftraceLightFalloffMinRadius.floatValue - 0.01f) > 0.0001f) { match = false; why = "falloff doesn't match HDRP"; } else { match = CompareWithHDRP(light, ref why); } } if (isLWRP) { if (!ftraceLightRealisticFalloff.boolValue || Mathf.Abs(ftraceLightFalloffMinRadius.floatValue - 0.01f) > 0.0001f) { match = false; why = "falloff doesn't match URP"; } else { match = CompareWithLWRP(light, ref why); } } var so = new SerializedObject(selectedLight); InitSerializedProperties(so); if (ftraceLightIndirectIntensity.floatValue != light.bounceIntensity) { match = false; why = "indirect intensity doesn't match"; } if (ftraceLightProj.enumValueIndex == (int)BakeryPointLight.ftLightProjectionMode.IES) { showWarningCant = true; } else if (ftraceLightProj.enumValueIndex == (int)BakeryPointLight.ftLightProjectionMode.Omni) { if (light.type != LightType.Point) { match = false; why = "real-time light is not point"; } else if (light.cookie != null) { match = false; why = "real-time light has cookie"; } } else if (ftraceLightProj.enumValueIndex == (int)BakeryPointLight.ftLightProjectionMode.Cubemap) { if (light.type != LightType.Point) { match = false; why = "real-time light is not point"; } else if (light.cookie == null) { match = false; why = "real-time light has no cookie"; } } else if (ftraceLightProj.enumValueIndex == (int)BakeryPointLight.ftLightProjectionMode.Cookie) { if (light.type != LightType.Spot) { match = false; why = "real-time light is not spot"; } else if (light.cookie == null && ftraceLightTexture2D.objectReferenceValue != spotCookieTexture) { match = false; why = "wrong cookie texture"; } else if (light.cookie != null && ftraceLightTexture2D.objectReferenceValue != light.cookie) { match = false; why = "wrong cookie texture"; } else if (light.spotAngle != ftraceLightAngle.floatValue) { match = false; why = "spot angle doesn't match"; } } else if (ftraceLightProj.enumValueIndex == (int)BakeryPointLight.ftLightProjectionMode.Cone) { if (light.type != LightType.Spot) { match = false; why = "real-time light is not spot"; } else if (light.spotAngle != ftraceLightAngle.floatValue) { match = false; why = "outer angle doesn't match"; } } var clr = ftraceLightColor.colorValue; float eps = 1.0f / 255.0f; float lightR, lightG, lightB, lightInt; float fr, fg, fb; float fintensity = ftraceLightIntensity.floatValue; if (isHDRP) { fintensity *= Mathf.PI; } if (PlayerSettings.colorSpace == ColorSpace.Linear) { fr = clr.linear.r; // * fintensity; fg = clr.linear.g; // * fintensity; fb = clr.linear.b; // * fintensity; } else { fr = clr.r; fg = clr.g; fb = clr.b; } GetLinearLightParameters(light, out lightR, out lightG, out lightB, out lightInt); if (GraphicsSettings.lightsUseLinearIntensity || PlayerSettings.colorSpace != ColorSpace.Linear) { if (Mathf.Abs(lightR - fr) > eps || Mathf.Abs(lightG - fg) > eps || Mathf.Abs(lightB - fb) > eps) { match = false; why = "color doesn't match"; } else if (Mathf.Abs(lightInt - fintensity) > eps) { match = false; why = "intensity doesn't match"; } } else { eps *= Mathf.Max(lightInt, fintensity); if (Mathf.Abs(lightR * lightInt - fr * fintensity) > eps || Mathf.Abs(lightG * lightInt - fg * fintensity) > eps || Mathf.Abs(lightB * lightInt - fb * fintensity) > eps) { match = false; why = "intensity doesn't match"; } } if (Mathf.Abs(light.range - ftraceLightCutoff.floatValue) > 0.001f) { match = false; why = "range doesn't match"; } if (!match) { showError = true; } } if (shadowmaskNoDynamicLight) { EditorGUILayout.Space(); EditorGUILayout.LabelField("Warning: shadowmask needs enabled real-time light to work"); } if (showWarningCant) { EditorGUILayout.Space(); EditorGUILayout.LabelField("Warning: real-time light can't match baked IES light"); EditorGUILayout.Space(); } if (showError) { EditorGUILayout.Space(); EditorGUILayout.LabelField("Real-time light doesn't match lightmap: " + why); if (GUILayout.Button("Match lightmapped to real-time")) { foreach (BakeryPointLight selectedLight in targets) { var light = selectedLight.GetComponent <Light>(); if (light == null) { continue; } //if (!light.enabled) continue; var so = new SerializedObject(selectedLight); InitSerializedProperties(so); if (PlayerSettings.colorSpace != ColorSpace.Linear) { ftraceLightColor.colorValue = light.color; ftraceLightIntensity.floatValue = light.intensity; } else if (!GraphicsSettings.lightsUseLinearIntensity) { float lightR, lightG, lightB, lightInt; GetLinearLightParameters(light, out lightR, out lightG, out lightB, out lightInt); ftraceLightColor.colorValue = new Color(lightR, lightG, lightB); ftraceLightIntensity.floatValue = lightInt; } else { ftraceLightColor.colorValue = light.color; ftraceLightIntensity.floatValue = light.intensity; } ftraceLightCutoff.floatValue = light.range; ftraceLightAngle.floatValue = light.spotAngle; if (light.type == LightType.Point) { if (light.cookie == null) { ftraceLightProj.enumValueIndex = (int)BakeryPointLight.ftLightProjectionMode.Omni; ftraceLightTexture.objectReferenceValue = null; } else { ftraceLightProj.enumValueIndex = (int)BakeryPointLight.ftLightProjectionMode.Cubemap; ftraceLightTexture.objectReferenceValue = light.cookie; } } else if (light.type == LightType.Spot) { ftraceLightProj.enumValueIndex = (int)BakeryPointLight.ftLightProjectionMode.Cookie; if (light.cookie == null) { ftraceLightTexture2D.objectReferenceValue = spotCookieTexture; } else { ftraceLightTexture2D.objectReferenceValue = light.cookie; } } ftraceLightIndirectIntensity.floatValue = light.bounceIntensity; if (isHDRP) { MatchToHDRPLight(light); } if (isLWRP) { MatchToLWRPLight(light); } so.ApplyModifiedProperties(); } } if (GUILayout.Button("Match real-time to lightmapped")) { foreach (BakeryPointLight selectedLight in targets) { var light = selectedLight.GetComponent <Light>(); if (light == null) { continue; } //if (!light.enabled) continue; var so = new SerializedObject(selectedLight); InitSerializedProperties(so); Undo.RecordObject(light, "Change light"); if (PlayerSettings.colorSpace != ColorSpace.Linear) { light.color = ftraceLightColor.colorValue; light.intensity = ftraceLightIntensity.floatValue; } else if (!GraphicsSettings.lightsUseLinearIntensity) { var clr = ftraceLightColor.colorValue; float fintensity = ftraceLightIntensity.floatValue; float fr = clr.linear.r; // * fintensity; float fg = clr.linear.g; // * fintensity; float fb = clr.linear.b; // * fintensity; fr = Mathf.Pow(fr * fintensity, 1.0f / 2.2f); fg = Mathf.Pow(fg * fintensity, 1.0f / 2.2f); fb = Mathf.Pow(fb * fintensity, 1.0f / 2.2f); float fint = Mathf.Max(Mathf.Max(fr, fg), fb); fr /= fint; fg /= fint; fb /= fint; light.color = new Color(fr, fg, fb); light.intensity = fint; } else { light.color = ftraceLightColor.colorValue; light.intensity = ftraceLightIntensity.floatValue; } light.range = ftraceLightCutoff.floatValue; light.spotAngle = ftraceLightAngle.floatValue; if (ftraceLightProj.enumValueIndex == (int)BakeryPointLight.ftLightProjectionMode.Omni) { light.type = LightType.Point; light.cookie = null; } else if (ftraceLightProj.enumValueIndex == (int)BakeryPointLight.ftLightProjectionMode.Cubemap) { light.type = LightType.Point; light.cookie = ftraceLightTexture.objectReferenceValue as Cubemap; } else if (ftraceLightProj.enumValueIndex == (int)BakeryPointLight.ftLightProjectionMode.Cookie) { light.type = LightType.Spot; light.cookie = ftraceLightTexture.objectReferenceValue == spotCookieTexture ? null : (ftraceLightTexture.objectReferenceValue as Texture2D); } else if (ftraceLightProj.enumValueIndex == (int)BakeryPointLight.ftLightProjectionMode.Cone) { light.type = LightType.Spot; } light.bounceIntensity = ftraceLightIndirectIntensity.floatValue; if (isHDRP) { SetHDRPLight(light); } if (isLWRP) { SetLWRPLight(light); } } } } if (PlayerSettings.colorSpace == ColorSpace.Linear) { if (!GraphicsSettings.lightsUseLinearIntensity) { EditorGUILayout.Space(); EditorGUILayout.LabelField("Warning: project is not set up to use linear light intensity."); EditorGUILayout.LabelField("GraphicsSettings.lightsUseLinearIntensity should be TRUE."); if (GUILayout.Button("Fix")) { GraphicsSettings.lightsUseLinearIntensity = true; } } else { EditorGUILayout.Space(); EditorGUILayout.LabelField("Project is using linear light intensity. This is nice."); if (GUILayout.Button("Change to non-linear")) { GraphicsSettings.lightsUseLinearIntensity = false; } } } }
private static Texture2D u091Fu091Eu091Fu0925u091Bu0921u0921u0922u0929u091Eu091E(ftLightmapsStorage u0928u0920u091Du091Eu0929u091Au0927u0925u0924u091Fu091E) => default; // 0x0000000181E9F030-0x0000000181E9F050 public static void u0923u091Du0921u0920u0927u0921u0929u0928u0921u0927u0920(ftLightmapsStorage u0928u0920u091Du091Eu0929u091Au0927u0925u0924u091Fu091E) { } // 0x0000000181EA5B90-0x0000000181EA5EF0
public static void UnloadScene(ftLightmapsStorage storage) { if (lightmapRefCount == null) { return; } if (storage.idremap == null) { return; } //int idx = loadedStorages.IndexOf(storage); //if (idx >= 0) loadedStorages.RemoveAt(idx); LightmapData[] existingLmaps = null; List <LightmapAdditionalData> existingLmapsAdditional = null; //bool rebuild = false; for (int i = 0; i < storage.idremap.Length; i++) { int currentID = storage.idremap[i]; // just never unload the 1st lightmap to prevent Unity from losing LM encoding settings // remapping all IDs at runtime would introduce a perf hiccup if (currentID == 0) { continue; } if (lightmapRefCount.Count <= currentID) { continue; } lightmapRefCount[currentID]--; //Debug.LogError("rem: "+currentID+" "+lightmapRefCount[currentID]); if (lightmapRefCount[currentID] == 0) { if (existingLmaps == null) { existingLmaps = LightmapSettings.lightmaps; } if (existingLmaps.Length > currentID) { existingLmaps[currentID].lightmapColor = null; existingLmaps[currentID].lightmapDir = null; existingLmaps[currentID].shadowMask = null; if (existingLmapsAdditional == null) { existingLmapsAdditional = globalMapsAdditional; } if (existingLmapsAdditional != null && existingLmapsAdditional.Count > currentID) { var emptyEntry = new LightmapAdditionalData(); existingLmapsAdditional[currentID] = emptyEntry; } } //if (currentID == 0) rebuild = true; } } /* * // If the first lightmap was unloaded, we need to rebuild the lightmap array * // because Unity uses 1st lightmap to determine encoding * if (rebuild) * { * int newLength = 0; * for(int i=0; i<existingLmaps.Length; i++) * { * if (existingLmaps[i].lightmapColor != null) newLength++; * } * var existingLmaps2 = new LightmapData[newLength]; * int ctr = 0; * for(int i=0; i<existingLmaps.Length; i++) * { * if (existingLmaps[i].lightmapColor != null) * { * existingLmaps2[ctr] = existingLmaps[i]; * ctr++; * } * } * existingLmaps = existingLmaps2; * * for(int i=0; i<) * } */ if (existingLmaps != null) { LightmapSettings.lightmaps = existingLmaps; } }
} // 0x0000000181EA9CE0-0x0000000181EAA010 public static void u0922u091Du0924u0925u0923u091Au0922u0925u0922u0924u091B(ftLightmapsStorage u0928u0920u091Du091Eu0929u091Au0927u0925u0924u091Fu091E) { } // 0x0000000181EA54D0-0x0000000181EA5830
} // 0x0000000181EA54D0-0x0000000181EA5830 public static void u0923u0926u0922u091Cu0924u091Cu0926u0926u0921u091Bu0924(ftLightmapsStorage u0928u0920u091Du091Eu0929u091Au0927u0925u0924u091Fu091E) { } // 0x0000000181EA7BC0-0x0000000181EA7EF0
public static GameObject u0925u0923u0928u091Bu0927u0928u091Eu0924u091Fu0925u091B(string u0929u091Au091Du091Cu091Eu0925u0921u0928u091Bu0925u091B, Scene u0921u0929u091Bu0922u0929u0927u091Du091Eu091Fu091Au091C) => default; // 0x0000000181EAE130-0x0000000181EAE2A0 public static void u0924u091Eu0927u091Fu0920u0929u0923u0927u0929u091Du0925(ftLightmapsStorage u0928u0920u091Du091Eu0929u091Au0927u0925u0924u091Fu091E) { } // 0x0000000181EA9CE0-0x0000000181EAA010
} // 0x0000000181E9F1D0-0x0000000181EA0C40 public static void u0927u091Du091Cu0922u0925u091Bu091Du091Bu091Bu0924u091A(ftLightmapsStorage u0928u0920u091Du091Eu0929u091Au0927u0925u0924u091Fu091E) { } // 0x0000000181EAE600-0x0000000181EAE930
} // 0x0000000181EAC0A0-0x0000000181EADD40 public static void u0920u0921u091Bu091Fu0920u0927u0928u0922u0929u0924u091B(Scene u0927u091Eu091Fu0924u0925u0923u0927u091Eu091Bu0923u0923, ftLightmapsStorage u0928u0920u091Du091Eu0929u091Au0927u0925u0924u091Fu091E) { } // 0x0000000181EA4F60-0x0000000181EA51A0
private static Texture2D u0920u0921u0927u0921u091Fu0929u0925u0922u091Cu0924u091E(ftLightmapsStorage u0928u0920u091Du091Eu0929u091Au0927u0925u0924u091Fu091E) => default; // 0x0000000181E9F030-0x0000000181E9F050 public static void u0925u091Du0920u0925u0920u0926u091Du091Cu091Cu0929u0924(Scene u0927u091Eu091Fu0924u0925u0923u0927u091Eu091Bu0923u0923, ftLightmapsStorage u0928u0920u091Du091Eu0929u091Au0927u0925u0924u091Fu091E) { } // 0x0000000181EADD40-0x0000000181EADF70
} // 0x0000000181EA2940-0x0000000181EA4740 public static void u0928u091Cu091Fu091Au091Au0921u091Eu0929u0924u091Eu0923(Scene u0927u091Eu091Fu0924u0925u0923u0927u091Eu091Bu0923u0923, ftLightmapsStorage u0928u0920u091Du091Eu0929u091Au0927u0925u0924u091Fu091E) { } // 0x0000000181EAEB80-0x0000000181EAED80
public static void RefreshScene(Scene scene, ftLightmapsStorage storage = null, bool updateNonBaked = false) { var sceneCount = SceneManager.sceneCount; if (globalMapsAdditional == null) { globalMapsAdditional = new List <LightmapAdditionalData>(); } var lmaps = new List <LightmapData>(); var lmapsAdditional = new List <LightmapAdditionalData>(); var existingLmaps = LightmapSettings.lightmaps; var existingLmapsAdditional = globalMapsAdditional; // Acquire storage if (storage == null) { if (!scene.isLoaded) { //Debug.LogError("dbg: Scene not loaded"); return; } SceneManager.SetActiveScene(scene); var go = FindInScene("!ftraceLightmaps", scene); if (go == null) { //Debug.LogError("dbg: no storage"); return; } storage = go.GetComponent <ftLightmapsStorage>(); if (storage == null) { //Debug.LogError("dbg: no storage 2"); return; } } if (storage.idremap == null || storage.idremap.Length != storage.maps.Count) { storage.idremap = new int[storage.maps.Count]; } // Decide which global engine lightmapping mode to use // TODO: allow mixing different modes directionalMode = storage.dirMaps.Count != 0; bool patchedDirection = false; LightmapSettings.lightmapsMode = directionalMode ? LightmapsMode.CombinedDirectional : LightmapsMode.NonDirectional; // Set dummy directional tex for non-directional lightmaps in directional mode if (directionalMode) { for (int i = 0; i < existingLmaps.Length; i++) { if (directionalMode && existingLmaps[i].lightmapDir == null) { var lm = existingLmaps[i]; lm.lightmapDir = GetEmptyDirectionTex(storage); existingLmaps[i] = lm; patchedDirection = true; } } } // Detect if changes to lightmap array are necessary bool sameArray = false; if (existingLmaps.Length == storage.maps.Count) { sameArray = true; for (int i = 0; i < storage.maps.Count; i++) { if (existingLmaps[i].lightmapColor != storage.maps[i]) { sameArray = false; break; } if (storage.rnmMaps0.Count > i && (existingLmapsAdditional.Count <= i || existingLmapsAdditional[i].rnm0 != storage.rnmMaps0[i])) { sameArray = false; break; } } } if (!sameArray) // create new lightmap array { if (sceneCount >= 1) { // first add old for (int i = 0; i < existingLmaps.Length; i++) { // skip empty lightmaps (can be created by 5.6 ldata asset or vertex color) // ... unless there are valid lightmaps around them bool lightmapIsEmpty = existingLmaps[i] == null || (existingLmaps[i].lightmapColor == null && existingLmaps[i].shadowMask == null); bool lightmapCanBeSkipped = lightmapIsEmpty && (i == 0 || i == existingLmaps.Length - 1); if (!lightmapCanBeSkipped) { lmaps.Add(existingLmaps[i]); if (existingLmapsAdditional.Count > i) { lmapsAdditional.Add(existingLmapsAdditional[i]); } } } } for (int i = 0; i < storage.maps.Count; i++) { var texlm = storage.maps[i]; Texture2D texmask = null; Texture2D texdir = null; Texture2D texrnm0 = null; Texture2D texrnm1 = null; Texture2D texrnm2 = null; int mapMode = 0; if (storage.masks.Count > i) { texmask = storage.masks[i]; } if (storage.dirMaps.Count > i) { texdir = storage.dirMaps[i]; } if (storage.rnmMaps0.Count > i) { texrnm0 = storage.rnmMaps0[i]; texrnm1 = storage.rnmMaps1[i]; texrnm2 = storage.rnmMaps2[i]; mapMode = storage.mapsMode[i]; } bool found = false; int firstEmpty = -1; for (int j = 0; j < lmaps.Count; j++) { if (lmaps[j].lightmapColor == texlm && lmaps[j].shadowMask == texmask) { // lightmap already added - reuse storage.idremap[i] = j; found = true; //Debug.LogError("reused "+j); // additional maps array could be flushed due to script recompilation - recover if (texrnm0 != null && (lmapsAdditional.Count <= j || lmapsAdditional[j].rnm0 == null)) { while (lmapsAdditional.Count <= j) { lmapsAdditional.Add(new LightmapAdditionalData()); } var l = new LightmapAdditionalData(); l.rnm0 = texrnm0; l.rnm1 = texrnm1; l.rnm2 = texrnm2; l.mode = mapMode; lmapsAdditional[j] = l; } break; } else if (firstEmpty < 0 && lmaps[j].lightmapColor == null && lmaps[j].shadowMask == null) { // free (deleted) entry in existing lightmap list - possibly reuse storage.idremap[i] = j; firstEmpty = j; } } if (!found) { LightmapData lm; if (firstEmpty >= 0) { lm = lmaps[firstEmpty]; } else { lm = new LightmapData(); } lm.lightmapColor = texlm; if (storage.masks.Count > i) { lm.shadowMask = texmask; } if (storage.dirMaps.Count > i && texdir != null) { lm.lightmapDir = texdir; } else if (directionalMode) { lm.lightmapDir = GetEmptyDirectionTex(storage); } if (firstEmpty < 0) { lmaps.Add(lm); storage.idremap[i] = lmaps.Count - 1; } else { lmaps[firstEmpty] = lm; } if (storage.rnmMaps0.Count > i) { var l = new LightmapAdditionalData(); l.rnm0 = texrnm0; l.rnm1 = texrnm1; l.rnm2 = texrnm2; l.mode = mapMode; if (firstEmpty < 0) { //Debug.LogError("added "+(lmaps.Count-1)); while (lmapsAdditional.Count < lmaps.Count - 1) { lmapsAdditional.Add(new LightmapAdditionalData()); } lmapsAdditional.Add(l); } else { //Debug.LogError("set " + firstEmpty); while (lmapsAdditional.Count < firstEmpty + 1) { lmapsAdditional.Add(new LightmapAdditionalData()); } lmapsAdditional[firstEmpty] = l; } } } } } else // reuse existing lightmap array, only remap IDs { for (int i = 0; i < storage.maps.Count; i++) { storage.idremap[i] = i; //Debug.LogError("full reuse"); /*if (storage.rnmMaps0.Count > i) * { * var l = new LightmapAdditionalData(); * l.rnm0 = storage.rnmMaps0[i]; * l.rnm1 = storage.rnmMaps1[i]; * l.rnm2 = storage.rnmMaps2[i]; * l.mode = storage.mapsMode[i]; * lmapsAdditional.Add(l); * }*/ } } #if UNITY_EDITOR // Set editor lighting mode Lightmapping.giWorkflowMode = Lightmapping.GIWorkflowMode.OnDemand; Lightmapping.realtimeGI = storage.usesRealtimeGI; Lightmapping.bakedGI = true; #endif // Replace the lightmap array if needed if (sameArray && patchedDirection) { LightmapSettings.lightmaps = existingLmaps; } if (!sameArray) { LightmapSettings.lightmaps = lmaps.ToArray(); globalMapsAdditional = lmapsAdditional; } /* * // Debug * var lms = LightmapSettings.lightmaps; * for(int i=0; i<lms.Length; i++) * { * var name1 = ((lms[i]==null || lms[i].lightmapColor==null) ? "-" : lms[i].lightmapColor.name); * var name2 = (globalMapsAdditional.Count > i ?(globalMapsAdditional[i].rnm0==null?"x":globalMapsAdditional[i].rnm0.name) : "-"); * Debug.LogError(i+" "+name1+" "+name2); * } */ // Attempt to update skybox probe if (RenderSettings.ambientMode == UnityEngine.Rendering.AmbientMode.Skybox)// && Lightmapping.lightingDataAsset == null) { var probe = RenderSettings.ambientProbe; int isEmpty = -1; for (int i = 0; i < 3; i++) { for (int j = 0; j < 9; j++) { // default bugged probes are [almost] black or 1302? float a = Mathf.Abs(probe[i, j]); if (a > 1000.0f || a < 0.000001f) { isEmpty = 1; break; } if (probe[i, j] != 0) { isEmpty = 0; break; } } if (isEmpty >= 0) { break; } } if (isEmpty != 0) { DynamicGI.UpdateEnvironment(); } } // Set lightmap data on mesh renderers var emptyVec4 = new Vector4(1, 1, 0, 0); for (int i = 0; i < storage.bakedRenderers.Count; i++) { var r = storage.bakedRenderers[i]; if (r == null) { continue; } //if (r.isPartOfStaticBatch) continue; var id = storage.bakedIDs[i]; Mesh vmesh = null; if (i < storage.bakedVertexColorMesh.Count) { vmesh = storage.bakedVertexColorMesh[i]; } if (vmesh != null) { r.additionalVertexStreams = vmesh; r.lightmapIndex = 0xFFFF; var prop = new MaterialPropertyBlock(); prop.SetFloat("bakeryLightmapMode", 1); r.SetPropertyBlock(prop); continue; } int globalID = (id < 0 || id >= storage.idremap.Length) ? id : storage.idremap[id]; r.lightmapIndex = globalID; if (!r.isPartOfStaticBatch) { // scaleOffset is baked on static batches already var scaleOffset = id < 0 ? emptyVec4 : storage.bakedScaleOffset[i]; r.lightmapScaleOffset = scaleOffset; } if (r.lightmapIndex >= 0 && globalID < globalMapsAdditional.Count) { var lmap = globalMapsAdditional[globalID]; if (lmap.rnm0 != null) { var prop = new MaterialPropertyBlock(); prop.SetTexture("_RNM0", lmap.rnm0); prop.SetTexture("_RNM1", lmap.rnm1); prop.SetTexture("_RNM2", lmap.rnm2); prop.SetFloat("bakeryLightmapMode", lmap.mode); r.SetPropertyBlock(prop); } } } // Set lightmap data on definitely-not-baked mesh renderers (can be possibly avoided) if (updateNonBaked) { for (int i = 0; i < storage.nonBakedRenderers.Count; i++) { var r = storage.nonBakedRenderers[i]; if (r == null) { continue; } if (r.isPartOfStaticBatch) { continue; } r.lightmapIndex = 0xFFFE; } } // Set lightmap data on terrains for (int i = 0; i < storage.bakedRenderersTerrain.Count; i++) { var r = storage.bakedRenderersTerrain[i]; if (r == null) { continue; } var id = storage.bakedIDsTerrain[i]; r.lightmapIndex = (id < 0 || id >= storage.idremap.Length) ? id : storage.idremap[id]; var scaleOffset = id < 0 ? emptyVec4 : storage.bakedScaleOffsetTerrain[i]; r.lightmapScaleOffset = scaleOffset; } // Set shadowmask parameters on lights for (int i = 0; i < storage.bakedLights.Count; i++) { #if UNITY_2017_3_OR_NEWER var output = new LightBakingOutput(); output.isBaked = true; output.lightmapBakeType = LightmapBakeType.Mixed; output.mixedLightingMode = MixedLightingMode.Shadowmask; output.occlusionMaskChannel = storage.bakedLightChannels[i]; output.probeOcclusionLightIndex = storage.bakedLights[i].bakingOutput.probeOcclusionLightIndex; storage.bakedLights[i].bakingOutput = output; //#else //var light = storage.bakedLights[i]; #endif } // Increment lightmap refcounts if (lightmapRefCount == null) { lightmapRefCount = new List <int>(); } for (int i = 0; i < storage.idremap.Length; i++) { int currentID = storage.idremap[i]; while (lightmapRefCount.Count <= currentID) { lightmapRefCount.Add(0); } if (lightmapRefCount[currentID] < 0) { lightmapRefCount[currentID] = 0; } lightmapRefCount[currentID]++; } //if (loadedStorages == null) loadedStorages = new List<ftLightmapsStorage>(); //if (loadedStorages.Contains(storage)) loadedStorages.Add(storage); //return appendOffset; }
} // 0x0000000181EAEB80-0x0000000181EAED80 private static Texture2D u0921u091Au091Bu091Bu0924u0922u0927u091Cu0924u091Bu0925(ftLightmapsStorage u0928u0920u091Du091Eu0929u091Au0927u0925u0924u091Fu091E) => default; // 0x0000000181E9F030-0x0000000181E9F050
} // 0x0000000181EAF010-0x0000000181EAF090 public static void u091Cu091Eu0920u0923u0927u0922u0925u0926u0921u0920u0926(Scene u0927u091Eu091Fu0924u0925u0923u0927u091Eu091Bu0923u0923, ftLightmapsStorage u0928u0920u091Du091Eu0929u091Au0927u0925u0924u091Fu091E = null, bool u0921u0923u091Eu091Au0926u091Fu0926u0929u091Bu091Fu0928 = false /* Metadata: 0x0064FE86 */) { } // 0x0000000181EA2940-0x0000000181EA4740
} // 0x0000000181EA5B90-0x0000000181EA5EF0 public static void u0926u091Eu0924u091Fu0929u0929u0922u0926u0924u091Au0927(Scene u0927u091Eu091Fu0924u0925u0923u0927u091Eu091Bu0923u0923, ftLightmapsStorage u0928u0920u091Du091Eu0929u091Au0927u0925u0924u091Fu091E) { } // 0x0000000181EAE2F0-0x0000000181EAE4F0