void UpdateAreaLightEmissiveMeshComponents() { foreach (var hdLightData in m_AdditionalLightDatas) { hdLightData.UpdateAreaLightEmissiveMesh(); MeshRenderer emissiveMeshRenderer = hdLightData.GetComponent <MeshRenderer>(); MeshFilter emissiveMeshFilter = hdLightData.GetComponent <MeshFilter>(); // If the display emissive mesh is disabled, skip to the next selected light if (emissiveMeshFilter == null || emissiveMeshRenderer == null) { continue; } // We only load the mesh and it's material here, because we can't do that inside HDAdditionalLightData (Editor assembly) // Every other properties of the mesh is updated in HDAdditionalLightData to support timeline and editor records emissiveMeshFilter.mesh = HDEditorUtils.LoadAsset <Mesh>("Runtime/RenderPipelineResources/Mesh/Quad.FBX"); if (emissiveMeshRenderer.sharedMaterial == null) { emissiveMeshRenderer.material = new Material(Shader.Find("HDRenderPipeline/Unlit")); } } m_SerializedHDLight.needUpdateAreaLightEmissiveMeshComponents = false; }
void UpdateAreaLightEmissiveMeshComponents() { foreach (var hdLightData in m_AdditionalLightDatas) { hdLightData.UpdateAreaLightEmissiveMesh(); MeshRenderer emissiveMeshRenderer = hdLightData.GetComponent <MeshRenderer>(); MeshFilter emissiveMeshFilter = hdLightData.GetComponent <MeshFilter>(); // If the display emissive mesh is disabled, skip to the next selected light if (emissiveMeshFilter == null || emissiveMeshRenderer == null) { continue; } // We only load the mesh and it's material here, because we can't do that inside HDAdditionalLightData (Editor assembly) // Every other properties of the mesh is updated in HDAdditionalLightData to support timeline and editor records switch (hdLightData.lightTypeExtent) { case LightTypeExtent.Tube: emissiveMeshFilter.mesh = HDEditorUtils.LoadAsset <Mesh>("Runtime/RenderPipelineResources/Mesh/Cylinder.fbx"); break; case LightTypeExtent.Rectangle: default: emissiveMeshFilter.mesh = HDEditorUtils.LoadAsset <Mesh>("Runtime/RenderPipelineResources/Mesh/Quad.FBX"); break; } if (emissiveMeshRenderer.sharedMaterial == null) { emissiveMeshRenderer.sharedMaterial = new Material(Shader.Find("HDRP/Unlit")); } emissiveMeshRenderer.sharedMaterial.SetFloat("_IncludeIndirectLighting", 0.0f); } m_SerializedHDLight.needUpdateAreaLightEmissiveMeshComponents = false; }
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); } }