/// <summary> /// Calculates the intensity of a light sponge. /// </summary> /// <param name="vertex">The world position of the vertex to light.</param> /// <param name="normal">The world normal of the vertex to light.</param> /// <param name="sponge">The reference light sponge.</param> public static Color CalculateColorSponge(Vector3 vertex, Vector3 normal, LightSponge sponge) { if (!sponge) { return(Color.white); } if (sponge.Shape == LightSponge.SpongeShape.Box) { return(CalculateColorSpongeCubic(vertex, normal, sponge.transform.position, sponge.transform.rotation, sponge.BoxBounds, sponge.Intensity, sponge.IgnoreReverseNormals)); } return(CalculateColorSpongeSpherical(vertex, normal, sponge.transform.position, sponge.SphereRadius, sponge.Intensity, sponge.IgnoreReverseNormals)); }
private void OnSceneGUI() { LightSponge sponge = (LightSponge)target; if (sponge.Shape == SpongeShape.Box) { DoBoxHandles(sponge); } else { DoSphereHandles(sponge); } }
private void DoSphereHandles(LightSponge sponge) { EditorGUI.BeginChangeCheck(); /*---Radius Handle---*/ Handles.color = _handlesColor; float newRadius = Handles.RadiusHandle(Quaternion.identity, sponge.transform.position, sponge.SphereRadius); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(sponge, "Updated Light Sponge Radius"); sponge.SphereRadius = newRadius; } Handles.color = Color.white; }
public override void OnInspectorGUI() { LightSponge sponge = (LightSponge)target; EditorGUI.BeginChangeCheck(); SpongeShape newShape = (SpongeShape)EditorGUILayout.EnumPopup(new GUIContent("Shape", "The shape of the sponge"), sponge.Shape); GUILayout.Space(10); bool newIgnore = EditorGUILayout.Toggle(new GUIContent("Ignore Opposite Normals", "Whether this sponge will ignore normals facing away from it."), sponge.IgnoreReverseNormals); float newIntensity = EditorGUILayout.Slider(new GUIContent("Intensity", "How much ambient and directional light this sponge will absorb."), sponge.Intensity, 0.0f, 1.0f); if (Mathf.Approximately(newIntensity, 0.0f)) { EditorGUILayout.HelpBox("Light sponges with an intensity of 0 are excluded from lighting bakes.", MessageType.Warning); } if (sponge.Shape == SpongeShape.Box) { Vector3 newBounds = EditorGUILayout.Vector3Field(new GUIContent("Bounds", "The bounds of the sponge."), sponge.BoxBounds); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(sponge, "Updated Light Sponge"); sponge.Shape = newShape; sponge.IgnoreReverseNormals = newIgnore; sponge.Intensity = newIntensity; sponge.BoxBounds = newBounds; } } else { float newRadius = EditorGUILayout.FloatField(new GUIContent("Radius", "The radius of the sponge."), sponge.SphereRadius); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(sponge, "Updated Light Sponge"); sponge.Shape = newShape; sponge.IgnoreReverseNormals = newIgnore; sponge.Intensity = newIntensity; sponge.SphereRadius = newRadius; } } }
public static void CreateNewLightSponge() { SceneView view = SceneView.currentDrawingSceneView; if (!view) { view = SceneView.lastActiveSceneView; } if (view) { Transform cameraT = view.camera.transform; GameObject newSponge = new GameObject("Light Sponge"); newSponge.transform.position = cameraT.position + cameraT.forward * 10.0f; LightSponge ls = newSponge.AddComponent <LightSponge>(); Selection.activeObject = newSponge; } }
private void DoBoxHandles(LightSponge sponge) { /*---Box Handle---*/ Handles.color = _handlesColor; if (_boundsHandle == null) { _boundsHandle = new BoxBoundsHandle(); } _boundsHandle.size = sponge.BoxBounds; _boundsHandle.center = sponge.transform.position; _boundsHandle.DrawHandle(); if (sponge.BoxBounds != _boundsHandle.size) { Undo.RecordObject(sponge, "Updated Light Sponge Bounds"); sponge.BoxBounds = _boundsHandle.size; } Handles.color = Color.white; }