浏览代码

Improve the SSS profile GUI

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

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


using System;
using UnityEngine.Rendering;
#if UNITY_EDITOR
using UnityEditor;
#endif

public SubsurfaceScatteringProfile()
{
stdDev1 = new Color(0.3f, 0.3f, 0.3f, 0.0f);
stdDev2 = new Color(1.0f, 1.0f, 1.0f, 0.0f);
stdDev2 = new Color(0.6f, 0.6f, 0.6f, 0.0f);
lerpWeight = 0.5f;
enableTransmittance = false;
thicknessScale = 3.0f;

get { return m_FilterKernels; }
}
// --- Private Methods ---
void OnValidate()
public void OnValidate()
{
if (m_Profiles.Length > maxNumProfiles)
{

public readonly GUIContent profileThicknessScale = new GUIContent("Thickness scale", "Linearly scales the object thickness which affects the amount of transmitted lighting.");
}
private static Styles s_Styles;
private static Styles s_Styles;
private Material m_ProfileMaterial;
private RenderTexture[] m_ProfileImages;
// --- Public Methods ---

void OnEnable()
{
m_Profiles = serializedObject.FindProperty("m_Profiles");
m_NumProfiles = m_Profiles.FindPropertyRelative("Array.size");
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];
for (int i = 0; i < SubsurfaceScatteringParameters.maxNumProfiles; i++)
{
m_ProfileImages[i] = new RenderTexture(256, 256, 0, RenderTextureFormat.DefaultHDR);
}
}
public override void OnInspectorGUI()

EditorGUI.BeginChangeCheck();
// Validate the data before displaying it.
((SubsurfaceScatteringParameters)serializedObject.targetObject).OnValidate();
EditorGUILayout.LabelField(styles.category);
EditorGUILayout.PropertyField(m_NumProfiles, styles.numProfiles);

EditorGUILayout.PropertyField(profileLerpWeight, styles.profileLerpWeight);
EditorGUILayout.PropertyField(profileTransmittance, styles.profileTransmittance);
EditorGUILayout.PropertyField(profileThicknessScale, styles.profileThicknessScale);
EditorGUILayout.Space();
using (new EditorGUILayout.HorizontalScope())
{
// Draw the profile.
m_ProfileMaterial.SetColor("_StdDev1", profileStdDev1.colorValue);
m_ProfileMaterial.SetColor("_StdDev2", profileStdDev2.colorValue);
m_ProfileMaterial.SetFloat("_LerpWeight", profileLerpWeight.floatValue);
Graphics.Blit(null, m_ProfileImages[i], m_ProfileMaterial);
// Reset the active RT.
RenderTexture.active = null;
GUILayout.FlexibleSpace();
Rect r = GUILayoutUtility.GetRect(256, 256);
GUILayout.FlexibleSpace();
EditorGUI.DrawPreviewTexture(r, m_ProfileImages[i]);
}
EditorGUILayout.Space();
EditorGUI.indentLevel--;
}

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


Shader "Hidden/HDRenderPipeline/DrawGaussianProfile"
{
Properties
{
[HideInInspector] _StdDev1("", Color) = (0, 0, 0)
[HideInInspector] _StdDev2("", Color) = (0, 0, 0)
[HideInInspector] _LerpWeight("", 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; // 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 dist = length(2 * input.texcoord - 1);
float3 var1 = _StdDev1.rgb * _StdDev1.rgb;
float3 var2 = _StdDev2.rgb * _StdDev2.rgb;
// Evaluate the linear combination of two 2D Gaussians instead of
// product of a linear combination of two normalized 1D Gaussians
// since we do not want to bother artists with the lack of radial symmetry.
float3 magnitude = lerp(exp(-dist * dist / (2 * var1)) / (TWO_PI * var1),
exp(-dist * dist / (2 * var2)) / (TWO_PI * var2), _LerpWeight);
return float4(magnitude, 1);
}
ENDHLSL
}
}
Fallback Off
}

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


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