//[MenuItem("Internal/HDRenderPipeline/Upgrade Scene Light Intensity to physical light unit", priority = CoreUtils.editMenuPriority2)] static void UpgradeLightsPLU() { Light[] lights = Resources.FindObjectsOfTypeAll <Light>(); foreach (var l in lights) { var add = l.GetComponent <HDAdditionalLightData>(); if (add == null) { continue; } // We only need to update the new intensity parameters on additional data, no need to change intensity if (add.lightTypeExtent == LightTypeExtent.Punctual) { switch (l.type) { case LightType.Point: add.punctualIntensity = l.intensity / LightUtils.ConvertPointLightIntensity(1.0f); break; case LightType.Spot: add.punctualIntensity = l.intensity / LightUtils.ConvertPointLightIntensity(1.0f); break; case LightType.Directional: add.directionalIntensity = l.intensity; break; } } else if (add.lightTypeExtent == LightTypeExtent.Rectangle) { add.areaIntensity = l.intensity / LightUtils.ConvertRectLightIntensity(1.0f, add.shapeWidth, add.shapeHeight); } else if (add.lightTypeExtent == LightTypeExtent.Line) { add.areaIntensity = l.intensity / LightUtils.CalculateLineLightIntensity(1.0f, add.shapeWidth); } } var scene = SceneManager.GetActiveScene(); EditorSceneManager.MarkSceneDirty(scene); }
internal static void DoEmissiveIntensityGUI(MaterialEditor materialEditor, MaterialProperty emissiveIntensity, MaterialProperty emissiveIntensityUnit) { bool unitIsMixed = emissiveIntensityUnit.hasMixedValue; bool intensityIsMixed = unitIsMixed || emissiveIntensity.hasMixedValue; using (new EditorGUILayout.HorizontalScope()) { EditorGUI.showMixedValue = intensityIsMixed; EmissiveIntensityUnit unit = (EmissiveIntensityUnit)emissiveIntensityUnit.floatValue; if (unitIsMixed) { using (new EditorGUI.DisabledScope(unitIsMixed)) materialEditor.ShaderProperty(emissiveIntensity, Styles.emissiveIntensityText); } else { if (!intensityIsMixed && unit == EmissiveIntensityUnit.EV100) { float evValue = LightUtils.ConvertLuminanceToEv(emissiveIntensity.floatValue); evValue = EditorGUILayout.FloatField(Styles.emissiveIntensityText, evValue); evValue = Mathf.Clamp(evValue, 0, float.MaxValue); emissiveIntensity.floatValue = LightUtils.ConvertEvToLuminance(evValue); } else { EditorGUI.BeginChangeCheck(); materialEditor.ShaderProperty(emissiveIntensity, Styles.emissiveIntensityText); if (EditorGUI.EndChangeCheck()) { emissiveIntensity.floatValue = Mathf.Clamp(emissiveIntensity.floatValue, 0, float.MaxValue); } } } EditorGUI.showMixedValue = emissiveIntensityUnit.hasMixedValue; EditorGUI.BeginChangeCheck(); var newUnit = (EmissiveIntensityUnit)EditorGUILayout.EnumPopup(unit); if (EditorGUI.EndChangeCheck()) { emissiveIntensityUnit.floatValue = (float)newUnit; } } EditorGUI.showMixedValue = false; }
private Color32 GetFinalLight(Vector3i a, Vector3i b, Vector3i c, Vector3i d) { bool t1 = Map.GetBlockSafe(b.x, b.y, b.z).IsTransparent(); bool t2 = Map.GetBlockSafe(c.x, c.y, c.z).IsTransparent(); if (t1 || t2) { Color32 c1 = LightUtils.GetBlockLight(a); Color32 c2 = LightUtils.GetBlockLight(b); Color32 c3 = LightUtils.GetBlockLight(c); Color32 c4 = LightUtils.GetBlockLight(d); return(LightUtils.Average(c1, c2, c3, c4)); } else { Color32 c1 = LightUtils.GetBlockLight(a); Color32 c2 = LightUtils.GetBlockLight(b); Color32 c3 = LightUtils.GetBlockLight(c); return(LightUtils.Average(c1, c2, c3)); } }
public void HouseOrder(List <HouseLight> houseLights) { try { houseLights = houseLights.GroupBy(r => new { r.HouseLightSide, r.LightOrder, r.MainBoardId, r.LightColor }).Select(r => new HouseLight { HouseLightSide = r.Key.HouseLightSide, MainBoardId = r.Key.MainBoardId, LightOrder = r.Key.LightOrder, LightColor = r.Key.LightColor }).ToList(); houseLights.ForEach(s => { if (s.LightColor > 0) { order.Enqueue(LightUtils.GetLightHouseOrder_RGB(s.MainBoardId.ToString(), s.LightOrder.ToString(), s.LightColor)); } else { order.Enqueue(ChangeToByte(LightUtils.GetLightHouseOrder(s.MainBoardId, s.LightOrder, s.HouseLightSide))); } } ); } catch (Exception ee) { Log.Error(ee); } }
public static float ConvertPunctualLightCandelaToLumen(LightType lightType, SpotLightShape spotLigthShape, float candela, bool enableSpotReflector, float spotAngle, float aspectRatio) { if (lightType == LightType.Spot && enableSpotReflector) { // We just need to multiply candela by solid angle in this case if (spotLigthShape == SpotLightShape.Cone) { return(LightUtils.ConvertSpotLightCandelaToLumen(candela, spotAngle * Mathf.Deg2Rad, true)); } else if (spotLigthShape == SpotLightShape.Pyramid) { float angleA, angleB; LightUtils.CalculateAnglesForPyramid(aspectRatio, spotAngle * Mathf.Deg2Rad, out angleA, out angleB); return(LightUtils.ConvertFrustrumLightCandelaToLumen(candela, angleA, angleB)); } else // Box { return(LightUtils.ConvertPointLightCandelaToLumen(candela)); } } return(LightUtils.ConvertPointLightCandelaToLumen(candela)); }
protected override void MaterialPropertiesGUI(Material material) { using (var header = new HeaderScope(Styles.InputsText, (uint)Expandable.Input, this)) { if (header.expanded) { m_MaterialEditor.TexturePropertySingleLine(Styles.colorText, colorMap, color); m_MaterialEditor.TextureScaleOffsetProperty(colorMap); } } var surfaceTypeValue = (SurfaceType)surfaceType.floatValue; if (surfaceTypeValue == SurfaceType.Transparent) { using (var header = new HeaderScope(StylesBaseUnlit.TransparencyInputsText, (uint)Expandable.Transparency, this)) { if (header.expanded) { DoDistortionInputsGUI(); } } } using (var header = new HeaderScope(Styles.emissiveLabelText, (uint)Expandable.Emissive, this)) { if (header.expanded) { EditorGUI.BeginChangeCheck(); m_MaterialEditor.ShaderProperty(useEmissiveIntensity, Styles.useEmissiveIntensityText); bool updateEmissiveColor = EditorGUI.EndChangeCheck(); if (useEmissiveIntensity.floatValue == 0) { EditorGUI.BeginChangeCheck(); DoEmissiveTextureProperty(material, emissiveColor); if (EditorGUI.EndChangeCheck() || updateEmissiveColor) { emissiveColor.colorValue = emissiveColor.colorValue; } EditorGUILayout.HelpBox(Styles.emissiveIntensityFromHDRColorText.text, MessageType.Info, true); } else { EditorGUI.BeginChangeCheck(); { DoEmissiveTextureProperty(material, emissiveColorLDR); emissiveColorLDR.colorValue = NormalizeEmissionColor(ref updateEmissiveColor, emissiveColorLDR.colorValue); using (new EditorGUILayout.HorizontalScope()) { EmissiveIntensityUnit unit = (EmissiveIntensityUnit)emissiveIntensityUnit.floatValue; if (unit == EmissiveIntensityUnit.Luminance) { m_MaterialEditor.ShaderProperty(emissiveIntensity, Styles.emissiveIntensityText); } else { float evValue = LightUtils.ConvertLuminanceToEv(emissiveIntensity.floatValue); evValue = EditorGUILayout.FloatField(Styles.emissiveIntensityText, evValue); emissiveIntensity.floatValue = LightUtils.ConvertEvToLuminance(evValue); } emissiveIntensityUnit.floatValue = (float)(EmissiveIntensityUnit)EditorGUILayout.EnumPopup(unit); } } if (EditorGUI.EndChangeCheck() || updateEmissiveColor) { emissiveColor.colorValue = emissiveColorLDR.colorValue * emissiveIntensity.floatValue; } } m_MaterialEditor.ShaderProperty(emissiveExposureWeight, Styles.emissiveExposureWeightText); DoEmissionArea(material); } } }
void ConvertLightIntensity(LightUnit oldLightUnit, LightUnit newLightUnit) { float intensity = m_AdditionalLightData.intensity.floatValue; // For punctual lights if (oldLightUnit == LightUnit.Lumen && newLightUnit == LightUnit.Candela) { if (m_LightShape == LightShape.Spot && m_AdditionalLightData.enableSpotReflector.boolValue) { // We have already calculate the correct value, just assign it intensity = ((Light)target).intensity; } else { intensity = LightUtils.ConvertPointLightLumenToCandela(intensity); } } if (oldLightUnit == LightUnit.Candela && newLightUnit == LightUnit.Lumen) { if (m_LightShape == LightShape.Spot && m_AdditionalLightData.enableSpotReflector.boolValue) { // We just need to multiply candela by solid angle in this case if ((SpotLightShape)m_AdditionalLightData.spotLightShape.enumValueIndex == SpotLightShape.Cone) { intensity = LightUtils.ConvertSpotLightCandelaToLumen(intensity, ((Light)target).spotAngle * Mathf.Deg2Rad, true); } else if ((SpotLightShape)m_AdditionalLightData.spotLightShape.enumValueIndex == SpotLightShape.Pyramid) { float angleA, angleB; LightUtils.CalculateAnglesForPyramid(m_AdditionalLightData.aspectRatio.floatValue, ((Light)target).spotAngle * Mathf.Deg2Rad, out angleA, out angleB); intensity = LightUtils.ConvertFrustrumLightCandelaToLumen(intensity, angleA, angleB); } else // Box { intensity = LightUtils.ConvertPointLightCandelaToLumen(intensity); } } else { intensity = LightUtils.ConvertPointLightCandelaToLumen(intensity); } } // For area lights if (oldLightUnit == LightUnit.Lumen && newLightUnit == LightUnit.Luminance) { if (m_LightShape == LightShape.Rectangle) { intensity = LightUtils.ConvertRectLightLumenToLuminance(intensity, m_AdditionalLightData.shapeWidth.floatValue, m_AdditionalLightData.shapeHeight.floatValue); } else if (m_LightShape == LightShape.Line) { intensity = LightUtils.CalculateLineLightLumenToLuminance(intensity, m_AdditionalLightData.shapeWidth.floatValue); } } if (oldLightUnit == LightUnit.Luminance && newLightUnit == LightUnit.Lumen) { if (m_LightShape == LightShape.Rectangle) { intensity = LightUtils.ConvertRectLightLuminanceToLumen(intensity, m_AdditionalLightData.shapeWidth.floatValue, m_AdditionalLightData.shapeHeight.floatValue); } else if (m_LightShape == LightShape.Line) { intensity = LightUtils.CalculateLineLightLuminanceToLumen(intensity, m_AdditionalLightData.shapeWidth.floatValue); } } m_AdditionalLightData.intensity.floatValue = intensity; }
void DrawEmissionGUI() { EditorGUI.BeginChangeCheck(); materialEditor.ShaderProperty(useEmissiveIntensity, Styles.useEmissiveIntensityText); bool updateEmissiveColor = EditorGUI.EndChangeCheck(); if (useEmissiveIntensity.floatValue == 0) { EditorGUI.BeginChangeCheck(); DoEmissiveTextureProperty(emissiveColor); if (EditorGUI.EndChangeCheck() || updateEmissiveColor) { emissiveColor.colorValue = emissiveColor.colorValue; } EditorGUILayout.HelpBox(Styles.emissiveIntensityFromHDRColorText.text, MessageType.Info, true); } else { EditorGUI.BeginChangeCheck(); DoEmissiveTextureProperty(emissiveColorLDR); // Normalize all emissive colors for each target separately foreach (Material material in materials) { if (material.HasProperty(kEmissiveColorLDR)) { material.SetColor(kEmissiveColorLDR, NormalizeEmissionColor(ref updateEmissiveColor, material.GetColor(kEmissiveColorLDR))); } } if (EditorGUI.EndChangeCheck() || updateEmissiveColor) { UpdateEmissiveColorAndIntensity(); } float newUnitFloat; float newIntensity = emissiveIntensity.floatValue; bool unitIsMixed = emissiveIntensityUnit.hasMixedValue; bool intensityIsMixed = unitIsMixed || emissiveIntensity.hasMixedValue; bool intensityChanged = false; bool unitChanged = false; EditorGUI.BeginChangeCheck(); { using (new EditorGUILayout.HorizontalScope()) { EmissiveIntensityUnit unit = (EmissiveIntensityUnit)emissiveIntensityUnit.floatValue; EditorGUI.showMixedValue = intensityIsMixed; if (unit == EmissiveIntensityUnit.Nits) { using (var change = new EditorGUI.ChangeCheckScope()) { materialEditor.ShaderProperty(emissiveIntensity, Styles.emissiveIntensityText); intensityChanged = change.changed; if (intensityChanged) { newIntensity = Mathf.Clamp(emissiveIntensity.floatValue, 0, float.MaxValue); } } } else { float value = emissiveIntensity.floatValue; if (!intensityIsMixed) { float evValue = LightUtils.ConvertLuminanceToEv(emissiveIntensity.floatValue); evValue = EditorGUILayout.FloatField(Styles.emissiveIntensityText, evValue); newIntensity = Mathf.Clamp(evValue, 0, float.MaxValue); emissiveIntensity.floatValue = LightUtils.ConvertEvToLuminance(evValue); } else { using (var change = new EditorGUI.ChangeCheckScope()) { newIntensity = EditorGUILayout.FloatField(Styles.emissiveIntensityText, value); intensityChanged = change.changed; } } } EditorGUI.showMixedValue = false; EditorGUI.showMixedValue = emissiveIntensityUnit.hasMixedValue; using (var change = new EditorGUI.ChangeCheckScope()) { newUnitFloat = (float)(EmissiveIntensityUnit)EditorGUILayout.EnumPopup(unit); unitChanged = change.changed; } EditorGUI.showMixedValue = false; } } if (EditorGUI.EndChangeCheck() || updateEmissiveColor) { if (unitChanged) { if (unitIsMixed) { UpdateEmissionUnit(newUnitFloat); } else { emissiveIntensityUnit.floatValue = newUnitFloat; } } // We don't allow changes on intensity if units are mixed if (intensityChanged && !unitIsMixed) { emissiveIntensity.floatValue = newIntensity; } UpdateEmissiveColorAndIntensity(); } } materialEditor.ShaderProperty(emissiveExposureWeight, Styles.emissiveExposureWeightText); if ((m_Features & Features.MultiplyWithBase) != 0) { materialEditor.ShaderProperty(albedoAffectEmissive, Styles.albedoAffectEmissiveText); } // Emission for GI? if ((m_Features & Features.EnableEmissionForGI) != 0) { BakedEmissionEnabledProperty(materialEditor); } }
static void ConvertLightIntensity(LightUnit oldLightUnit, LightUnit newLightUnit, SerializedHDLight serialized, Editor owner) { float intensity = serialized.serializedLightData.intensity.floatValue; Light light = (Light)owner.target; // For punctual lights if ((LightTypeExtent)serialized.serializedLightData.lightTypeExtent.enumValueIndex == LightTypeExtent.Punctual) { // Lumen -> if (oldLightUnit == LightUnit.Lumen && newLightUnit == LightUnit.Candela) { intensity = LightUtils.ConvertPunctualLightLumenToCandela(light.type, intensity, light.intensity, serialized.serializedLightData.enableSpotReflector.boolValue); } else if (oldLightUnit == LightUnit.Lumen && newLightUnit == LightUnit.Lux) { intensity = LightUtils.ConvertPunctualLightLumenToLux(light.type, intensity, light.intensity, serialized.serializedLightData.enableSpotReflector.boolValue, serialized.serializedLightData.luxAtDistance.floatValue); } else if (oldLightUnit == LightUnit.Lumen && newLightUnit == LightUnit.Ev100) { intensity = LightUtils.ConvertPunctualLightLumenToEv(light.type, intensity, light.intensity, serialized.serializedLightData.enableSpotReflector.boolValue); } // Candela -> else if (oldLightUnit == LightUnit.Candela && newLightUnit == LightUnit.Lumen) { intensity = LightUtils.ConvertPunctualLightCandelaToLumen(light.type, (SpotLightShape)serialized.serializedLightData.spotLightShape.enumValueIndex, intensity, serialized.serializedLightData.enableSpotReflector.boolValue, light.spotAngle, serialized.serializedLightData.aspectRatio.floatValue); } else if (oldLightUnit == LightUnit.Candela && newLightUnit == LightUnit.Lux) { intensity = LightUtils.ConvertCandelaToLux(intensity, serialized.serializedLightData.luxAtDistance.floatValue); } else if (oldLightUnit == LightUnit.Candela && newLightUnit == LightUnit.Ev100) { intensity = LightUtils.ConvertCandelaToEv(intensity); } // Lux -> else if (oldLightUnit == LightUnit.Lux && newLightUnit == LightUnit.Lumen) { intensity = LightUtils.ConvertPunctualLightLuxToLumen(light.type, (SpotLightShape)serialized.serializedLightData.spotLightShape.enumValueIndex, intensity, serialized.serializedLightData.enableSpotReflector.boolValue, light.spotAngle, serialized.serializedLightData.aspectRatio.floatValue, serialized.serializedLightData.luxAtDistance.floatValue); } else if (oldLightUnit == LightUnit.Lux && newLightUnit == LightUnit.Candela) { intensity = LightUtils.ConvertLuxToCandela(intensity, serialized.serializedLightData.luxAtDistance.floatValue); } else if (oldLightUnit == LightUnit.Lux && newLightUnit == LightUnit.Ev100) { intensity = LightUtils.ConvertLuxToEv(intensity, serialized.serializedLightData.luxAtDistance.floatValue); } // EV100 -> else if (oldLightUnit == LightUnit.Ev100 && newLightUnit == LightUnit.Lumen) { intensity = LightUtils.ConvertPunctualLightEvToLumen(light.type, (SpotLightShape)serialized.serializedLightData.spotLightShape.enumValueIndex, intensity, serialized.serializedLightData.enableSpotReflector.boolValue, light.spotAngle, serialized.serializedLightData.aspectRatio.floatValue); } else if (oldLightUnit == LightUnit.Ev100 && newLightUnit == LightUnit.Candela) { intensity = LightUtils.ConvertEvToCandela(intensity); } else if (oldLightUnit == LightUnit.Ev100 && newLightUnit == LightUnit.Lux) { intensity = LightUtils.ConvertEvToLux(intensity, serialized.serializedLightData.luxAtDistance.floatValue); } } else // For area lights { if (oldLightUnit == LightUnit.Lumen && newLightUnit == LightUnit.Luminance) { intensity = LightUtils.ConvertAreaLightLumenToLuminance((LightTypeExtent)serialized.serializedLightData.lightTypeExtent.enumValueIndex, intensity, serialized.serializedLightData.shapeWidth.floatValue, serialized.serializedLightData.shapeHeight.floatValue); } if (oldLightUnit == LightUnit.Luminance && newLightUnit == LightUnit.Lumen) { intensity = LightUtils.ConvertAreaLightLuminanceToLumen((LightTypeExtent)serialized.serializedLightData.lightTypeExtent.enumValueIndex, intensity, serialized.serializedLightData.shapeWidth.floatValue, serialized.serializedLightData.shapeHeight.floatValue); } if (oldLightUnit == LightUnit.Luminance && newLightUnit == LightUnit.Ev100) { intensity = LightUtils.ConvertLuminanceToEv(intensity); } if (oldLightUnit == LightUnit.Ev100 && newLightUnit == LightUnit.Luminance) { intensity = LightUtils.ConvertEvToLuminance(intensity); } if (oldLightUnit == LightUnit.Ev100 && newLightUnit == LightUnit.Lumen) { intensity = LightUtils.ConvertAreaLightEvToLumen((LightTypeExtent)serialized.serializedLightData.lightTypeExtent.enumValueIndex, intensity, serialized.serializedLightData.shapeWidth.floatValue, serialized.serializedLightData.shapeHeight.floatValue); } if (oldLightUnit == LightUnit.Lumen && newLightUnit == LightUnit.Ev100) { intensity = LightUtils.ConvertAreaLightLumenToEv((LightTypeExtent)serialized.serializedLightData.lightTypeExtent.enumValueIndex, intensity, serialized.serializedLightData.shapeWidth.floatValue, serialized.serializedLightData.shapeHeight.floatValue); } } serialized.serializedLightData.intensity.floatValue = intensity; }
void UpdateAreaLightEmissiveMesh() { foreach (var lightData in m_AdditionalLightDatas) { GameObject lightGameObject = lightData.gameObject; MeshRenderer emissiveMeshRenderer = lightData.GetComponent <MeshRenderer>(); MeshFilter emissiveMeshFilter = lightData.GetComponent <MeshFilter>(); Light light = lightGameObject.GetComponent <Light>(); bool displayAreaLightEmissiveMesh = IsAreaLightShape(m_LightShape) && m_LightShape != LightShape.Line && m_AdditionalLightData.displayAreaLightEmissiveMesh.boolValue; // Ensure that the emissive mesh components are here if (displayAreaLightEmissiveMesh) { if (emissiveMeshRenderer == null) { emissiveMeshRenderer = lightGameObject.AddComponent <MeshRenderer>(); } if (emissiveMeshFilter == null) { emissiveMeshFilter = lightGameObject.AddComponent <MeshFilter>(); } } else // Or remove them if the option is disabled { if (emissiveMeshRenderer != null) { DestroyImmediate(emissiveMeshRenderer); } if (emissiveMeshFilter != null) { DestroyImmediate(emissiveMeshFilter); } // Skip to the next light continue; } float areaLightIntensity = 0.0f; // Update Mesh emissive value switch (m_LightShape) { case LightShape.Rectangle: emissiveMeshFilter.mesh = HDEditorUtils.LoadAsset <Mesh>("RenderPipelineResources/Quad.FBX"); lightGameObject.transform.localScale = new Vector3(lightData.shapeWidth, lightData.shapeHeight, 0); // Do the same conversion as for light intensity areaLightIntensity = LightUtils.ConvertRectLightIntensity( m_AdditionalLightData.areaIntensity.floatValue, lightData.shapeWidth, lightData.shapeHeight); break; default: break; } if (emissiveMeshRenderer.sharedMaterial == null) { emissiveMeshRenderer.material = new Material(Shader.Find("HDRenderPipeline/Unlit")); } emissiveMeshRenderer.sharedMaterial.SetColor("_UnlitColor", Color.black); // Note that we must use the light in linear RGB emissiveMeshRenderer.sharedMaterial.SetColor("_EmissiveColor", light.color.linear * areaLightIntensity); } }
void DrawEmissionGUI() { EditorGUI.BeginChangeCheck(); materialEditor.ShaderProperty(useEmissiveIntensity, Styles.useEmissiveIntensityText); bool updateEmissiveColor = EditorGUI.EndChangeCheck(); if (useEmissiveIntensity.floatValue == 0) { EditorGUI.BeginChangeCheck(); DoEmissiveTextureProperty(emissiveColor); if (EditorGUI.EndChangeCheck() || updateEmissiveColor) { emissiveColor.colorValue = emissiveColor.colorValue; } EditorGUILayout.HelpBox(Styles.emissiveIntensityFromHDRColorText.text, MessageType.Info, true); } else { EditorGUI.BeginChangeCheck(); { DoEmissiveTextureProperty(emissiveColorLDR); emissiveColorLDR.colorValue = NormalizeEmissionColor(ref updateEmissiveColor, emissiveColorLDR.colorValue); using (new EditorGUILayout.HorizontalScope()) { EmissiveIntensityUnit unit = (EmissiveIntensityUnit)emissiveIntensityUnit.floatValue; if (unit == EmissiveIntensityUnit.Luminance) { using (var change = new EditorGUI.ChangeCheckScope()) { materialEditor.ShaderProperty(emissiveIntensity, Styles.emissiveIntensityText); if (change.changed) { emissiveIntensity.floatValue = Mathf.Clamp(emissiveIntensity.floatValue, 0, float.MaxValue); } } } else { float evValue = LightUtils.ConvertLuminanceToEv(emissiveIntensity.floatValue); evValue = EditorGUILayout.FloatField(Styles.emissiveIntensityText, evValue); evValue = Mathf.Clamp(evValue, 0, float.MaxValue); emissiveIntensity.floatValue = LightUtils.ConvertEvToLuminance(evValue); } emissiveIntensityUnit.floatValue = (float)(EmissiveIntensityUnit)EditorGUILayout.EnumPopup(unit); } } if (EditorGUI.EndChangeCheck() || updateEmissiveColor) { emissiveColor.colorValue = emissiveColorLDR.colorValue * emissiveIntensity.floatValue; } } materialEditor.ShaderProperty(emissiveExposureWeight, Styles.emissiveExposureWeightText); if ((m_Features & Features.MultiplyWithBase) != 0) { materialEditor.ShaderProperty(albedoAffectEmissive, Styles.albedoAffectEmissiveText); } // Emission for GI? if ((m_Features & Features.EnableEmissionForGI) != 0) { if (materialEditor.EmissionEnabledProperty()) { // change the GI flag and fix it up with emissive as black if necessary materialEditor.LightmapEmissionFlagsProperty(MaterialEditor.kMiniTextureFieldLabelIndentLevel, true, true); } } }
internal static void DoEmissiveIntensityGUI(MaterialEditor materialEditor, MaterialProperty emissiveIntensity, MaterialProperty emissiveIntensityUnit) { MaterialEditor.BeginProperty(emissiveIntensity); MaterialEditor.BeginProperty(emissiveIntensityUnit); bool unitIsMixed = emissiveIntensityUnit.hasMixedValue; bool intensityIsMixed = unitIsMixed || emissiveIntensity.hasMixedValue; float indent = 15 * EditorGUI.indentLevel; const int k_ValueUnitSeparator = 2; const int k_UnitWidth = 100; Rect valueRect = EditorGUILayout.GetControlRect(); valueRect.width += indent - k_ValueUnitSeparator - k_UnitWidth; Rect unitRect = valueRect; unitRect.x += valueRect.width - indent + k_ValueUnitSeparator; unitRect.width = k_UnitWidth + .5f; { EditorGUI.showMixedValue = intensityIsMixed; EmissiveIntensityUnit unit = (EmissiveIntensityUnit)emissiveIntensityUnit.floatValue; if (unitIsMixed) { using (new EditorGUI.DisabledScope(true)) materialEditor.ShaderProperty(valueRect, emissiveIntensity, Styles.emissiveIntensityText); } else { if (!intensityIsMixed && unit == EmissiveIntensityUnit.EV100) { float evValue = LightUtils.ConvertLuminanceToEv(emissiveIntensity.floatValue); evValue = EditorGUI.FloatField(valueRect, Styles.emissiveIntensityText, evValue); evValue = Mathf.Clamp(evValue, 0, s_MaxEvValue); emissiveIntensity.floatValue = LightUtils.ConvertEvToLuminance(evValue); } else { EditorGUI.BeginChangeCheck(); materialEditor.ShaderProperty(valueRect, emissiveIntensity, Styles.emissiveIntensityText); if (EditorGUI.EndChangeCheck()) { emissiveIntensity.floatValue = Mathf.Clamp(emissiveIntensity.floatValue, 0, float.MaxValue); } } } EditorGUI.showMixedValue = emissiveIntensityUnit.hasMixedValue; EditorGUI.BeginChangeCheck(); var newUnit = (EmissiveIntensityUnit)EditorGUI.EnumPopup(unitRect, unit); if (EditorGUI.EndChangeCheck()) { emissiveIntensityUnit.floatValue = (float)newUnit; } } EditorGUI.showMixedValue = false; MaterialEditor.EndProperty(); MaterialEditor.EndProperty(); }
public void ShaderPropertiesGUI(Material material) { // Use default labelWidth EditorGUIUtility.labelWidth = 0f; float normalBlendSrcValue = normalBlendSrc.floatValue; float maskBlendSrcValue = maskBlendSrc.floatValue; float smoothnessRemapMinValue = smoothnessRemapMin.floatValue; float smoothnessRemapMaxValue = smoothnessRemapMax.floatValue; float AORemapMinValue = AORemapMin.floatValue; float AORemapMaxValue = AORemapMax.floatValue; Decal.MaskBlendFlags maskBlendFlags = (Decal.MaskBlendFlags)maskBlendMode.floatValue; HDRenderPipelineAsset hdrp = GraphicsSettings.renderPipelineAsset as HDRenderPipelineAsset; bool perChannelMask = hdrp.currentPlatformRenderPipelineSettings.decalSettings.perChannelMask; using (var header = new HeaderScope(Styles.InputsText, (uint)Expandable.Input, this)) { if (header.expanded) { // Detect any changes to the material EditorGUI.BeginChangeCheck(); { m_MaterialEditor.TexturePropertySingleLine((material.GetFloat(kAlbedoMode) == 1.0f) ? Styles.baseColorText : Styles.baseColorText2, baseColorMap, baseColor); // Currently always display Albedo contribution as we have an albedo tint that apply EditorGUI.indentLevel++; m_MaterialEditor.ShaderProperty(albedoMode, Styles.albedoModeText); EditorGUI.indentLevel--; m_MaterialEditor.TexturePropertySingleLine(Styles.normalMapText, normalMap); if (material.GetTexture(kNormalMap)) { EditorGUI.indentLevel++; normalBlendSrcValue = EditorGUILayout.Popup("Normal Opacity channel", (int)normalBlendSrcValue, blendSourceNames); EditorGUI.indentLevel--; } m_MaterialEditor.TexturePropertySingleLine(Styles.maskMapText[(int)maskBlendFlags], maskMap); if (material.GetTexture(kMaskMap)) { EditorGUI.indentLevel++; EditorGUILayout.MinMaxSlider(Styles.smoothnessRemappingText, ref smoothnessRemapMinValue, ref smoothnessRemapMaxValue, 0.0f, 1.0f); if (perChannelMask) { m_MaterialEditor.ShaderProperty(metallicScale, Styles.metallicText); EditorGUILayout.MinMaxSlider(Styles.aoRemappingText, ref AORemapMinValue, ref AORemapMaxValue, 0.0f, 1.0f); } maskBlendSrcValue = EditorGUILayout.Popup("Mask Opacity channel", (int)maskBlendSrcValue, blendSourceNames); if (perChannelMask) { bool mustDisableScope = false; if (maskmapMetal.floatValue + maskmapAO.floatValue + maskmapSmoothness.floatValue == 1.0f) { mustDisableScope = true; } using (new EditorGUI.DisabledScope(mustDisableScope && maskmapMetal.floatValue == 1.0f)) { m_MaterialEditor.ShaderProperty(maskmapMetal, "Affect Metal"); } using (new EditorGUI.DisabledScope(mustDisableScope && maskmapAO.floatValue == 1.0f)) { m_MaterialEditor.ShaderProperty(maskmapAO, "Affect AO"); } using (new EditorGUI.DisabledScope(mustDisableScope && maskmapSmoothness.floatValue == 1.0f)) { m_MaterialEditor.ShaderProperty(maskmapSmoothness, "Affect Smoothness"); } // Sanity condition in case for whatever reasons all value are 0.0 but it should never happen if ((maskmapMetal.floatValue == 0.0f) && (maskmapAO.floatValue == 0.0f) && (maskmapSmoothness.floatValue == 0.0f)) { maskmapSmoothness.floatValue = 1.0f; } maskBlendFlags = 0; // Re-init the mask if (maskmapMetal.floatValue == 1.0f) { maskBlendFlags |= Decal.MaskBlendFlags.Metal; } if (maskmapAO.floatValue == 1.0f) { maskBlendFlags |= Decal.MaskBlendFlags.AO; } if (maskmapSmoothness.floatValue == 1.0f) { maskBlendFlags |= Decal.MaskBlendFlags.Smoothness; } } else // if perChannelMask is not enabled, force to have smoothness { maskBlendFlags = Decal.MaskBlendFlags.Smoothness; } EditorGUI.indentLevel--; } m_MaterialEditor.ShaderProperty(maskMapBlueScale, Styles.maskMapBlueScaleText); m_MaterialEditor.ShaderProperty(decalBlend, Styles.decalBlendText); m_MaterialEditor.ShaderProperty(emissive, "Emissive"); if (emissive.floatValue == 1.0f) { m_MaterialEditor.ShaderProperty(useEmissiveIntensity, "Use Emission Intensity"); if (useEmissiveIntensity.floatValue == 1.0f) { m_MaterialEditor.TexturePropertySingleLine(Styles.emissiveText, emissiveColorMap, emissiveColorLDR); using (new EditorGUILayout.HorizontalScope()) { EmissiveIntensityUnit unit = (EmissiveIntensityUnit)emissiveIntensityUnit.floatValue; if (unit == EmissiveIntensityUnit.Luminance) { m_MaterialEditor.ShaderProperty(emissiveIntensity, Styles.emissiveIntensityText); } else { float evValue = LightUtils.ConvertLuminanceToEv(emissiveIntensity.floatValue); evValue = EditorGUILayout.FloatField(Styles.emissiveIntensityText, evValue); emissiveIntensity.floatValue = LightUtils.ConvertEvToLuminance(evValue); } emissiveIntensityUnit.floatValue = (float)(EmissiveIntensityUnit)EditorGUILayout.EnumPopup(unit); } } else { m_MaterialEditor.TexturePropertySingleLine(Styles.emissiveText, emissiveColorMap, emissiveColorHDR); } } EditorGUI.indentLevel--; EditorGUILayout.HelpBox( "Control of AO and Metal is based on option 'Enable Metal and AO properties' in HDRP Asset.\nThere is a performance cost of enabling this option.", MessageType.Info); } if (EditorGUI.EndChangeCheck()) { normalBlendSrc.floatValue = normalBlendSrcValue; maskBlendSrc.floatValue = maskBlendSrcValue; maskBlendMode.floatValue = (float)maskBlendFlags; smoothnessRemapMin.floatValue = smoothnessRemapMinValue; smoothnessRemapMax.floatValue = smoothnessRemapMaxValue; AORemapMin.floatValue = AORemapMinValue; AORemapMax.floatValue = AORemapMaxValue; if (useEmissiveIntensity.floatValue == 1.0f) { emissiveColor.colorValue = emissiveColorLDR.colorValue * emissiveIntensity.floatValue; } else { emissiveColor.colorValue = emissiveColorHDR.colorValue; } foreach (var obj in m_MaterialEditor.targets) { SetupMaterialKeywordsAndPassInternal((Material)obj); } } } } EditorGUI.indentLevel++; using (var header = new HeaderScope(Styles.SortingText, (uint)Expandable.Sorting, this)) { if (header.expanded) { m_MaterialEditor.ShaderProperty(drawOrder, Styles.drawOrderText); m_MaterialEditor.ShaderProperty(decalMeshDepthBias, Styles.meshDecalDepthBiasText); } } EditorGUI.indentLevel--; }
static void ConvertLightIntensity(LightUnit oldLightUnit, LightUnit newLightUnit, SerializedHDLight serialized, Editor owner) { float intensity = serialized.serializedLightData.intensity.floatValue; Light light = (Light)owner.target; // For punctual lights if (oldLightUnit == LightUnit.Lumen && newLightUnit == LightUnit.Candela) { if (serialized.editorLightShape == LightShape.Spot && serialized.serializedLightData.enableSpotReflector.boolValue) { // We have already calculate the correct value, just assign it intensity = light.intensity; } else { intensity = LightUtils.ConvertPointLightLumenToCandela(intensity); } } if (oldLightUnit == LightUnit.Candela && newLightUnit == LightUnit.Lumen) { if (serialized.editorLightShape == LightShape.Spot && serialized.serializedLightData.enableSpotReflector.boolValue) { // We just need to multiply candela by solid angle in this case if ((SpotLightShape)serialized.serializedLightData.spotLightShape.enumValueIndex == SpotLightShape.Cone) { intensity = LightUtils.ConvertSpotLightCandelaToLumen(intensity, light.spotAngle * Mathf.Deg2Rad, true); } else if ((SpotLightShape)serialized.serializedLightData.spotLightShape.enumValueIndex == SpotLightShape.Pyramid) { float angleA, angleB; LightUtils.CalculateAnglesForPyramid(serialized.serializedLightData.aspectRatio.floatValue, light.spotAngle * Mathf.Deg2Rad, out angleA, out angleB); intensity = LightUtils.ConvertFrustrumLightCandelaToLumen(intensity, angleA, angleB); } else // Box { intensity = LightUtils.ConvertPointLightCandelaToLumen(intensity); } } else { intensity = LightUtils.ConvertPointLightCandelaToLumen(intensity); } } // For area lights if (oldLightUnit == LightUnit.Lumen && newLightUnit == LightUnit.Luminance) { intensity = LightUtils.ConvertAreaLightLumenToLuminance((LightTypeExtent)serialized.serializedLightData.lightTypeExtent.enumValueIndex, intensity, serialized.serializedLightData.shapeWidth.floatValue, serialized.serializedLightData.shapeHeight.floatValue); } if (oldLightUnit == LightUnit.Luminance && newLightUnit == LightUnit.Lumen) { intensity = LightUtils.ConvertAreaLightLuminanceToLumen((LightTypeExtent)serialized.serializedLightData.lightTypeExtent.enumValueIndex, intensity, serialized.serializedLightData.shapeWidth.floatValue, serialized.serializedLightData.shapeHeight.floatValue); } if (oldLightUnit == LightUnit.Luminance && newLightUnit == LightUnit.Ev100) { intensity = LightUtils.ConvertLuminanceToEv(intensity); } if (oldLightUnit == LightUnit.Ev100 && newLightUnit == LightUnit.Luminance) { intensity = LightUtils.ConvertEvToLuminance(intensity); } if (oldLightUnit == LightUnit.Ev100 && newLightUnit == LightUnit.Lumen) { intensity = LightUtils.ConvertAreaLightEvToLumen((LightTypeExtent)serialized.serializedLightData.lightTypeExtent.enumValueIndex, intensity, serialized.serializedLightData.shapeWidth.floatValue, serialized.serializedLightData.shapeHeight.floatValue); } if (oldLightUnit == LightUnit.Lumen && newLightUnit == LightUnit.Ev100) { intensity = LightUtils.ConvertAreaLightLumenToEv((LightTypeExtent)serialized.serializedLightData.lightTypeExtent.enumValueIndex, intensity, serialized.serializedLightData.shapeWidth.floatValue, serialized.serializedLightData.shapeHeight.floatValue); } serialized.serializedLightData.intensity.floatValue = intensity; }
public void LightOrder(List <StorageLight> lights) { try { lights = lights.GroupBy(r => new { r.LightOrder, r.ContinuedTime, r.RackPositionId, r.MainBoardId, r.LightColor }).Select(r => new StorageLight { RackPositionId = r.Key.RackPositionId, ContinuedTime = r.Key.ContinuedTime, MainBoardId = r.Key.MainBoardId, LightOrder = r.Key.LightOrder, LightColor = r.Key.LightColor }).ToList(); if (lights.Count == 1) { if (lights[0].LightColor > 0) { order.Enqueue(LightUtils.GetOneLightOrder_RGB(lights[0].MainBoardId.ToString().PadLeft(3, '0') + (lights[0].RackPositionId > 700 ? (lights[0].RackPositionId - 700).ToString() : lights[0].RackPositionId.ToString()).PadLeft(3, '0'), lights[0].LightOrder.ToString(), lights[0].LightColor, "5")); } else { order.Enqueue(ChangeToByte(LightUtils.GetOneLightOrder(lights[0].LightOrder, 10, 10, lights[0].ContinuedTime, lights[0].MainBoardId, lights[0].RackPositionId))); } } else { #region 多灯 //全部闪灯 List <StorageLight> lightsFlash = lights.FindAll(s => s.LightOrder == 2); //全部亮灭灯 List <StorageLight> lightsNoFlash = lights.FindAll(s => s.LightOrder == 1 || s.LightOrder == 0); foreach (var rack in lightsNoFlash.GroupBy(s => new { s.MainBoardId, s.LightColor })) { Dictionary <int, int> dic = new Dictionary <int, int>(); foreach (var library in rack) { if (dic.Keys.Contains(library.RackPositionId)) { dic[library.RackPositionId] = library.LightOrder; } else { dic.Add(library.RackPositionId, library.LightOrder); } } //添加多灯命令 if (rack.Key.LightColor == 0) { order.Enqueue(ChangeToByte(LightUtils.GetMoreLightsOrder(dic, rack.Key.MainBoardId))); } else { order.Enqueue(LightUtils.GetMoreLightsOrder_RGB(dic, rack.Key.MainBoardId, rack.Key.LightColor, "1")); } } //添加闪灯命令 lightsFlash.ForEach(s => { if (s.LightColor == 0) { order.Enqueue(ChangeToByte(LightUtils.GetOneLightOrder(s.LightOrder, 10, 10, s.ContinuedTime, s.MainBoardId, s.RackPositionId)) ); } else { order.Enqueue(LightUtils.GetOneLightOrder_RGB(s.MainBoardId.ToString().PadLeft(3, '0') + s.RackPositionId.ToString().PadLeft(3, '0'), s.LightOrder.ToString(), s.LightColor, "5")); } }); #endregion } } catch (Exception ee) { Log.Error(ee); } }
void DrawDecalGUI() { bool perChannelMask = false; HDRenderPipelineAsset hdrp = HDRenderPipeline.currentAsset; if (hdrp != null) { perChannelMask = hdrp.currentPlatformRenderPipelineSettings.decalSettings.perChannelMask; } bool allMaskMap = materials.All(m => m.GetTexture(kMaskMap)); materialEditor.TexturePropertySingleLine((materials[0].GetFloat(kAffectAlbedo) == 1.0f) ? Styles.baseColorText : Styles.baseColorText2, baseColorMap, baseColor); materialEditor.TexturePropertySingleLine(Styles.normalMapText, normalMap); if (materials.All(m => m.GetTexture(kNormalMap))) { EditorGUI.indentLevel++; EditorGUI.BeginChangeCheck(); var normalBlendSrcValue = (int)normalBlendSrc.floatValue; normalBlendSrcValue = EditorGUILayout.Popup(Styles.normalOpacityChannelText, normalBlendSrcValue, allMaskMap ? blendSourceNames : blendSourceNamesNoMap); if (EditorGUI.EndChangeCheck()) { normalBlendSrc.floatValue = normalBlendSrcValue; } EditorGUI.indentLevel--; } materialEditor.TexturePropertySingleLine(Styles.maskMapText, maskMap); EditorGUI.indentLevel++; if (allMaskMap) { if (perChannelMask) { float MetalRemapMinValue = metallicRemapMin.floatValue; float MetalRemapMaxValue = metallicRemapMax.floatValue; EditorGUI.BeginChangeCheck(); EditorGUILayout.MinMaxSlider(Styles.metallicRemappingText, ref MetalRemapMinValue, ref MetalRemapMaxValue, 0.0f, 1.0f); if (EditorGUI.EndChangeCheck()) { metallicRemapMin.floatValue = MetalRemapMinValue; metallicRemapMax.floatValue = MetalRemapMaxValue; } float AORemapMinValue = AORemapMin.floatValue; float AORemapMaxValue = AORemapMax.floatValue; EditorGUI.BeginChangeCheck(); EditorGUILayout.MinMaxSlider(Styles.aoRemappingText, ref AORemapMinValue, ref AORemapMaxValue, 0.0f, 1.0f); if (EditorGUI.EndChangeCheck()) { AORemapMin.floatValue = AORemapMinValue; AORemapMax.floatValue = AORemapMaxValue; } } float smoothnessRemapMinValue = smoothnessRemapMin.floatValue; float smoothnessRemapMaxValue = smoothnessRemapMax.floatValue; EditorGUI.BeginChangeCheck(); EditorGUILayout.MinMaxSlider(Styles.smoothnessRemappingText, ref smoothnessRemapMinValue, ref smoothnessRemapMaxValue, 0.0f, 1.0f); if (EditorGUI.EndChangeCheck()) { smoothnessRemapMin.floatValue = smoothnessRemapMinValue; smoothnessRemapMax.floatValue = smoothnessRemapMaxValue; } } else { if (perChannelMask) { materialEditor.ShaderProperty(metallic, Styles.metallicText); materialEditor.ShaderProperty(AO, Styles.aoText); } materialEditor.ShaderProperty(smoothness, Styles.smoothnessText); } EditorGUI.BeginChangeCheck(); var maskBlendSrcValue = (int)maskBlendSrc.floatValue; maskBlendSrcValue = EditorGUILayout.Popup(Styles.maskOpacityChannelText, maskBlendSrcValue, allMaskMap ? blendSourceNames : blendSourceNamesNoMap); if (EditorGUI.EndChangeCheck()) { maskBlendSrc.floatValue = maskBlendSrcValue; } EditorGUI.indentLevel--; materialEditor.ShaderProperty(maskMapBlueScale, allMaskMap ? Styles.maskMapBlueScaleText : Styles.opacityBlueScaleText); materialEditor.ShaderProperty(decalBlend, Styles.decalBlendText); //if (affectEmission.floatValue == 1.0f) // Always show emissive part using (var scope = new EditorGUI.ChangeCheckScope()) { materialEditor.ShaderProperty(useEmissiveIntensity, Styles.useEmissionIntensityText); if (useEmissiveIntensity.floatValue == 1.0f) { materialEditor.TexturePropertySingleLine(Styles.emissionMapText, emissiveColorMap, emissiveColorLDR); using (new EditorGUILayout.HorizontalScope()) { EmissiveIntensityUnit unit = (EmissiveIntensityUnit)emissiveIntensityUnit.floatValue; if (unit == EmissiveIntensityUnit.Nits) { materialEditor.ShaderProperty(emissiveIntensity, Styles.emissiveIntensityText); } else { float evValue = LightUtils.ConvertLuminanceToEv(emissiveIntensity.floatValue); evValue = EditorGUILayout.FloatField(Styles.emissiveIntensityText, evValue); emissiveIntensity.floatValue = LightUtils.ConvertEvToLuminance(evValue); } emissiveIntensityUnit.floatValue = (float)(EmissiveIntensityUnit)EditorGUILayout.EnumPopup(unit); } } else { materialEditor.TexturePropertySingleLine(Styles.emissionMapText, emissiveColorMap, emissiveColorHDR); } materialEditor.ShaderProperty(emissiveExposureWeight, Styles.emissiveExposureWeightText); // If anything change, update the emission value if (scope.changed) { if (useEmissiveIntensity.floatValue == 1.0f) { materialEditor.serializedObject.ApplyModifiedProperties(); foreach (Material target in materials) { target.UpdateEmissiveColorFromIntensityAndEmissiveColorLDR(); } materialEditor.serializedObject.Update(); } else { emissiveColor.colorValue = emissiveColorHDR.colorValue; } } } }
void DrawEmissionGUI() { EditorGUI.BeginChangeCheck(); materialEditor.ShaderProperty(useEmissiveIntensity, Styles.useEmissiveIntensityText); bool updateEmissiveColor = EditorGUI.EndChangeCheck(); if (useEmissiveIntensity.floatValue == 0) { EditorGUI.BeginChangeCheck(); DoEmissiveTextureProperty(emissiveColor); if (EditorGUI.EndChangeCheck() || updateEmissiveColor) { emissiveColor.colorValue = emissiveColor.colorValue; } EditorGUILayout.HelpBox(Styles.emissiveIntensityFromHDRColorText.text, MessageType.Info, true); } else { float newUnitFloat; float newIntensity = emissiveIntensity.floatValue; bool unitIsMixed = emissiveIntensityUnit.hasMixedValue; bool intensityIsMixed = unitIsMixed || emissiveIntensity.hasMixedValue; bool intensityChanged = false; bool unitChanged = false; EditorGUI.BeginChangeCheck(); { DoEmissiveTextureProperty(emissiveColorLDR); using (new EditorGUILayout.HorizontalScope()) { EmissiveIntensityUnit unit = (EmissiveIntensityUnit)emissiveIntensityUnit.floatValue; EditorGUI.showMixedValue = intensityIsMixed; if (unit == EmissiveIntensityUnit.Nits) { using (var change = new EditorGUI.ChangeCheckScope()) { materialEditor.ShaderProperty(emissiveIntensity, Styles.emissiveIntensityText); intensityChanged = change.changed; if (intensityChanged) { newIntensity = Mathf.Clamp(emissiveIntensity.floatValue, 0, float.MaxValue); } } } else { float value = emissiveIntensity.floatValue; if (!intensityIsMixed) { float evValue = LightUtils.ConvertLuminanceToEv(emissiveIntensity.floatValue); evValue = EditorGUILayout.FloatField(Styles.emissiveIntensityText, evValue); newIntensity = Mathf.Clamp(evValue, 0, float.MaxValue); emissiveIntensity.floatValue = LightUtils.ConvertEvToLuminance(evValue); } else { using (var change = new EditorGUI.ChangeCheckScope()) { newIntensity = EditorGUILayout.FloatField(Styles.emissiveIntensityText, value); intensityChanged = change.changed; } } } EditorGUI.showMixedValue = false; EditorGUI.showMixedValue = emissiveIntensityUnit.hasMixedValue; using (var change = new EditorGUI.ChangeCheckScope()) { newUnitFloat = (float)(EmissiveIntensityUnit)EditorGUILayout.EnumPopup(unit); unitChanged = change.changed; } EditorGUI.showMixedValue = false; } } if (EditorGUI.EndChangeCheck() || updateEmissiveColor) { if (unitChanged) { if (unitIsMixed) { UpdateEmissionUnit(newUnitFloat); } else { emissiveIntensityUnit.floatValue = newUnitFloat; } } // We don't allow changes on intensity if units are mixed if (intensityChanged && !unitIsMixed) { emissiveIntensity.floatValue = newIntensity; } UpdateEmissiveColorFromIntensityAndEmissiveColorLDR(); } } materialEditor.ShaderProperty(emissiveExposureWeight, Styles.emissiveExposureWeightText); if ((m_Features & Features.MultiplyWithBase) != 0) { materialEditor.ShaderProperty(albedoAffectEmissive, Styles.albedoAffectEmissiveText); } // Emission for GI? if ((m_Features & Features.EnableEmissionForGI) != 0) { // Change the GI emission flag and fix it up with emissive as black if necessary. materialEditor.LightmapEmissionFlagsProperty(MaterialEditor.kMiniTextureFieldLabelIndentLevel, true); } }
void ParseHeader(BinaryReader BR) { //used utils/vrad/vradstaticprops.cpp:1506 -- void CVradStaticPropMgr::SerializeLighting() if (BR.BaseStream.Length < 40) { throw new Exception("Not a VHV file! (file size is less than header size)"); } //parsing main header BR.BaseStream.Seek(0, SeekOrigin.Begin); Header = new Structs.FileHeader_t { m_nVersion = BR.ReadInt32(), m_nChecksum = BR.ReadUInt32(), m_nVertexFlags = (Structs.VertexFlags)BR.ReadUInt32(), m_nVertexSize = BR.ReadUInt32(), m_nVertexes = BR.ReadUInt32(), m_nMeshes = BR.ReadInt32() }; //int[] unused = BR.ReadInt32Array(4); BR.BaseStream.Seek(16, SeekOrigin.Current); //skip unused if (Header.m_nVersion != Structs.VHV_VERSION) { throw new Exception($"Not supported version or not a VHV file! ({Header.m_nVersion}!={Structs.VHV_VERSION})"); } //parsing mesh headers Header.pMesh = new Structs.MeshHeader_t[Header.m_nMeshes]; for (int n = 0; n < Header.m_nMeshes; n++) { // construct mesh dictionary Header.pMesh[n] = new Structs.MeshHeader_t { m_nLod = BR.ReadUInt32(), m_nVertexes = BR.ReadUInt32(), m_nOffset = BR.ReadUInt32() }; BR.BaseStream.Seek(16, SeekOrigin.Current); //skip unused } //BR.BaseStream.Seek(4 * 109, SeekOrigin.Current); for (int n = 0; n < Header.m_nMeshes; n++) { // construct vertexes var pMesh = Header.pMesh[n]; BR.BaseStream.Seek(pMesh.m_nOffset, SeekOrigin.Begin); ColorRGBExp32[] m_VertexColors = new ColorRGBExp32[pMesh.m_nVertexes]; long POSITION_THERE = BR.BaseStream.Position; long BYTES_LEFT = BR.BaseStream.Length - POSITION_THERE; for (int k = 0; k < pMesh.m_nVertexes; k++) { //Vector vertexColor = m_StaticProps[i].m_MeshData[n].m_VertexColors[k]; //ColorRGBExp32 rgbColor; //VectorToColorRGBExp32(vertexColor, rgbColor); //byte[] dstColor;//[4]; //ConvertRGBExp32ToRGBA8888(rgbColor, dstColor); // b,g,r,a order //pVertexData[0] = dstColor[2]; //pVertexData[1] = dstColor[1]; //pVertexData[2] = dstColor[0]; //pVertexData[3] = dstColor[3]; //pVertexData += 4; //RGBA8888 -> RGBExp32 // Linear to Tex light [0-1 to 0-255] (mb to gamma?) //RGBExp32 -> Vector //if (Header.m_nVertexFlags.HasFlag(Structs.VertexFlags.VERTEX_COLOR)) //{ // //byte[] colordata = BR.ReadBytes(4); // byte[] colordata = BR.ReadBytes(3); // //0 1 2 3 // //4 5 6 7 // //8 9 10 11 // //float exponent = (float)System.Math.Pow(2f, colordata[3]); // //m_VertexColors[k] = new ColorRGBExp32(colordata[0], // // colordata[1], // // colordata[2], // // 255); // m_VertexColors[k] = new ColorRGBExp32(LightUtils.linearToTexLight(colordata[0], 1f), // LightUtils.linearToTexLight(colordata[1], 1f), // LightUtils.linearToTexLight(colordata[2], 1f), // 255); //} //else if (Header.m_nVertexFlags.HasFlag(Structs.VertexFlags.VERTEX_NORMAL)) { byte[] colordata = BR.ReadBytes(12); //0 1 2 3 //4 5 6 7 //8 9 10 11 float exponent = (float)Math.Pow(2f, MathUtils.Avg(colordata[3], colordata[7], colordata[11])); m_VertexColors[k] = new ColorRGBExp32(LightUtils.linearToTexLight(MathUtils.Avg(colordata[2], colordata[6], colordata[10]), exponent), LightUtils.linearToTexLight(MathUtils.Avg(colordata[1], colordata[5], colordata[9]), exponent), LightUtils.linearToTexLight(MathUtils.Avg(colordata[0], colordata[4], colordata[8]), exponent), 255); } else { throw new NotImplementedException("Not implemented vertex flag: " + Header.m_nVertexFlags); } } Header.pMesh[n].m_VertexColors = m_VertexColors; } }
void DrawDecalGUI() { normalBlendSrcValue = normalBlendSrc.floatValue; maskBlendSrcValue = maskBlendSrc.floatValue; smoothnessRemapMinValue = smoothnessRemapMin.floatValue; smoothnessRemapMaxValue = smoothnessRemapMax.floatValue; AORemapMinValue = AORemapMin.floatValue; AORemapMaxValue = AORemapMax.floatValue; maskBlendFlags = (Decal.MaskBlendFlags)maskBlendMode.floatValue; HDRenderPipelineAsset hdrp = HDRenderPipeline.currentAsset; bool perChannelMask = hdrp.currentPlatformRenderPipelineSettings.decalSettings.perChannelMask; // Detect any changes to the material EditorGUI.BeginChangeCheck(); { materialEditor.TexturePropertySingleLine((materials[0].GetFloat(kAlbedoMode) == 1.0f) ? Styles.baseColorText : Styles.baseColorText2, baseColorMap, baseColor); // Currently always display Albedo contribution as we have an albedo tint that apply EditorGUI.indentLevel++; materialEditor.ShaderProperty(albedoMode, Styles.albedoModeText); EditorGUI.indentLevel--; materialEditor.TexturePropertySingleLine(Styles.normalMapText, normalMap); if (materials.All(m => m.GetTexture(kNormalMap))) { EditorGUI.indentLevel++; normalBlendSrcValue = EditorGUILayout.Popup(Styles.normalOpacityChannelText, (int)normalBlendSrcValue, blendSourceNames); EditorGUI.indentLevel--; } materialEditor.TexturePropertySingleLine(Styles.maskMapText[(int)maskBlendFlags], maskMap); if (materials.All(m => m.GetTexture(kMaskMap))) { EditorGUI.indentLevel++; EditorGUILayout.MinMaxSlider(Styles.smoothnessRemappingText, ref smoothnessRemapMinValue, ref smoothnessRemapMaxValue, 0.0f, 1.0f); if (perChannelMask) { materialEditor.ShaderProperty(metallicScale, Styles.metallicText); EditorGUILayout.MinMaxSlider(Styles.aoRemappingText, ref AORemapMinValue, ref AORemapMaxValue, 0.0f, 1.0f); } maskBlendSrcValue = EditorGUILayout.Popup(Styles.maskOpacityChannelText, (int)maskBlendSrcValue, blendSourceNames); if (perChannelMask) { bool mustDisableScope = false; if (maskmapMetal.floatValue + maskmapAO.floatValue + maskmapSmoothness.floatValue == 1.0f) { mustDisableScope = true; } using (new EditorGUI.DisabledScope(mustDisableScope && maskmapMetal.floatValue == 1.0f)) { materialEditor.ShaderProperty(maskmapMetal, Styles.affectMetalText); } using (new EditorGUI.DisabledScope(mustDisableScope && maskmapAO.floatValue == 1.0f)) { materialEditor.ShaderProperty(maskmapAO, Styles.affectAmbientOcclusionText); } using (new EditorGUI.DisabledScope(mustDisableScope && maskmapSmoothness.floatValue == 1.0f)) { materialEditor.ShaderProperty(maskmapSmoothness, Styles.affectSmoothnessText); } // Sanity condition in case for whatever reasons all value are 0.0 but it should never happen if ((maskmapMetal.floatValue == 0.0f) && (maskmapAO.floatValue == 0.0f) && (maskmapSmoothness.floatValue == 0.0f)) { maskmapSmoothness.floatValue = 1.0f; } maskBlendFlags = 0; // Re-init the mask if (maskmapMetal.floatValue == 1.0f) { maskBlendFlags |= Decal.MaskBlendFlags.Metal; } if (maskmapAO.floatValue == 1.0f) { maskBlendFlags |= Decal.MaskBlendFlags.AO; } if (maskmapSmoothness.floatValue == 1.0f) { maskBlendFlags |= Decal.MaskBlendFlags.Smoothness; } } else // if perChannelMask is not enabled, force to have smoothness { maskBlendFlags = Decal.MaskBlendFlags.Smoothness; } EditorGUI.indentLevel--; } materialEditor.ShaderProperty(maskMapBlueScale, Styles.maskMapBlueScaleText); materialEditor.ShaderProperty(decalBlend, Styles.decalBlendText); materialEditor.ShaderProperty(emissive, Styles.emissiveText); if (emissive.floatValue == 1.0f) { materialEditor.ShaderProperty(useEmissiveIntensity, Styles.useEmissionIntensityText); if (useEmissiveIntensity.floatValue == 1.0f) { materialEditor.TexturePropertySingleLine(Styles.emissionMapText, emissiveColorMap, emissiveColorLDR); using (new EditorGUILayout.HorizontalScope()) { EmissiveIntensityUnit unit = (EmissiveIntensityUnit)emissiveIntensityUnit.floatValue; if (unit == EmissiveIntensityUnit.Nits) { materialEditor.ShaderProperty(emissiveIntensity, Styles.emissiveIntensityText); } else { float evValue = LightUtils.ConvertLuminanceToEv(emissiveIntensity.floatValue); evValue = EditorGUILayout.FloatField(Styles.emissiveIntensityText, evValue); emissiveIntensity.floatValue = LightUtils.ConvertEvToLuminance(evValue); } emissiveIntensityUnit.floatValue = (float)(EmissiveIntensityUnit)EditorGUILayout.EnumPopup(unit); } } else { materialEditor.TexturePropertySingleLine(Styles.emissionMapText, emissiveColorMap, emissiveColorHDR); } materialEditor.ShaderProperty(emissiveExposureWeight, Styles.emissiveExposureWeightText); } if (!perChannelMask) { EditorGUILayout.HelpBox("Enable 'Metal and AO properties' in your HDRP Asset if you want to control the Metal and AO properties of decals.\nThere is a performance cost of enabling this option.", MessageType.Info); } } }
// Caution: this function must match the one in HDAdditionalLightData.ConvertPhysicalLightIntensityToLightIntensity - any change need to be replicated void UpdateLightIntensity() { // Clamp negative values. m_AdditionalLightData.directionalIntensity.floatValue = Mathf.Max(0, m_AdditionalLightData.directionalIntensity.floatValue); m_AdditionalLightData.punctualIntensity.floatValue = Mathf.Max(0, m_AdditionalLightData.punctualIntensity.floatValue); m_AdditionalLightData.areaIntensity.floatValue = Mathf.Max(0, m_AdditionalLightData.areaIntensity.floatValue); switch (m_LightShape) { case LightShape.Directional: settings.intensity.floatValue = m_AdditionalLightData.directionalIntensity.floatValue; break; case LightShape.Point: settings.intensity.floatValue = LightUtils.ConvertPointLightIntensity(m_AdditionalLightData.punctualIntensity.floatValue); break; case LightShape.Spot: // Spot should used conversion which take into account the angle, and thus the intensity vary with angle. // This is not easy to manipulate for lighter, so we simply consider any spot light as just occluded point light. So reuse the same code. var spotLightShape = (SpotLightShape)m_AdditionalLightData.spotLightShape.enumValueIndex; if (m_AdditionalLightData.enableSpotReflector.boolValue) { if (spotLightShape == SpotLightShape.Cone) { settings.intensity.floatValue = LightUtils.ConvertSpotLightIntensity(m_AdditionalLightData.punctualIntensity.floatValue, settings.spotAngle.floatValue * Mathf.Deg2Rad, true); } else if (spotLightShape == SpotLightShape.Pyramid) { var aspectRatio = m_AdditionalLightData.aspectRatio.floatValue; // Since the smallest angles is = to the fov, and we don't care of the angle order, simply make sure the aspect ratio is > 1 if (aspectRatio < 1f) { aspectRatio = 1f / aspectRatio; } var angleA = settings.spotAngle.floatValue * Mathf.Deg2Rad; var halfAngle = angleA * 0.5f; // half of the smallest angle var length = Mathf.Tan(halfAngle); // half length of the smallest side of the rectangle length *= aspectRatio; // half length of the bigest side of the rectangle halfAngle = Mathf.Atan(length); // half of the bigest angle var angleB = halfAngle * 2f; settings.intensity.floatValue = LightUtils.ConvertFrustrumLightIntensity(m_AdditionalLightData.punctualIntensity.floatValue, angleA, angleB); } else // Box shape, fallback to punctual light. { settings.intensity.floatValue = LightUtils.ConvertPointLightIntensity(m_AdditionalLightData.punctualIntensity.floatValue); } } else // Reflector disabled, fallback to punctual light. { settings.intensity.floatValue = LightUtils.ConvertPointLightIntensity(m_AdditionalLightData.punctualIntensity.floatValue); } break; case LightShape.Rectangle: settings.intensity.floatValue = LightUtils.ConvertRectLightIntensity(m_AdditionalLightData.areaIntensity.floatValue, m_AdditionalLightData.shapeWidth.floatValue, m_AdditionalLightData.shapeHeight.floatValue); break; case LightShape.Line: settings.intensity.floatValue = LightUtils.CalculateLineLightIntensity(m_AdditionalLightData.areaIntensity.floatValue, m_AdditionalLightData.shapeWidth.floatValue); break; } }