浏览代码

Merge branch 'master' into DebugShader

# Conflicts:
#	Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.cs
/main
Julien Ignace 8 年前
当前提交
c90ffdda
共有 10 个文件被更改,包括 151 次插入20 次删除
  1. 2
      Assets/ScriptableRenderLoop/ForwardRenderLoop/ForwardRenderLoop.cs
  2. 2
      Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.asset
  3. 25
      Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.cs
  4. 84
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/PostProcess/FinalPass.shader
  5. 15
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/TemplateDisneyGGX.hlsl
  6. 1
      Assets/ScriptableRenderLoop/ScriptableRenderLoop.cs
  7. 32
      Assets/ScriptableRenderLoop/ScriptableRenderLoopPicker.cs
  8. 6
      Assets/ScriptableRenderLoop/fptl/FptlLighting.cs
  9. 2
      Assets/TestScenes/HDTest/HDRenderLoopTest.unity
  10. 2
      Assets/TestScenes/HDTest/Material/HDRenderLoopMaterials/test-alpha.mat

2
Assets/ScriptableRenderLoop/ForwardRenderLoop/ForwardRenderLoop.cs


Rebuild ();
}
void Rebuild()
public override void Rebuild()
{
m_ShadowPass = new ShadowRenderPass (m_ShadowSettings);
}

2
Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.asset


m_Script: {fileID: 11500000, guid: 558064ecdbf6b6742892d699acb39aed, type: 3}
m_Name: HDRenderLoop
m_EditorClassIdentifier:
enableTonemap: 0
exposure: 0

25
Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.cs


public const int MaxLights = 32;
public bool enableTonemap = true;
public float exposure = 0;
//[SerializeField]
//ShadowSettings m_ShadowSettings = ShadowSettings.Default;
//ShadowRenderPass m_ShadowPass;

return mat;
}
void Rebuild()
public override void Rebuild()
{
ClearComputeBuffers();

void FinalPass(RenderLoop renderLoop)
{
// Those could be tweakable for the neutral tonemapper, but in the case of the LookDev we don't need that
const float BlackIn = 0.02f;
const float WhiteIn = 10.0f;
const float BlackOut = 0.0f;
const float WhiteOut = 10.0f;
const float WhiteLevel = 5.3f;
const float WhiteClip = 10.0f;
const float DialUnits = 20.0f;
const float HalfDialUnits = DialUnits * 0.5f;
// converting from artist dial units to easy shader-lerps (0-1)
Vector4 tonemapCoeff1 = new Vector4((BlackIn * DialUnits) + 1.0f, (BlackOut * HalfDialUnits) + 1.0f, (WhiteIn / DialUnits), (1.0f - (WhiteOut / DialUnits)));
Vector4 tonemapCoeff2 = new Vector4(0.0f, 0.0f, WhiteLevel, WhiteClip / HalfDialUnits);
m_FinalPassMaterial.SetVector("_ToneMapCoeffs1", tonemapCoeff1);
m_FinalPassMaterial.SetVector("_ToneMapCoeffs2", tonemapCoeff2);
m_FinalPassMaterial.SetFloat("_EnableToneMap", enableTonemap ? 1.0f : 0.0f);
m_FinalPassMaterial.SetFloat("_Exposure", exposure);
CommandBuffer cmd = new CommandBuffer();
cmd.name = "FinalPass";
// Resolve our HDR texture to CameraTarget.

84
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/PostProcess/FinalPass.shader


// Final compositing pass, just does gamma correction for now.
Shader "Hidden/Unity/FinalPass"
{
Properties { _MainTex ("Texture", any) = "" {} }
Properties
{
_MainTex ("Texture", any) = "" {}
_ToneMapCoeffs1("Parameters for neutral tonemap", Vector) = (0.0, 0.0, 0.0, 0.0)
_ToneMapCoeffs2("Parameters for neutral tonemap", Vector) = (0.0, 0.0, 0.0, 0.0)
_Exposure("Exposure", Range(-32.0, 32.0)) = 0
}
SubShader {
Pass {
ZTest Always Cull Off ZWrite Off

#include "../ShaderVariables.hlsl"
sampler2D _MainTex;
float4 _ToneMapCoeffs1;
float4 _ToneMapCoeffs2;
#define InBlack _ToneMapCoeffs1.x
#define OutBlack _ToneMapCoeffs1.y
#define InWhite _ToneMapCoeffs1.z
#define OutWhite _ToneMapCoeffs1.w
#define WhiteLevel _ToneMapCoeffs2.z
#define WhiteClip _ToneMapCoeffs2.w
float _Exposure;
float _EnableToneMap;
struct Attributes {
float3 vertex : POSITION;

return output;
}
float3 evalCurve(float3 x, float A, float B, float C, float D, float E, float F)
{
return ((x*(A*x + C*B) + D*E) / (x*(A*x + B) + D*F)) - E / F;
}
float3 applyTonemapFilmicAD(float3 linearColor)
{
float blackRatio = InBlack / OutBlack;
float whiteRatio = InWhite / OutWhite;
// blend tunable coefficients
float B = lerp(0.57, 0.37, blackRatio);
float C = lerp(0.01, 0.24, whiteRatio);
float D = lerp(0.02, 0.20, blackRatio);
// constants
float A = 0.2;
float E = 0.02;
float F = 0.30;
// eval and correct for white point
float3 whiteScale = 1.0f / evalCurve(WhiteLevel, A, B, C, D, E, F);
float3 curr = evalCurve(linearColor * whiteScale, A, B, C, D, E, F);
return curr * whiteScale;
}
float3 remapWhite(float3 inPixel, float whitePt)
{
// var breakout for readability
const float inBlack = 0;
const float outBlack = 0;
float inWhite = whitePt;
const float outWhite = 1;
// remap input range to output range
float3 outPixel = ((inPixel.rgb) - inBlack.xxx) / (inWhite.xxx - inBlack.xxx) * (outWhite.xxx - outBlack.xxx) + outBlack.xxx;
return (outPixel.rgb);
}
float3 NeutralTonemap(float3 x)
{
float3 finalColor = applyTonemapFilmicAD(x); // curve (dynamic coeffs differ per level)
finalColor = remapWhite(finalColor, WhiteClip); // post-curve white point adjustment
finalColor = saturate(finalColor);
return finalColor;
}
float3 ApplyToneMap(float3 color)
{
if (_EnableToneMap > 0.0)
{
return NeutralTonemap(color);
}
else
{
return saturate(color);
}
}
float4 Frag(Varyings input) : SV_Target
{
float4 c = tex2D(_MainTex, input.texcoord);

// So we must not correct the sRGB here else it will be done two time.
// To fix!
c.rgb = ApplyToneMap(c.rgb * pow(2.0, _Exposure));
// return LinearToSRGB(c);
return c;

15
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/TemplateDisneyGGX.hlsl


// float _CoatRoughness;
// sampler2D _CoatRoughnessMap;
float _Cutoff;
float _AlphaCutoff;
//-------------------------------------------------------------------------------------
// Lighting architecture

output.tangentToWorld[1].w = 0;
output.tangentToWorld[2].w = 0;
#ifdef SHADER_STAGE_FRAGMENT
#if defined(_DOUBLESIDED_LIGHTING_FLIP) || defined(_DOUBLESIDED_LIGHTING_MIRROR)
output.cullFace = FRONT_FACE_TYPE(0); // To avoid a warning
#endif
#endif
return PackVaryings(output);
}

#endif
#ifdef _ALPHATEST_ON
clip(alpha - _Cutoff);
clip(alpha - _AlphaCutoff);
#endif
builtinData.opacity = alpha;

#else
// Mirror the normal with the plane define by vertex normal
float3 oppositeNormalWS = reflect(surfaceData.normalWS, vertexNormalWS);
#endif
#endif
// surfaceData.normalWS = IS_FRONT_VFACE((input.cullFace >= 0.0 ? GetOdddNegativeScale() : -GetOdddNegativeScale()) >= 0.0, surfaceData.normalWS, oppositeNormalWS);
surfaceData.normalWS = IS_FRONT_VFACE((input.cullFace >= 0.0 ? GetOdddNegativeScale() : -GetOdddNegativeScale()) >= 0.0, surfaceData.normalWS, oppositeNormalWS);
surfaceData.normalWS = IS_FRONT_VFACE(input.cullFace, GetOdddNegativeScale() >= 0.0 ? surfaceData.normalWS : oppositeNormalWS, -GetOdddNegativeScale() >= 0.0 ? surfaceData.normalWS : oppositeNormalWS);
#endif
surfaceData.materialId = 0;

1
Assets/ScriptableRenderLoop/ScriptableRenderLoop.cs


public abstract class ScriptableRenderLoop : ScriptableObject
{
public abstract void Render(Camera[] cameras, RenderLoop renderLoop);
public virtual void Rebuild() { }
#if UNITY_EDITOR
public virtual UnityEditor.SupportedRenderingFeatures GetSupportedRenderingFeatures() { return new UnityEditor.SupportedRenderingFeatures(); }

32
Assets/ScriptableRenderLoop/ScriptableRenderLoopPicker.cs


if (m_RenderLoop == null)
return false;
#if UNITY_EDITOR
if (m_AssetVersion != ms_GlobalAssetVersion)
{
m_AssetVersion = ms_GlobalAssetVersion;
m_RenderLoop.Rebuild();
}
#endif
}
}
#if UNITY_EDITOR
// Temporary hack to allow compute shader reloading
internal class AssetReloader : UnityEditor.AssetPostprocessor
{
static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
{
foreach (string str in importedAssets)
{
if (str.EndsWith(".compute"))
{
ms_GlobalAssetVersion++;
break;
}
}
}
}
public static int ms_GlobalAssetVersion = 0;
public int m_AssetVersion = 0;
#endif
}
}

6
Assets/ScriptableRenderLoop/fptl/FptlLighting.cs


}
void Rebuild()
public override void Rebuild()
{
ClearComputeBuffers();

m_blitMaterial = new Material(m_FinalPassShader);
m_blitMaterial.hideFlags = HideFlags.HideAndDontSave;
lightList = null;
}
void OnDisable()

void ResizeIfNecessary(int curWidth, int curHeight)
{
if(curWidth!=m_WidthOnRecord || curHeight!=m_HeightOnRecord)
if(curWidth!=m_WidthOnRecord || curHeight!=m_HeightOnRecord || lightList == null)
{
if(m_WidthOnRecord>0 && m_HeightOnRecord>0)
ReleaseResolutionDependentBuffers();

2
Assets/TestScenes/HDTest/HDRenderLoopTest.unity


m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1614424510}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 2.58852, y: 1.27, z: -0.944}
m_LocalPosition: {x: 2.159, y: 1.27, z: -3.323}
m_LocalScale: {x: 0.2, y: 0.2, z: 0.2}
m_Children: []
m_Father: {fileID: 0}

2
Assets/TestScenes/HDTest/Material/HDRenderLoopMaterials/test-alpha.mat


m_Floats:
- first:
name: _AlphaCutoff
second: 0.309
second: 0.166
- first:
name: _AlphaCutoffEnable
second: 1

正在加载...
取消
保存