浏览代码

Add transmittance preview

/Branch_Batching2
Evgenii Golubev 7 年前
当前提交
e2501e62
共有 4 个文件被更改,包括 133 次插入12 次删除
  1. 2
      Assets/ScriptableRenderPipeline/HDRenderPipeline/SceneSettings/Resources/DrawGaussianProfile.shader
  2. 50
      Assets/ScriptableRenderPipeline/HDRenderPipeline/SceneSettings/SubsurfaceScatteringParameters.cs
  3. 84
      Assets/ScriptableRenderPipeline/HDRenderPipeline/SceneSettings/Resources/DrawTransmittanceGraph.shader
  4. 9
      Assets/ScriptableRenderPipeline/HDRenderPipeline/SceneSettings/Resources/DrawTransmittanceGraph.shader.meta

2
Assets/ScriptableRenderPipeline/HDRenderPipeline/SceneSettings/Resources/DrawGaussianProfile.shader


Varyings Vert(Attributes input)
{
Varyings output;
output.vertex = TransformWorldToHClip(input.vertex);
output.vertex = TransformWorldToHClip(input.vertex);
output.texcoord = input.texcoord.xy;
return output;
}

50
Assets/ScriptableRenderPipeline/HDRenderPipeline/SceneSettings/SubsurfaceScatteringParameters.cs


{
public readonly GUIContent category = new GUIContent("Subsurface scattering parameters");
public readonly GUIContent[] profiles = new GUIContent[SubsurfaceScatteringParameters.maxNumProfiles] { new GUIContent("Profile #0"), new GUIContent("Profile #1"), new GUIContent("Profile #2"), new GUIContent("Profile #3"), new GUIContent("Profile #4"), new GUIContent("Profile #5"), new GUIContent("Profile #6"), new GUIContent("Profile #7") };
public readonly GUIContent profilePreview = new GUIContent("Profile preview. Note that the intensity of the region in the center may be clamped.");
public readonly GUIContent profilePreview0 = new GUIContent("Profile preview");
public readonly GUIContent profilePreview1 = new GUIContent("Shows the fraction of light scattered from the source as radius increases to 1.");
public readonly GUIContent profilePreview2 = new GUIContent("Note that the intensity of the region in the center may be clamped.");
public readonly GUIContent transmittancePreview0 = new GUIContent("Transmittance preview");
public readonly GUIContent transmittancePreview1 = new GUIContent("Shows the fraction of light passing through the object as thickness increases to 1.");
public readonly GUIContent numProfiles = new GUIContent("Number of profiles");
public readonly GUIContent profileStdDev1 = new GUIContent("Standard deviation #1", "Determines the shape of the 1st Gaussian filter. Increases the strength and the radius of the blur of the corresponding color channel.");
public readonly GUIContent profileStdDev2 = new GUIContent("Standard deviation #2", "Determines the shape of the 2nd Gaussian filter. Increases the strength and the radius of the blur of the corresponding color channel.");

public readonly GUIStyle centeredMiniBoldLabel = new GUIStyle (GUI.skin.label);
private Material m_ProfileMaterial;
private RenderTexture[] m_ProfileImages;
private Material m_ProfileMaterial, m_TransmittanceMaterial;
private RenderTexture[] m_ProfileImages, m_TransmittanceImages;
// --- Public Methods ---

{
s_Styles = new Styles();
}
s_Styles.centeredMiniBoldLabel.alignment = TextAnchor.MiddleCenter;
s_Styles.centeredMiniBoldLabel.fontSize = 10;
s_Styles.centeredMiniBoldLabel.fontStyle = FontStyle.Bold;
return s_Styles;
}
}

m_EnableSSS = serializedObject.FindProperty("m_EnableSSS");
m_Profiles = serializedObject.FindProperty("m_Profiles");
m_NumProfiles = m_Profiles.FindPropertyRelative("Array.size");
m_ProfileMaterial = Utilities.CreateEngineMaterial("Hidden/HDRenderPipeline/DrawGaussianProfile");
m_ProfileImages = new RenderTexture[SubsurfaceScatteringParameters.maxNumProfiles];
m_EnableSSS = serializedObject.FindProperty("m_EnableSSS");
m_Profiles = serializedObject.FindProperty("m_Profiles");
m_NumProfiles = m_Profiles.FindPropertyRelative("Array.size");
m_ProfileMaterial = Utilities.CreateEngineMaterial("Hidden/HDRenderPipeline/DrawGaussianProfile");
m_TransmittanceMaterial = Utilities.CreateEngineMaterial("Hidden/HDRenderPipeline/DrawTransmittanceGraph");
m_ProfileImages = new RenderTexture[SubsurfaceScatteringParameters.maxNumProfiles];
m_TransmittanceImages = new RenderTexture[SubsurfaceScatteringParameters.maxNumProfiles];
m_ProfileImages[i] = new RenderTexture(256, 256, 0, RenderTextureFormat.DefaultHDR);
m_ProfileImages[i] = new RenderTexture(256, 256, 0, RenderTextureFormat.DefaultHDR);
m_TransmittanceImages[i] = new RenderTexture(16, 256, 0, RenderTextureFormat.DefaultHDR);
}
}

EditorGUILayout.PropertyField(profileThicknessScale, styles.profileThicknessScale);
EditorGUILayout.Space();
EditorGUILayout.LabelField(styles.profilePreview0, styles.centeredMiniBoldLabel);
EditorGUILayout.LabelField(styles.profilePreview1, EditorStyles.centeredGreyMiniLabel);
EditorGUILayout.LabelField(styles.profilePreview2, EditorStyles.centeredGreyMiniLabel);
EditorGUILayout.Space();
EditorGUI.DrawPreviewTexture(GUILayoutUtility.GetRect(256, 256), m_ProfileImages[i], m_ProfileMaterial, ScaleMode.ScaleToFit);
EditorGUI.DrawPreviewTexture(GUILayoutUtility.GetRect(256, 256), m_ProfileImages[i], m_ProfileMaterial, ScaleMode.ScaleToFit, 1.0f);
EditorGUILayout.LabelField(styles.profilePreview, EditorStyles.centeredGreyMiniLabel);
EditorGUILayout.LabelField(styles.transmittancePreview0, styles.centeredMiniBoldLabel);
EditorGUILayout.LabelField(styles.transmittancePreview1, EditorStyles.centeredGreyMiniLabel);
EditorGUILayout.Space();
// Draw the transmittance graph.
m_TransmittanceMaterial.SetColor("_StdDev1", profileStdDev1.colorValue);
m_TransmittanceMaterial.SetColor("_StdDev2", profileStdDev2.colorValue);
m_TransmittanceMaterial.SetFloat("_LerpWeight", profileLerpWeight.floatValue);
m_TransmittanceMaterial.SetFloat("_ThicknessScale", profileThicknessScale.floatValue);
EditorGUI.DrawPreviewTexture(GUILayoutUtility.GetRect(16, 16), m_TransmittanceImages[i], m_TransmittanceMaterial, ScaleMode.ScaleToFit, 16.0f);
EditorGUILayout.Space();
EditorGUI.indentLevel--;

84
Assets/ScriptableRenderPipeline/HDRenderPipeline/SceneSettings/Resources/DrawTransmittanceGraph.shader


Shader "Hidden/HDRenderPipeline/DrawTransmittanceGraph"
{
Properties
{
[HideInInspector] _StdDev1("", Color) = (0, 0, 0)
[HideInInspector] _StdDev2("", Color) = (0, 0, 0)
[HideInInspector] _LerpWeight("", Float) = 0
[HideInInspector] _ThicknessScale("", Float) = 0
}
SubShader
{
Pass
{
Cull Off
ZTest Off
ZWrite Off
Blend Off
HLSLPROGRAM
#pragma target 4.5
#pragma only_renderers d3d11 ps4 metal // TEMP: until we go further in dev
#pragma vertex Vert
#pragma fragment Frag
//-------------------------------------------------------------------------------------
// Include
//-------------------------------------------------------------------------------------
#include "ShaderLibrary/Common.hlsl"
#include "ShaderLibrary/Color.hlsl"
#include "HDRenderPipeline/ShaderVariables.hlsl"
//-------------------------------------------------------------------------------------
// Inputs & outputs
//-------------------------------------------------------------------------------------
float4 _StdDev1, _StdDev2;
float _LerpWeight, _ThicknessScale; // See 'SubsurfaceScatteringParameters'
//-------------------------------------------------------------------------------------
// Implementation
//-------------------------------------------------------------------------------------
struct Attributes
{
float3 vertex : POSITION;
float2 texcoord : TEXCOORD0;
};
struct Varyings
{
float4 vertex : SV_POSITION;
float2 texcoord : TEXCOORD0;
};
Varyings Vert(Attributes input)
{
Varyings output;
output.vertex = TransformWorldToHClip(input.vertex);
output.texcoord = input.texcoord.xy;
return output;
}
float4 Frag(Varyings input) : SV_Target
{
float thickness = input.texcoord.x * _ThicknessScale;
float t2 = thickness * thickness;
float3 var1 = _StdDev1.rgb * _StdDev1.rgb;
float3 var2 = _StdDev2.rgb * _StdDev2.rgb;
// See ComputeTransmittance() in Lit.hlsl for more details.
float3 transmittance = lerp(exp(-t2 * 0.5 * rcp(var1)),
exp(-t2 * 0.5 * rcp(var2)), _LerpWeight);
return float4(transmittance, 1);
}
ENDHLSL
}
}
Fallback Off
}

9
Assets/ScriptableRenderPipeline/HDRenderPipeline/SceneSettings/Resources/DrawTransmittanceGraph.shader.meta


fileFormatVersion: 2
guid: 4517edda0467bb14489d5eccc9973ba2
timeCreated: 1487326565
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存