浏览代码

Merge pull request #555 from Unity-Technologies/Unity-2017.3

Unity 2017.3
/main
GitHub 7 年前
当前提交
1886d3d6
共有 13 个文件被更改,包括 19 次插入72 次删除
  1. 2
      ScriptableRenderPipeline/Core/ShaderLibrary/VolumeRendering.hlsl
  2. 7
      ScriptableRenderPipeline/Core/Shadow/Shadow.cs
  3. 12
      ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs
  4. 3
      ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/TilePass.cs
  5. 2
      ScriptableRenderPipeline/HDRenderPipeline/Material/LayeredLit/LayeredLit.shader
  6. 2
      ScriptableRenderPipeline/HDRenderPipeline/Material/LayeredLit/LayeredLitTessellation.shader
  7. 25
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.hlsl
  8. 2
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.shader
  9. 2
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/LitTessellation.shader
  10. 14
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Resources/SubsurfaceScattering.compute
  11. 10
      ScriptableRenderPipeline/HDRenderPipeline/ShaderVariables.hlsl
  12. 10
      ScriptableRenderPipeline/HDRenderPipeline/Lighting/Volumetrics.meta

2
ScriptableRenderPipeline/Core/ShaderLibrary/VolumeRendering.hlsl


}
// Absorption coefficient from Disney: http://blog.selfshadow.com/publications/s2015-shading-course/burley/s2015_pbs_disney_bsdf_notes.pdf
float TransmittanceColorAtDistanceToAbsorption(float3 transmittanceColor, float atDistance)
float3 TransmittanceColorAtDistanceToAbsorption(float3 transmittanceColor, float atDistance)
{
return -log(transmittanceColor + 0.00001) / max(atDistance, 0.000001);
}

7
ScriptableRenderPipeline/Core/Shadow/Shadow.cs


{
public const uint k_MaxCascadesInShader = 4;
protected readonly int m_TempDepthId;
protected readonly int m_ZClipId;
protected RenderTexture m_Shadowmap;
protected RenderTargetIdentifier m_ShadowmapId;
protected VectorArray<CachedEntry> m_EntryCache = new VectorArray<CachedEntry>( 0, true );

public Key key;
public Data current;
public Data previous;
public bool zclip;
public int CompareTo( CachedEntry other )
{

public ShadowAtlas( ref AtlasInit init ) : base( ref init.baseInit )
{
m_ZClipId = Shader.PropertyToID( "_ZClip" );
if( !IsNativeDepth() )
{
m_TempDepthId = Shader.PropertyToID( "Temporary Shadowmap Depth" );

// read
float texelSizeX = 1.0f, texelSizeY = 1.0f;
CachedEntry ce = m_EntryCache[ceIdx];
ce.zclip = sr.shadowType != GPUShadowType.Directional;
// modify
Matrix4x4 vp, invvp;
if( sr.shadowType == GPUShadowType.Point )

cmd.SetViewport( m_EntryCache[i].current.viewport );
cmd.SetViewProjectionMatrices( m_EntryCache[i].current.view, m_EntryCache[i].current.proj );
cmd.SetGlobalVector( "g_vLightDirWs", m_EntryCache[i].current.lightDir );
cmd.SetGlobalFloat( m_ZClipId, m_EntryCache[i].zclip ? 1.0f : 0.0f );
//cmd.EndSample(cbName);
dss.lightIndex = m_EntryCache[i].key.visibleIdx;

cmd.EndSample("Shadowmap.DisableShaderKeyword");
}
cmd.SetGlobalFloat( m_ZClipId, 1.0f ); // Re-enable zclip globally
m_ActiveEntriesCount = 0;
profilingSample.Dispose();

12
ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs


m_LightLoop.AllocResolutionDependentBuffers(camera.pixelWidth, camera.pixelHeight);
}
if (resolutionChanged && m_VolumetricLightingEnabled)
CreateVolumetricLightingBuffers(camera.pixelWidth, camera.pixelHeight);
// update recorded window resolution
m_CurrentWidth = camera.pixelWidth;
m_CurrentHeight = camera.pixelHeight;

cmd.SetGlobalVectorArray(HDShaderIDs._ShapeParams, sssParameters.shapeParams);
cmd.SetGlobalVectorArray(HDShaderIDs._HalfRcpVariancesAndWeights, sssParameters.halfRcpVariancesAndWeights);
cmd.SetGlobalVectorArray(HDShaderIDs._TransmissionTints, sssParameters.transmissionTints);
SetGlobalVolumeProperties(m_VolumetricLightingEnabled, cmd);
}
}

RenderForward(m_CullResults, camera, renderContext, cmd, ForwardPass.Transparent);
RenderForwardError(m_CullResults, camera, renderContext, cmd, ForwardPass.Transparent);
// Render volumetric lighting
VolumetricLightingPass(hdCamera, cmd);
PushFullScreenDebugTexture(cmd, m_CameraColorBuffer, camera, renderContext, FullScreenDebugMode.NanTracker);
// Planar and real time cubemap doesn't need post process and render in FP16

var depthTexture = GetDepthTexture();
var options = new LightLoop.LightingPassOptions();
options.volumetricLightingEnabled = m_VolumetricLightingEnabled;
if (m_CurrentDebugDisplaySettings.renderingDebugSettings.enableSSSAndTransmission)
{

CoreUtils.SetRenderTarget(cmd, m_HTileRT, ClearFlag.Color, Color.black);
}
}
if (m_VolumetricLightingEnabled)
ClearVolumetricLightingBuffers(cmd, camera.isFirstFrame);
// TEMP: As we are in development and have not all the setup pass we still clear the color in emissive buffer and gbuffer, but this will be removed later.

3
ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/TilePass.cs


public struct LightingPassOptions
{
public bool outputSplitLighting;
public bool volumetricLightingEnabled;
}
public void RenderDeferredDirectionalShadow(HDCamera hdCamera, RenderTargetIdentifier deferredShadowRT, RenderTargetIdentifier depthTexture, CommandBuffer cmd)

cmd.SetComputeTextureParam(deferredComputeShader, kernel, HDShaderIDs.specularLightingUAV, colorBuffers[0]);
cmd.SetComputeTextureParam(deferredComputeShader, kernel, HDShaderIDs.diffuseLightingUAV, colorBuffers[1]);
HDRenderPipeline.SetGlobalVolumeProperties(options.volumetricLightingEnabled, cmd, deferredComputeShader);
// always do deferred lighting in blocks of 16x16 (not same as tiled light size)

2
ScriptableRenderPipeline/HDRenderPipeline/Material/LayeredLit/LayeredLit.shader


Cull[_CullMode]
ZClip Off
ZClip [_ZClip]
ZWrite On
ZTest LEqual

2
ScriptableRenderPipeline/HDRenderPipeline/Material/LayeredLit/LayeredLitTessellation.shader


Cull[_CullMode]
ZClip Off
ZClip [_ZClip]
ZWrite On
ZTest LEqual

25
ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.hlsl


#include "Lit.cs.hlsl"
#include "SubsurfaceScatteringSettings.cs.hlsl"
// Enables attenuation of light source contributions by participating media (fog).
#define VOLUMETRIC_SHADOWING_ENABLED
#ifdef VOLUMETRIC_SHADOWING_ENABLED
// Apparently, not all shaders include "ShaderVariables.hlsl".
#include "../../ShaderVariables.hlsl"
#include "../../../Core/ShaderLibrary/VolumeRendering.hlsl"
#endif
// Define refraction keyword helpers
#define HAS_REFRACTION (defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE))
#if HAS_REFRACTION

float3 transmissionPositionWS; // start of the refracted ray after exiting the shape
float3 transmissionTransmittance; // transmittance due to absorption
float transmissionSSMipLevel; // mip level of the screen space gaussian pyramid for rough refraction
#ifdef VOLUMETRIC_SHADOWING_ENABLED
float globalFogExtinction;
#endif
};
// This is a refract - TODO: do we call original refract or this one, original maybe slightly more expensive, to check

{
preLightData.ltcMagnitudeFresnel = bsdfData.fresnel0 * ltcGGXFresnelMagnitudeDiff + (float3)ltcGGXFresnelMagnitude;
}
#ifdef VOLUMETRIC_SHADOWING_ENABLED
preLightData.globalFogExtinction = _GlobalFog_Extinction;
#endif
#ifdef REFRACTION_MODEL
RefractionModelResult refraction = REFRACTION_MODEL(V, posInput, bsdfData);

shadow = lerp(1.0, shadow, lightData.shadowDimmer);
illuminance *= shadow;
}
#ifdef VOLUMETRIC_SHADOWING_ENABLED
float volumetricShadow = Transmittance(OpticalDepthHomogeneous(preLightData.globalFogExtinction, dist));
// Premultiply.
lightData.diffuseScale *= volumetricShadow;
lightData.specularScale *= volumetricShadow;
#endif
// Projector lights always have a cookies, so we can perform clipping inside the if().
[branch] if (lightData.cookieIndex >= 0)

2
ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.shader


Cull[_CullMode]
ZClip Off
ZClip [_ZClip]
ZWrite On
ZTest LEqual

2
ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/LitTessellation.shader


Cull[_CullMode]
ZClip Off
ZClip [_ZClip]
ZWrite On
ZTest LEqual

14
ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Resources/SubsurfaceScattering.compute


}
}
void WriteResult(uint2 pixelCoord, float3 irradiance)
void StoreResult(uint2 pixelCoord, float3 irradiance)
{
#ifdef USE_INTERMEDIATE_BUFFER
_CameraFilteringTexture[pixelCoord] = float4(irradiance, 1);

[branch] if (distScale == 0 || maxDistInPixels < 1)
{
#if SSS_DEBUG_LOD
WriteResult(pixelCoord, float3(0, 0, 1));
StoreResult(pixelCoord, float3(0, 0, 1));
WriteResult(pixelCoord, albedo * centerIrradiance);
StoreResult(pixelCoord, albedo * centerIrradiance);
#endif
return;
}

float3 viewDirVS = normalize(centerPosVS);
if (dot(normalVS, viewDirVS) >= 0)
{
WriteResult(pixelCoord, float3(1, 1, 1));
StoreResult(pixelCoord, float3(1, 1, 1));
return;
}
#endif

#if SSS_DEBUG_LOD
WriteResult(pixelCoord, useNearFieldKernel ? float3(1, 0, 0) : float3(0.5, 0.5, 0);
StoreResult(pixelCoord, useNearFieldKernel ? float3(1, 0, 0) : float3(0.5, 0.5, 0);
return;
#endif

[branch] if (!useNearFieldKernel)
{
WriteResult(pixelCoord, albedo * totalIrradiance / totalWeight);
StoreResult(pixelCoord, albedo * totalIrradiance / totalWeight);
return;
}

totalIrradiance, totalWeight);
}
WriteResult(pixelCoord, albedo * totalIrradiance / totalWeight);
StoreResult(pixelCoord, albedo * totalIrradiance / totalWeight);
}

10
ScriptableRenderPipeline/HDRenderPipeline/ShaderVariables.hlsl


float4 _InvProjParam;
float4 _ScreenSize; // (w, h, 1/w, 1/h)
float4 _FrustumPlanes[6]; // (N, -dot(N, P))
// Volumetric lighting. Should be a struct in 'UnityPerFrame'.
// Unfortunately, we cannot modify the layout of 'UnityPerFrame',
// and structures inside constant buffers are not supported by Unity.
float3 _GlobalFog_Scattering;
float _GlobalFog_Extinction;
float _GlobalFog_Asymmetry;
float _GlobalFog_Align16_0;
float _GlobalFog_Align16_1;
float _GlobalFog_Align16_2;
CBUFFER_END
#ifdef USE_LEGACY_UNITY_MATRIX_VARIABLES

10
ScriptableRenderPipeline/HDRenderPipeline/Lighting/Volumetrics.meta


fileFormatVersion: 2
guid: 1fe4fc72895e4bb4f90ff44b47e76051
folderAsset: yes
timeCreated: 1503411233
licenseType: Pro
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存