Thomas
7 年前
当前提交
0854d3d2
共有 5 个文件被更改,包括 285 次插入 和 230 次删除
-
259ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/SubsurfaceScatteringProfile.cs
-
60ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Editor/SubsurfaceScatteringProfileEditor.Styles.cs
-
13ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Editor/SubsurfaceScatteringProfileEditor.Styles.cs.meta
-
170ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Editor/SubsurfaceScatteringProfileEditor.cs
-
13ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Editor/SubsurfaceScatteringProfileEditor.cs.meta
|
|||
using UnityEngine; |
|||
|
|||
namespace UnityEditor.Experimental.Rendering.HDPipeline |
|||
{ |
|||
partial class SubsurfaceScatteringProfileEditor |
|||
{ |
|||
sealed class Styles |
|||
{ |
|||
public readonly GUIContent profilePreview0 = new GUIContent("Profile Preview"); |
|||
public readonly GUIContent profilePreview1 = new GUIContent("Shows the fraction of light scattered from the source (center)."); |
|||
public readonly GUIContent profilePreview2 = new GUIContent("The distance to the boundary of the image corresponds to the Max Radius."); |
|||
public readonly GUIContent profilePreview3 = new GUIContent("Note that the intensity of pixels around the center may be clipped."); |
|||
public readonly GUIContent transmittancePreview0 = new GUIContent("Transmittance Preview"); |
|||
public readonly GUIContent transmittancePreview1 = new GUIContent("Shows the fraction of light passing through the object for thickness values from the remap."); |
|||
public readonly GUIContent transmittancePreview2 = new GUIContent("Can be viewed as a cross section of a slab of material illuminated by white light from the left."); |
|||
public readonly GUIContent profileScatteringDistance = new GUIContent("Scattering Distance", "Determines the shape of the profile, and the blur radius of the filter per color channel. Alpha is ignored."); |
|||
public readonly GUIContent profileTransmissionTint = new GUIContent("Transmission tint", "Color which tints transmitted light. Alpha is ignored."); |
|||
public readonly GUIContent profileMaxRadius = new GUIContent("Max Radius", "Effective radius of the filter (in millimeters). The blur is energy-preserving, so a wide filter results in a large area with small contributions of individual samples. Reducing the distance increases the sharpness of the result."); |
|||
public readonly GUIContent texturingMode = new GUIContent("Texturing Mode", "Specifies when the diffuse texture should be applied."); |
|||
public readonly GUIContent[] texturingModeOptions = new GUIContent[2] |
|||
{ |
|||
new GUIContent("Pre- and post-scatter", "Texturing is performed during both the lighting and the SSS passes. Slightly blurs the diffuse texture. Choose this mode if your diffuse texture contains little to no SSS lighting."), |
|||
new GUIContent("Post-scatter", "Texturing is performed only during the SSS pass. Effectively preserves the sharpness of the diffuse texture. Choose this mode if your diffuse texture already contains SSS lighting (e.g. a photo of skin).") |
|||
}; |
|||
public readonly GUIContent profileTransmissionMode = new GUIContent("Transmission Mode", "Configures the simulation of light passing through thin objects. Depends on the thickness value (which is applied in the normal direction)."); |
|||
public readonly GUIContent[] transmissionModeOptions = new GUIContent[3] |
|||
{ |
|||
new GUIContent("None", "Disables transmission. Choose this mode for completely opaque, or very thick translucent objects."), |
|||
new GUIContent("Thin Object", "Choose this mode for thin objects, such as paper or leaves. Transmitted light reuses the shadowing state of the surface."), |
|||
new GUIContent("Regular", "Choose this mode for moderately thick objects. For performance reasons, transmitted light ignores occlusion (shadows).") |
|||
}; |
|||
public readonly GUIContent profileMinMaxThickness = new GUIContent("Min-Max Thickness", "Shows the values of the thickness remap below (in millimeters)."); |
|||
public readonly GUIContent profileThicknessRemap = new GUIContent("Thickness Remap", "Remaps the thickness parameter from [0, 1] to the desired range (in millimeters)."); |
|||
public readonly GUIContent profileWorldScale = new GUIContent("World Scale", "Size of the world unit in meters."); |
|||
// Old SSS Model >>>
|
|||
public readonly GUIContent profileScatterDistance1 = new GUIContent("Scattering Distance #1", "The radius (in centimeters) of the 1st Gaussian filter, one per color channel. Alpha is ignored. The blur is energy-preserving, so a wide filter results in a large area with small contributions of individual samples. Smaller values increase the sharpness."); |
|||
public readonly GUIContent profileScatterDistance2 = new GUIContent("Scattering Distance #2", "The radius (in centimeters) of the 2nd Gaussian filter, one per color channel. Alpha is ignored. The blur is energy-preserving, so a wide filter results in a large area with small contributions of individual samples. Smaller values increase the sharpness."); |
|||
public readonly GUIContent profileLerpWeight = new GUIContent("Filter Interpolation", "Controls linear interpolation between the two Gaussian filters."); |
|||
// <<< Old SSS Model
|
|||
public readonly GUIStyle centeredMiniBoldLabel = new GUIStyle(GUI.skin.label); |
|||
|
|||
public Styles() |
|||
{ |
|||
centeredMiniBoldLabel.alignment = TextAnchor.MiddleCenter; |
|||
centeredMiniBoldLabel.fontSize = 10; |
|||
centeredMiniBoldLabel.fontStyle = FontStyle.Bold; |
|||
} |
|||
} |
|||
|
|||
static Styles s_Styles; |
|||
|
|||
// Can't use a static initializer in case we need to create GUIStyle in the Styles class as
|
|||
// these can only be created with an active GUI rendering context
|
|||
void CheckStyles() |
|||
{ |
|||
if (s_Styles == null) |
|||
s_Styles = new Styles(); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: fcb1bb4049093ff41855e3951f22e9cf |
|||
timeCreated: 1507119569 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using UnityEngine; |
|||
using UnityEngine.Experimental.Rendering; |
|||
using UnityEngine.Experimental.Rendering.HDPipeline; |
|||
|
|||
namespace UnityEditor.Experimental.Rendering.HDPipeline |
|||
{ |
|||
[CustomEditor(typeof(SubsurfaceScatteringProfile))] |
|||
public partial class SubsurfaceScatteringProfileEditor : Editor |
|||
{ |
|||
RenderTexture m_ProfileImage; |
|||
RenderTexture m_TransmittanceImage; |
|||
Material m_ProfileMaterial; |
|||
Material m_TransmittanceMaterial; |
|||
SerializedProperty m_ScatteringDistance; |
|||
SerializedProperty m_MaxRadius; |
|||
SerializedProperty m_ShapeParam; |
|||
SerializedProperty m_TransmissionTint; |
|||
SerializedProperty m_TexturingMode; |
|||
SerializedProperty m_TransmissionMode; |
|||
SerializedProperty m_ThicknessRemap; |
|||
SerializedProperty m_WorldScale; |
|||
|
|||
// Old SSS Model >>>
|
|||
SerializedProperty m_ScatterDistance1; |
|||
SerializedProperty m_ScatterDistance2; |
|||
SerializedProperty m_LerpWeight; |
|||
// <<< Old SSS Model
|
|||
|
|||
void OnEnable() |
|||
{ |
|||
using (var o = new PropertyFetcher<SubsurfaceScatteringProfile>(serializedObject)) |
|||
{ |
|||
m_ScatteringDistance = o.FindProperty(x => x.scatteringDistance); |
|||
m_MaxRadius = o.FindProperty("m_MaxRadius"); |
|||
m_ShapeParam = o.FindProperty("m_ShapeParam"); |
|||
m_TransmissionTint = o.FindProperty(x => x.transmissionTint); |
|||
m_TexturingMode = o.FindProperty(x => x.texturingMode); |
|||
m_TransmissionMode = o.FindProperty(x => x.transmissionMode); |
|||
m_ThicknessRemap = o.FindProperty(x => x.thicknessRemap); |
|||
m_WorldScale = o.FindProperty(x => x.worldScale); |
|||
// Old SSS Model >>>
|
|||
m_ScatterDistance1 = o.FindProperty(x => x.scatterDistance1); |
|||
m_ScatterDistance2 = o.FindProperty(x => x.scatterDistance2); |
|||
m_LerpWeight = o.FindProperty(x => x.lerpWeight); |
|||
// <<< Old SSS Model
|
|||
} |
|||
|
|||
// These shaders don't need to be reference by RenderPipelineResource as they are not use at runtime
|
|||
m_ProfileMaterial = CoreUtils.CreateEngineMaterial("Hidden/HDRenderPipeline/DrawSssProfile"); |
|||
m_TransmittanceMaterial = CoreUtils.CreateEngineMaterial("Hidden/HDRenderPipeline/DrawTransmittanceGraph"); |
|||
|
|||
m_ProfileImage = new RenderTexture(256, 256, 0, RenderTextureFormat.DefaultHDR); |
|||
m_TransmittanceImage = new RenderTexture( 16, 256, 0, RenderTextureFormat.DefaultHDR); |
|||
} |
|||
|
|||
void OnDisable() |
|||
{ |
|||
CoreUtils.Destroy(m_ProfileMaterial); |
|||
CoreUtils.Destroy(m_TransmittanceMaterial); |
|||
CoreUtils.Destroy(m_ProfileImage); |
|||
CoreUtils.Destroy(m_TransmittanceImage); |
|||
} |
|||
|
|||
public override void OnInspectorGUI() |
|||
{ |
|||
var hdPipeline = RenderPipelineManager.currentPipeline as HDRenderPipeline; |
|||
|
|||
if (hdPipeline == null) |
|||
return; |
|||
|
|||
serializedObject.Update(); |
|||
CheckStyles(); |
|||
|
|||
// Old SSS Model >>>
|
|||
bool useDisneySSS = hdPipeline.sssSettings.useDisneySSS; |
|||
// <<< Old SSS Model
|
|||
|
|||
using (var scope = new EditorGUI.ChangeCheckScope()) |
|||
{ |
|||
if (useDisneySSS) |
|||
{ |
|||
EditorGUILayout.PropertyField(m_ScatteringDistance, s_Styles.profileScatteringDistance); |
|||
|
|||
using (new EditorGUI.DisabledScope(true)) |
|||
EditorGUILayout.PropertyField(m_MaxRadius, s_Styles.profileMaxRadius); |
|||
} |
|||
else |
|||
{ |
|||
EditorGUILayout.PropertyField(m_ScatterDistance1, s_Styles.profileScatterDistance1); |
|||
EditorGUILayout.PropertyField(m_ScatterDistance2, s_Styles.profileScatterDistance2); |
|||
EditorGUILayout.PropertyField(m_LerpWeight, s_Styles.profileLerpWeight); |
|||
} |
|||
|
|||
m_TexturingMode.intValue = EditorGUILayout.Popup(s_Styles.texturingMode, m_TexturingMode.intValue, s_Styles.texturingModeOptions); |
|||
m_TransmissionMode.intValue = EditorGUILayout.Popup(s_Styles.profileTransmissionMode, m_TransmissionMode.intValue, s_Styles.transmissionModeOptions); |
|||
|
|||
EditorGUILayout.PropertyField(m_TransmissionTint, s_Styles.profileTransmissionTint); |
|||
EditorGUILayout.PropertyField(m_ThicknessRemap, s_Styles.profileMinMaxThickness); |
|||
Vector2 thicknessRemap = m_ThicknessRemap.vector2Value; |
|||
EditorGUILayout.MinMaxSlider(s_Styles.profileThicknessRemap, ref thicknessRemap.x, ref thicknessRemap.y, 0.0f, 50.0f); |
|||
m_ThicknessRemap.vector2Value = thicknessRemap; |
|||
EditorGUILayout.PropertyField(m_WorldScale, s_Styles.profileWorldScale); |
|||
|
|||
EditorGUILayout.Space(); |
|||
EditorGUILayout.LabelField(s_Styles.profilePreview0, s_Styles.centeredMiniBoldLabel); |
|||
EditorGUILayout.LabelField(s_Styles.profilePreview1, EditorStyles.centeredGreyMiniLabel); |
|||
EditorGUILayout.LabelField(s_Styles.profilePreview2, EditorStyles.centeredGreyMiniLabel); |
|||
EditorGUILayout.LabelField(s_Styles.profilePreview3, EditorStyles.centeredGreyMiniLabel); |
|||
EditorGUILayout.Space(); |
|||
|
|||
serializedObject.ApplyModifiedProperties(); |
|||
|
|||
if (scope.changed) |
|||
{ |
|||
// Validate each individual asset and update caches.
|
|||
((SubsurfaceScatteringProfile)target).Validate(); |
|||
} |
|||
} |
|||
|
|||
float r = m_MaxRadius.floatValue; |
|||
Vector3 S = m_ShapeParam.vector3Value; |
|||
Vector4 T = m_TransmissionTint.colorValue; |
|||
Vector2 R = m_ThicknessRemap.vector2Value; |
|||
bool transmissionEnabled = m_TransmissionMode.intValue != (int)SubsurfaceScatteringProfile.TransmissionMode.None; |
|||
|
|||
m_ProfileMaterial.SetFloat(HDShaderIDs._MaxRadius, r); |
|||
m_ProfileMaterial.SetVector(HDShaderIDs._ShapeParam, S); |
|||
|
|||
// Old SSS Model >>>
|
|||
CoreUtils.SelectKeyword(m_ProfileMaterial, "SSS_MODEL_DISNEY", "SSS_MODEL_BASIC", useDisneySSS); |
|||
|
|||
// Apply the three-sigma rule, and rescale.
|
|||
float s = (1.0f / 3.0f) * SssConstants.SSS_BASIC_DISTANCE_SCALE; |
|||
float rMax = Mathf.Max(m_ScatterDistance1.colorValue.r, m_ScatterDistance1.colorValue.g, m_ScatterDistance1.colorValue.b, |
|||
m_ScatterDistance2.colorValue.r, m_ScatterDistance2.colorValue.g, m_ScatterDistance2.colorValue.b); |
|||
Vector4 stdDev1 = s * m_ScatterDistance1.colorValue; |
|||
Vector4 stdDev2 = s * m_ScatterDistance2.colorValue; |
|||
m_ProfileMaterial.SetVector(HDShaderIDs._StdDev1, stdDev1); |
|||
m_ProfileMaterial.SetVector(HDShaderIDs._StdDev2, stdDev2); |
|||
m_ProfileMaterial.SetFloat(HDShaderIDs._LerpWeight, m_LerpWeight.floatValue); |
|||
m_ProfileMaterial.SetFloat(HDShaderIDs._MaxRadius, rMax); |
|||
// <<< Old SSS Model
|
|||
|
|||
// Draw the profile.
|
|||
EditorGUI.DrawPreviewTexture(GUILayoutUtility.GetRect(256, 256), m_ProfileImage, m_ProfileMaterial, ScaleMode.ScaleToFit, 1.0f); |
|||
|
|||
EditorGUILayout.Space(); |
|||
EditorGUILayout.LabelField(s_Styles.transmittancePreview0, s_Styles.centeredMiniBoldLabel); |
|||
EditorGUILayout.LabelField(s_Styles.transmittancePreview1, EditorStyles.centeredGreyMiniLabel); |
|||
EditorGUILayout.LabelField(s_Styles.transmittancePreview2, EditorStyles.centeredGreyMiniLabel); |
|||
EditorGUILayout.Space(); |
|||
|
|||
// Old SSS Model >>>
|
|||
// Multiply by 0.1 to convert from millimeters to centimeters. Apply the distance scale.
|
|||
float a = 0.1f * SssConstants.SSS_BASIC_DISTANCE_SCALE; |
|||
Vector4 halfRcpVarianceAndWeight1 = new Vector4(a * a * 0.5f / (stdDev1.x * stdDev1.x), a * a * 0.5f / (stdDev1.y * stdDev1.y), a * a * 0.5f / (stdDev1.z * stdDev1.z), 4 * (1.0f - m_LerpWeight.floatValue)); |
|||
Vector4 halfRcpVarianceAndWeight2 = new Vector4(a * a * 0.5f / (stdDev2.x * stdDev2.x), a * a * 0.5f / (stdDev2.y * stdDev2.y), a * a * 0.5f / (stdDev2.z * stdDev2.z), 4 * m_LerpWeight.floatValue); |
|||
m_TransmittanceMaterial.SetVector(HDShaderIDs._HalfRcpVarianceAndWeight1, halfRcpVarianceAndWeight1); |
|||
m_TransmittanceMaterial.SetVector(HDShaderIDs._HalfRcpVarianceAndWeight2, halfRcpVarianceAndWeight2); |
|||
// <<< Old SSS Model
|
|||
|
|||
m_TransmittanceMaterial.SetVector(HDShaderIDs._ShapeParam, S); |
|||
m_TransmittanceMaterial.SetVector(HDShaderIDs._TransmissionTint, transmissionEnabled ? T : Vector4.zero); |
|||
m_TransmittanceMaterial.SetVector(HDShaderIDs._ThicknessRemap, R); |
|||
|
|||
// Draw the transmittance graph.
|
|||
EditorGUI.DrawPreviewTexture(GUILayoutUtility.GetRect(16, 16), m_TransmittanceImage, m_TransmittanceMaterial, ScaleMode.ScaleToFit, 16.0f); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 4e87e719e85a91846ad1d5aa15793685 |
|||
timeCreated: 1507118957 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue