浏览代码
Merge branch 'master' into feature/SSR
Merge branch 'master' into feature/SSR
# Conflicts: # ScriptableRenderPipeline/HDRenderPipeline/HDRP/Camera/HDCamera.cs # ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDRenderPipeline.cs # ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/Lit.hlsl/main
Frédéric Vauchelles
7 年前
当前提交
09596c67
共有 154 个文件被更改,包括 2842 次插入 和 1903 次删除
-
51ScriptableRenderPipeline/Core/CoreRP/Editor/MaterialUpgrader.cs
-
61ScriptableRenderPipeline/Core/CoreRP/ShaderLibrary/Common.hlsl
-
4ScriptableRenderPipeline/Core/CoreRP/ShaderLibrary/EntityLighting.hlsl
-
9ScriptableRenderPipeline/Core/CoreRP/ShaderLibrary/ImageBasedLighting.hlsl
-
8ScriptableRenderPipeline/Core/CoreRP/ShaderLibrary/Wind.hlsl
-
76ScriptableRenderPipeline/Core/CoreRP/Utilities/CoreUtils.cs
-
95ScriptableRenderPipeline/HDRenderPipeline/HDRP/Camera/HDCamera.cs
-
2ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/DebugColorPicker.shader
-
11ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/DebugDisplay.cs
-
1ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/DebugDisplay.hlsl
-
10ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/DebugFullScreen.shader
-
2ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/DebugViewMaterialGBuffer.shader
-
6ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/DebugViewTiles.shader
-
8ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/LightingDebug.cs
-
12ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/LightingDebug.cs.hlsl
-
3ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/MaterialDebug.cs.hlsl
-
3ScriptableRenderPipeline/HDRenderPipeline/HDRP/Decal/DecalProjectorComponent.cs
-
66ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Material/Decal/DecalProjectorComponentEditor.cs
-
72ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDRenderPipeline.cs
-
24ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDStringConstants.cs
-
2ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Deferred.shader
-
2ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/DeferredDirectionalShadow.compute
-
106ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightEvaluation.hlsl
-
2ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/Deferred.compute
-
10ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/LightLoop.cs
-
19ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/LightLoopDef.hlsl
-
10ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Reflection/VolumeProjection.hlsl
-
3ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Volumetrics/VolumetricLighting.cs
-
18ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Decal/Decal.cs.hlsl
-
2ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/LayeredLit/LayeredLitData.hlsl
-
104ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/Lit.cs
-
326ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/Lit.hlsl
-
2ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/LitData.hlsl
-
52ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/StackLit/StackLit.hlsl
-
3ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/SubsurfaceScattering/SubsurfaceScatteringManager.cs
-
2ScriptableRenderPipeline/HDRenderPipeline/HDRP/RenderPipelineResources/CameraMotionVectors.shader
-
3ScriptableRenderPipeline/HDRenderPipeline/HDRP/RenderPipelineResources/CopyStencilBuffer.shader
-
2ScriptableRenderPipeline/HDRenderPipeline/HDRP/ShaderPass/ShaderPassDBuffer.hlsl
-
2ScriptableRenderPipeline/HDRenderPipeline/HDRP/ShaderPass/VaryingMesh.hlsl
-
175ScriptableRenderPipeline/HDRenderPipeline/HDRP/ShaderVariables.hlsl
-
5ScriptableRenderPipeline/HDRenderPipeline/HDRP/ShaderVariablesFunctions.hlsl
-
2ScriptableRenderPipeline/HDRenderPipeline/HDRP/Sky/OpaqueAtmosphericScattering.shader
-
4ScriptableRenderPipeline/HDRenderPipeline/HDRP/Wind/ShaderWindSettings.cs
-
100ScriptableRenderPipeline/LightweightPipeline/CHANGELOG.md
-
39ScriptableRenderPipeline/LightweightPipeline/LWRP/Data/LightweightPipelineAsset.cs
-
1ScriptableRenderPipeline/LightweightPipeline/LWRP/Data/LightweightPipelineResources.asset
-
1ScriptableRenderPipeline/LightweightPipeline/LWRP/Data/LightweightPipelineResources.cs
-
30ScriptableRenderPipeline/LightweightPipeline/LWRP/Editor/LightweightAssetEditor.cs
-
101ScriptableRenderPipeline/LightweightPipeline/LWRP/Editor/ShaderGUI/LightweightShaderGUI.cs
-
58ScriptableRenderPipeline/LightweightPipeline/LWRP/Editor/ShaderGUI/LightweightStandardGUI.cs
-
4ScriptableRenderPipeline/LightweightPipeline/LWRP/Editor/ShaderGUI/LightweightStandardParticlesShaderGUI.cs
-
62ScriptableRenderPipeline/LightweightPipeline/LWRP/Editor/ShaderGUI/LightweightStandardSimpleLightingGUI.cs
-
117ScriptableRenderPipeline/LightweightPipeline/LWRP/Editor/ShaderGUI/LightweightUnlitGUI.cs
-
17ScriptableRenderPipeline/LightweightPipeline/LWRP/Editor/ShaderGraph/lightweightPBRExtraPasses.template
-
13ScriptableRenderPipeline/LightweightPipeline/LWRP/Editor/ShaderGraph/lightweightPBRForwardPass.template
-
33ScriptableRenderPipeline/LightweightPipeline/LWRP/Editor/ShaderGraph/lightweightUnlitExtraPasses.template
-
6ScriptableRenderPipeline/LightweightPipeline/LWRP/Editor/ShaderGraph/lightweightUnlitPass.template
-
20ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightConstantBuffer.cs
-
830ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipeline.cs
-
160ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipelineUtils.cs
-
2ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightShaderUtils.cs
-
6ScriptableRenderPipeline/LightweightPipeline/LWRP/Materials/Lightweight-Default.mat
-
10ScriptableRenderPipeline/LightweightPipeline/LWRP/Materials/Lightweight-StandardSimpleLighting.mat
-
5ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/Core.hlsl
-
16ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/Input.hlsl
-
87ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/Lighting.hlsl
-
5ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/LightweightPassDepthOnly.hlsl
-
112ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/LightweightPassLit.hlsl
-
5ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/LightweightPassShadow.hlsl
-
84ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/Particles.hlsl
-
155ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/Shadows.hlsl
-
30ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/LightweightPassMetaCommon.hlsl
-
1ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightBlit.shader
-
1ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightCopyDepth.shader
-
12ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightScreenSpaceShadows.shader
-
19ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightStandard.shader
-
9ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightStandardParticles.shader
-
18ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightStandardParticlesSimpleLighting.shader
-
18ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightStandardParticlesUnlit.shader
-
24ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightStandardSimpleLighting.shader
-
59ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightStandardUnlit.shader
-
6ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/LTCAreaLight/LtcData.DisneyDiffuse.cs
-
2ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/LTCAreaLight/LtcData.GGX.cs
-
8ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/LTCAreaLight.meta
-
8ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/PreIntegratedFGD.meta
-
631ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightShadowPass.cs
-
11ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightShadowPass.cs.meta
-
71ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/InputSurfaceCommon.hlsl
-
97ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/InputSurfacePBR.hlsl
-
9ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/InputSurfacePBR.hlsl.meta
-
33ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/InputSurfaceSimple.hlsl
-
9ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/InputSurfaceSimple.hlsl.meta
-
15ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/InputSurfaceUnlit.hlsl
-
9ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/InputSurfaceUnlit.hlsl.meta
-
146ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/LightweightPassLitSimple.hlsl
-
9ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/LightweightPassLitSimple.hlsl.meta
-
22ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/LightweightPassMetaPBR.hlsl
-
9ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/LightweightPassMetaPBR.hlsl.meta
|
|||
# Changelog |
|||
All notable changes to this package will be documented in this file. |
|||
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) |
|||
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). |
|||
## [1.1.4-preview] |
|||
### Improvements |
|||
- Terrain and grass shaders ported |
|||
- Updated materials and shader default albedo and specular color to midgrey. |
|||
- Exposed _ScaledScreenParams to shader. It works the same as _ScreenParams but takes pipeline RenderScale into consideration |
|||
- Performance Improvements in mobile |
|||
|
|||
### Bugfixes |
|||
- Fixed SRP Shader library issue that was causing all constants to be highp in mobile |
|||
- Fixed shader error that prevented LWRP to build to UWP |
|||
- Fixed shader compilation errors in Linux due to case sensitive includes |
|||
- Fixed Rendering Texture flipping issue |
|||
- Fixed Standard Particles shader cutout and blending modes |
|||
- Fixed crash caused by using projectors |
|||
- Fixed issue that was causing Shadow Strength to not be computed on mobile |
|||
- Fixed Material Upgrader issue that caused editor to SoftLocks |
|||
- Fixed GI in Unlit shader |
|||
- Fixed null reference in the Unlit material shader GUI |
|||
## [0.1.6] - 2018-xx-yy |
|||
## [1.1.2-preview] |
|||
### Improvements |
|||
- Performance improvements in mobile |
|||
|
|||
### Bugfixes |
|||
- Fixed shadows on GLES 2.0 |
|||
- Fixed CPU performance regression in shadow rendering |
|||
- Fixed alpha clip shadow issues |
|||
- Fixed unmatched command buffer error message |
|||
- Fixed null reference exception caused by missing resource in LWRP |
|||
- Fixed issue that was causing Camera clear flags was being ignored in mobile |
|||
### Changelog starting |
|||
## [1.1.1-preview] |
|||
### Improvements |
|||
- Added Cascade Split selection UI |
|||
- Shadowmap uses 16bit format instead of 32bit. |
|||
- Added SHADER_HINT_NICE_QUALITY. If user defines this to 1 in the shader Lightweight pipeline will favor quality even on mobile platforms. |
|||
- Small shader performance improvements |
|||
Started Changelog |
|||
### Bugfixes |
|||
- Fixed Subtractive Mode |
|||
- Shadow Distance does not accept negative values anymore |
|||
|
|||
## [0.1.24] |
|||
### Improvements |
|||
- Refactored lightweight standard shaders and shader library to improve ease of use. |
|||
- Added Light abstraction layer on lightweight shader library. |
|||
- HDR RT now uses what format is configured in Tier settings. |
|||
- Optimized tile LOAD op on mobile. |
|||
- Added HDR global setting on pipeline asset. |
|||
- Added Soft Particles settings on pipeline asset. |
|||
- Ported particles shaders to SRP library |
|||
- Reduced GC pressure |
|||
- Reduced shader variant count by ~56% by improving fog and lightmap keywords |
|||
- Converted LW shader library files to use real/half when necessary. |
|||
|
|||
### Bugfixes |
|||
- Fixed realtime shadows on OpenGL |
|||
- Fixed shader compiler errors in GLES 2.0 |
|||
- Fixed issue sorting issues when BeforeTransparent custom fx was enabled. |
|||
- Fixed VR single pass rendering. |
|||
- Fixed viewport rendering issues when rendering to backbuffer. |
|||
- Fixed viewport rendering issues when rendering to with MSAA turned off. |
|||
- Fixed multi-camera rendering. |
|||
|
|||
## [0.1.23] |
|||
### Improvements |
|||
- Shaders ported to the new SRP shader library. |
|||
- Constant Buffer Refactor to use new Batcher |
|||
- Shadow filtering and bias improved. |
|||
- Pipeline now updates color constants in gamma when in Gamma colorspace. |
|||
- UI Improvements (Rendering features not supported by LW are hidden) |
|||
- Optimized ALU and CB usage on Shadows. |
|||
- Reduced shader variant count by ~33% by improving shadow and light classification keywords |
|||
- Default resources were removed from the pipeline asset. |
|||
|
|||
### Bugfixes |
|||
- Fixed shader include path when using SRP from package manager. |
|||
- Fixed spot light attenuation to match Unity Built-in pipeline. |
|||
- Fixed depth pre-pass clearing issue. |
|||
|
|||
## [0.1.12] |
|||
### Improvements |
|||
- Realtime shadow filtering was improved. |
|||
- Standard Unlit shader now has an option to sample GI. |
|||
- Added Material Upgrader for stock Unity Mobile and Legacy Shaders. |
|||
- UI improvements |
|||
|
|||
### Bugfixes |
|||
- Fixed an issue that was including unreferenced shaders in the build. |
|||
- Fixed a null reference caused by Particle System component lights. |
|||
|
|||
## [0.1.11] |
|||
Initial Release. |
|||
|
|||
|
|||
|
|||
|
830
ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipeline.cs
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
|
|||
fileFormatVersion: 2 |
|||
guid: 0cc808eb94961c54791ef0b41f113496 |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: d67850515da2e0844bf387a58fa11fac |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using UnityEngine.Rendering; |
|||
|
|||
namespace UnityEngine.Experimental.Rendering.LightweightPipeline |
|||
{ |
|||
[Serializable] |
|||
public class ShadowSettings |
|||
{ |
|||
public LightShadows directionalShadowQuality; |
|||
public bool screenSpace; |
|||
public int directionalShadowAtlasWidth; |
|||
public int directionalShadowAtlasHeight; |
|||
public LightShadows localLightsShadowQuality; |
|||
public int localShadowAtlasWidth; |
|||
public int localShadowAtlasHeight; |
|||
public int bufferBitCount; |
|||
|
|||
public float maxShadowDistance; |
|||
public int directionalLightCascadeCount; |
|||
public Vector3 directionalLightCascades; |
|||
|
|||
public RenderTextureFormat shadowmapTextureFormat; |
|||
public RenderTextureFormat screenspaceShadowmapTextureFormat; |
|||
|
|||
static ShadowSettings defaultShadowSettings = null; |
|||
|
|||
public static ShadowSettings Default |
|||
{ |
|||
get |
|||
{ |
|||
if (defaultShadowSettings == null) |
|||
{ |
|||
defaultShadowSettings = new ShadowSettings(); |
|||
defaultShadowSettings.directionalShadowQuality = LightShadows.None; |
|||
defaultShadowSettings.screenSpace = true; |
|||
defaultShadowSettings.directionalShadowAtlasHeight = defaultShadowSettings.directionalShadowAtlasWidth = 2048; |
|||
defaultShadowSettings.localLightsShadowQuality = LightShadows.None; |
|||
defaultShadowSettings.localShadowAtlasWidth = 512; |
|||
defaultShadowSettings.localShadowAtlasHeight = 512; |
|||
defaultShadowSettings.bufferBitCount = 16; |
|||
defaultShadowSettings.directionalLightCascadeCount = 1; |
|||
defaultShadowSettings.directionalLightCascades = new Vector3(0.05F, 0.2F, 0.3F); |
|||
defaultShadowSettings.shadowmapTextureFormat = RenderTextureFormat.Shadowmap; |
|||
defaultShadowSettings.screenspaceShadowmapTextureFormat = RenderTextureFormat.R8; |
|||
} |
|||
return defaultShadowSettings; |
|||
} |
|||
} |
|||
} |
|||
|
|||
public struct ShadowSliceData |
|||
{ |
|||
public Matrix4x4 shadowTransform; |
|||
public int offsetX; |
|||
public int offsetY; |
|||
public int resolution; |
|||
|
|||
public void Clear() |
|||
{ |
|||
shadowTransform = Matrix4x4.identity; |
|||
offsetX = offsetY = 0; |
|||
resolution = 1024; |
|||
} |
|||
} |
|||
|
|||
public class LightweightShadowPass |
|||
{ |
|||
public bool IsDirectionalShadowsEnabled { get { return m_ShadowSettings.directionalShadowQuality != LightShadows.None; } } |
|||
public bool IsLocalShadowsEnabled { get { return m_ShadowSettings.localLightsShadowQuality != LightShadows.None; }} |
|||
public bool RequireScreenSpaceShadowmap { get { return IsDirectionalShadowsEnabled && m_ShadowSettings.screenSpace; } } |
|||
public bool HasDirectionalShadowmap { get { return m_DirectionalShadowmapQuality != LightShadows.None; } } |
|||
public bool HasLocalLightsShadowmap { get { return m_LocalShadowmapQuality != LightShadows.None; } } |
|||
|
|||
public float RenderingDistance { get { return m_ShadowSettings.maxShadowDistance; } } |
|||
|
|||
private const int kMaxCascades = 4; |
|||
|
|||
private int m_ShadowCasterCascadesCount; |
|||
private int m_DirectionalShadowmapID; |
|||
private int m_LocalShadowmapID; |
|||
private int m_ScreenSpaceShadowmapID; |
|||
|
|||
private ShadowSettings m_ShadowSettings = ShadowSettings.Default; |
|||
|
|||
private Material m_ScreenSpaceShadowsMaterial; |
|||
|
|||
private RenderTexture m_DirectionalShadowmapTexture; |
|||
private RenderTexture m_LocalShadowmapTexture; |
|||
private RenderTargetIdentifier m_ScreenSpaceShadowmapTexture; |
|||
|
|||
private RenderTextureDescriptor m_DirectionalShadowmapDescriptor; |
|||
private RenderTextureDescriptor m_LocalShadowmapDescriptor; |
|||
|
|||
private LightShadows m_DirectionalShadowmapQuality; |
|||
private LightShadows m_LocalShadowmapQuality; |
|||
|
|||
private Matrix4x4[] m_DirectionalShadowMatrices; |
|||
private ShadowSliceData[] m_CascadeSlices; |
|||
private Vector4[] m_CascadeSplitDistances; |
|||
private Vector4 m_CascadeSplitRadii; |
|||
|
|||
private Matrix4x4[] m_LocalShadowMatrices; |
|||
private ShadowSliceData[] m_LocalLightSlices; |
|||
private float[] m_LocalShadowStrength; |
|||
|
|||
public LightweightShadowPass(LightweightPipelineAsset pipelineAsset, int maxLocalLightsCount) |
|||
{ |
|||
BuildShadowSettings(pipelineAsset); |
|||
|
|||
m_DirectionalShadowMatrices = new Matrix4x4[kMaxCascades + 1]; |
|||
m_CascadeSlices = new ShadowSliceData[kMaxCascades]; |
|||
m_CascadeSplitDistances = new Vector4[kMaxCascades]; |
|||
|
|||
m_LocalShadowMatrices = new Matrix4x4[maxLocalLightsCount]; |
|||
m_LocalLightSlices = new ShadowSliceData[maxLocalLightsCount]; |
|||
m_LocalShadowStrength = new float[maxLocalLightsCount]; |
|||
|
|||
DirectionalShadowConstantBuffer._WorldToShadow = Shader.PropertyToID("_WorldToShadow"); |
|||
DirectionalShadowConstantBuffer._ShadowData = Shader.PropertyToID("_ShadowData"); |
|||
DirectionalShadowConstantBuffer._DirShadowSplitSpheres = Shader.PropertyToID("_DirShadowSplitSpheres"); |
|||
DirectionalShadowConstantBuffer._DirShadowSplitSphereRadii = Shader.PropertyToID("_DirShadowSplitSphereRadii"); |
|||
DirectionalShadowConstantBuffer._ShadowOffset0 = Shader.PropertyToID("_ShadowOffset0"); |
|||
DirectionalShadowConstantBuffer._ShadowOffset1 = Shader.PropertyToID("_ShadowOffset1"); |
|||
DirectionalShadowConstantBuffer._ShadowOffset2 = Shader.PropertyToID("_ShadowOffset2"); |
|||
DirectionalShadowConstantBuffer._ShadowOffset3 = Shader.PropertyToID("_ShadowOffset3"); |
|||
DirectionalShadowConstantBuffer._ShadowmapSize = Shader.PropertyToID("_ShadowmapSize"); |
|||
|
|||
LocalShadowConstantBuffer._LocalWorldToShadowAtlas = Shader.PropertyToID("_LocalWorldToShadowAtlas"); |
|||
LocalShadowConstantBuffer._LocalShadowStrength = Shader.PropertyToID("_LocalShadowStrength"); |
|||
LocalShadowConstantBuffer._LocalShadowOffset0 = Shader.PropertyToID("_LocalShadowOffset0"); |
|||
LocalShadowConstantBuffer._LocalShadowOffset1 = Shader.PropertyToID("_LocalShadowOffset1"); |
|||
LocalShadowConstantBuffer._LocalShadowOffset2 = Shader.PropertyToID("_LocalShadowOffset2"); |
|||
LocalShadowConstantBuffer._LocalShadowOffset3 = Shader.PropertyToID("_LocalShadowOffset3"); |
|||
LocalShadowConstantBuffer._LocalShadowmapSize = Shader.PropertyToID("_LocalShadowmapSize"); |
|||
|
|||
m_DirectionalShadowmapID = Shader.PropertyToID("_ShadowMap"); |
|||
m_LocalShadowmapID = Shader.PropertyToID("_LocalShadowMapAtlas"); |
|||
m_ScreenSpaceShadowmapID = Shader.PropertyToID("_ScreenSpaceShadowMap"); |
|||
m_ScreenSpaceShadowmapTexture = new RenderTargetIdentifier(m_ScreenSpaceShadowmapID); |
|||
|
|||
m_DirectionalShadowmapDescriptor = new RenderTextureDescriptor(m_ShadowSettings.directionalShadowAtlasWidth, |
|||
m_ShadowSettings.directionalShadowAtlasHeight, m_ShadowSettings.shadowmapTextureFormat, m_ShadowSettings.bufferBitCount); |
|||
|
|||
m_LocalShadowmapDescriptor = new RenderTextureDescriptor(m_ShadowSettings.localShadowAtlasWidth, |
|||
m_ShadowSettings.localShadowAtlasHeight, m_ShadowSettings.shadowmapTextureFormat, m_ShadowSettings.bufferBitCount); |
|||
|
|||
m_ScreenSpaceShadowsMaterial = CoreUtils.CreateEngineMaterial(pipelineAsset.ScreenSpaceShadowShader); |
|||
|
|||
Clear(); |
|||
} |
|||
|
|||
public void InitializeResources(CommandBuffer cmd, RenderTextureDescriptor renderTextureDesc) |
|||
{ |
|||
if (RequireScreenSpaceShadowmap) |
|||
{ |
|||
renderTextureDesc.depthBufferBits = 0; |
|||
renderTextureDesc.colorFormat = m_ShadowSettings.screenspaceShadowmapTextureFormat; |
|||
cmd.GetTemporaryRT(m_ScreenSpaceShadowmapID, renderTextureDesc, FilterMode.Bilinear); |
|||
} |
|||
} |
|||
|
|||
public void Dispose(CommandBuffer cmd) |
|||
{ |
|||
cmd.ReleaseTemporaryRT(m_ScreenSpaceShadowmapID); |
|||
|
|||
if (m_DirectionalShadowmapTexture) |
|||
{ |
|||
RenderTexture.ReleaseTemporary(m_DirectionalShadowmapTexture); |
|||
m_DirectionalShadowmapTexture = null; |
|||
} |
|||
|
|||
if (m_LocalShadowmapTexture) |
|||
{ |
|||
RenderTexture.ReleaseTemporary(m_LocalShadowmapTexture); |
|||
m_LocalShadowmapTexture = null; |
|||
} |
|||
} |
|||
|
|||
public bool Execute(ref CullResults cullResults, ref LightData lightData, ref ScriptableRenderContext context) |
|||
{ |
|||
Clear(); |
|||
|
|||
bool directionalShadowmapRendered = false; |
|||
if (IsDirectionalShadowsEnabled) |
|||
directionalShadowmapRendered = RenderDirectionalCascadeShadowmap(ref cullResults, ref lightData, ref context); |
|||
|
|||
if (IsLocalShadowsEnabled) |
|||
RenderLocalShadowmapAtlas(ref cullResults, ref lightData, ref context); |
|||
|
|||
return directionalShadowmapRendered && m_ShadowSettings.screenSpace; |
|||
} |
|||
|
|||
public void CollectShadows(Camera camera, FrameRenderingConfiguration frameRenderingConfiguration, ref ScriptableRenderContext context) |
|||
{ |
|||
CommandBuffer cmd = CommandBufferPool.Get("Collect Shadows"); |
|||
|
|||
SetShadowCollectPassKeywords(cmd); |
|||
|
|||
// Note: The source isn't actually 'used', but there's an engine peculiarity (bug) that
|
|||
// doesn't like null sources when trying to determine a stereo-ized blit. So for proper
|
|||
// stereo functionality, we use the screen-space shadow map as the source (until we have
|
|||
// a better solution).
|
|||
// An alternative would be DrawProcedural, but that would require further changes in the shader.
|
|||
cmd.SetRenderTarget(m_ScreenSpaceShadowmapTexture); |
|||
cmd.ClearRenderTarget(true, true, Color.white); |
|||
cmd.Blit(m_ScreenSpaceShadowmapTexture, m_ScreenSpaceShadowmapTexture, m_ScreenSpaceShadowsMaterial); |
|||
|
|||
LightweightUtils.StartStereoRendering(camera, ref context, frameRenderingConfiguration); |
|||
|
|||
context.ExecuteCommandBuffer(cmd); |
|||
|
|||
LightweightUtils.StopStereoRendering(camera, ref context, frameRenderingConfiguration); |
|||
|
|||
CommandBufferPool.Release(cmd); |
|||
} |
|||
|
|||
private void BuildShadowSettings(LightweightPipelineAsset pipelineAsset) |
|||
{ |
|||
// Until we can have keyword stripping forcing single cascade hard shadows on gles2
|
|||
bool supportsScreenSpaceShadows = SystemInfo.graphicsDeviceType != GraphicsDeviceType.OpenGLES2; |
|||
bool supportsLocalShadows = Application.isMobilePlatform || Application.platform == RuntimePlatform.WebGLPlayer; |
|||
|
|||
m_ShadowSettings = ShadowSettings.Default; |
|||
m_ShadowSettings.directionalShadowQuality = (LightShadows)pipelineAsset.ShadowSetting; |
|||
|
|||
m_ShadowSettings.screenSpace = supportsScreenSpaceShadows; |
|||
m_ShadowSettings.directionalLightCascadeCount = (m_ShadowSettings.screenSpace) ? pipelineAsset.CascadeCount : 1; |
|||
|
|||
m_ShadowSettings.directionalShadowAtlasWidth = pipelineAsset.ShadowAtlasResolution; |
|||
m_ShadowSettings.directionalShadowAtlasHeight = pipelineAsset.ShadowAtlasResolution; |
|||
m_ShadowSettings.maxShadowDistance = pipelineAsset.ShadowDistance; |
|||
m_ShadowSettings.shadowmapTextureFormat = SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.Shadowmap) |
|||
? RenderTextureFormat.Shadowmap |
|||
: RenderTextureFormat.Depth; |
|||
|
|||
m_ShadowSettings.screenspaceShadowmapTextureFormat = SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.R8) |
|||
? RenderTextureFormat.R8 |
|||
: RenderTextureFormat.ARGB32; |
|||
|
|||
switch (m_ShadowSettings.directionalLightCascadeCount) |
|||
{ |
|||
case 1: |
|||
m_ShadowSettings.directionalLightCascades = new Vector3(1.0f, 0.0f, 0.0f); |
|||
break; |
|||
|
|||
case 2: |
|||
m_ShadowSettings.directionalLightCascades = new Vector3(pipelineAsset.Cascade2Split, 1.0f, 0.0f); |
|||
break; |
|||
|
|||
default: |
|||
m_ShadowSettings.directionalLightCascades = pipelineAsset.Cascade4Split; |
|||
break; |
|||
} |
|||
|
|||
// Until we can have keyword stripping we disable local light shadows on mobile
|
|||
m_ShadowSettings.localLightsShadowQuality = (supportsLocalShadows) ? LightShadows.Hard : LightShadows.None; |
|||
} |
|||
|
|||
private void Clear() |
|||
{ |
|||
m_DirectionalShadowmapTexture = null; |
|||
m_LocalShadowmapTexture = null; |
|||
m_DirectionalShadowmapQuality = LightShadows.None; |
|||
m_LocalShadowmapQuality = LightShadows.None; |
|||
|
|||
for (int i = 0; i < m_DirectionalShadowMatrices.Length; ++i) |
|||
m_DirectionalShadowMatrices[i] = Matrix4x4.identity; |
|||
|
|||
for (int i = 0; i < m_LocalShadowMatrices.Length; ++i) |
|||
m_LocalShadowMatrices[i] = Matrix4x4.identity; |
|||
|
|||
for (int i = 0; i < m_CascadeSplitDistances.Length; ++i) |
|||
m_CascadeSplitDistances[i] = new Vector4(0.0f, 0.0f, 0.0f, 0.0f); |
|||
|
|||
m_CascadeSplitRadii = new Vector4(0.0f, 0.0f, 0.0f, 0.0f); |
|||
|
|||
for (int i = 0; i < m_CascadeSlices.Length; ++i) |
|||
m_CascadeSlices[i].Clear(); |
|||
|
|||
for (int i = 0; i < m_LocalLightSlices.Length; ++i) |
|||
m_LocalLightSlices[i].Clear(); |
|||
|
|||
for (int i = 0; i < m_LocalShadowStrength.Length; ++i) |
|||
m_LocalShadowStrength[i] = 0.0f; |
|||
} |
|||
|
|||
private void SetShadowCollectPassKeywords(CommandBuffer cmd) |
|||
{ |
|||
CoreUtils.SetKeyword(cmd, "_SHADOWS_SOFT", m_DirectionalShadowmapQuality == LightShadows.Soft); |
|||
CoreUtils.SetKeyword(cmd, "_SHADOWS_CASCADE", m_ShadowSettings.directionalLightCascadeCount > 1); |
|||
} |
|||
|
|||
private bool RenderDirectionalCascadeShadowmap(ref CullResults cullResults, ref LightData lightData, ref ScriptableRenderContext context) |
|||
{ |
|||
int shadowLightIndex = lightData.mainLightIndex; |
|||
if (shadowLightIndex == -1) |
|||
return false; |
|||
|
|||
VisibleLight shadowLight = lightData.visibleLights[shadowLightIndex]; |
|||
Light light = shadowLight.light; |
|||
Debug.Assert(shadowLight.lightType == LightType.Directional); |
|||
|
|||
if (light.shadows == LightShadows.None) |
|||
return false; |
|||
|
|||
CommandBuffer cmd = CommandBufferPool.Get("Prepare Directional Shadowmap"); |
|||
m_ShadowCasterCascadesCount = m_ShadowSettings.directionalLightCascadeCount; |
|||
|
|||
int shadowResolution = GetMaxTileResolutionInAtlas(m_ShadowSettings.directionalShadowAtlasWidth, m_ShadowSettings.directionalShadowAtlasHeight, m_ShadowCasterCascadesCount); |
|||
float shadowNearPlane = light.shadowNearPlane; |
|||
|
|||
Bounds bounds; |
|||
if (!cullResults.GetShadowCasterBounds(shadowLightIndex, out bounds)) |
|||
return false; |
|||
|
|||
Matrix4x4 view, proj; |
|||
var settings = new DrawShadowsSettings(cullResults, shadowLightIndex); |
|||
|
|||
m_DirectionalShadowmapTexture = RenderTexture.GetTemporary(m_DirectionalShadowmapDescriptor); |
|||
m_DirectionalShadowmapTexture.filterMode = FilterMode.Bilinear; |
|||
m_DirectionalShadowmapTexture.wrapMode = TextureWrapMode.Clamp; |
|||
|
|||
CoreUtils.SetRenderTarget(cmd, m_DirectionalShadowmapTexture, ClearFlag.Depth); |
|||
|
|||
bool success = false; |
|||
for (int cascadeIndex = 0; cascadeIndex < m_ShadowCasterCascadesCount; ++cascadeIndex) |
|||
{ |
|||
success = cullResults.ComputeDirectionalShadowMatricesAndCullingPrimitives(shadowLightIndex, |
|||
cascadeIndex, m_ShadowCasterCascadesCount, m_ShadowSettings.directionalLightCascades, shadowResolution, shadowNearPlane, out view, out proj, |
|||
out settings.splitData); |
|||
|
|||
float cullingSphereRadius = settings.splitData.cullingSphere.w; |
|||
m_CascadeSplitDistances[cascadeIndex] = settings.splitData.cullingSphere; |
|||
m_CascadeSplitRadii[cascadeIndex] = cullingSphereRadius * cullingSphereRadius; |
|||
|
|||
if (!success) |
|||
break; |
|||
|
|||
m_CascadeSlices[cascadeIndex].offsetX = (cascadeIndex % 2) * shadowResolution; |
|||
m_CascadeSlices[cascadeIndex].offsetY = (cascadeIndex / 2) * shadowResolution; |
|||
m_CascadeSlices[cascadeIndex].resolution = shadowResolution; |
|||
m_CascadeSlices[cascadeIndex].shadowTransform = GetShadowTransform(proj, view); |
|||
|
|||
// If we have shadow cascades baked into the atlas we bake cascade transform
|
|||
// in each shadow matrix to save shader ALU and L/S
|
|||
if (m_ShadowCasterCascadesCount > 1) |
|||
ApplySliceTransform(ref m_CascadeSlices[cascadeIndex], m_ShadowSettings.directionalShadowAtlasWidth, m_ShadowSettings.directionalShadowAtlasHeight); |
|||
|
|||
SetupShadowCasterConstants(cmd, ref shadowLight, proj, shadowResolution); |
|||
RenderShadowSlice(cmd, ref context, ref m_CascadeSlices[cascadeIndex], proj, view, settings); |
|||
} |
|||
|
|||
if (success) |
|||
{ |
|||
m_DirectionalShadowmapQuality = (m_ShadowSettings.directionalShadowQuality != LightShadows.Soft) ? LightShadows.Hard : light.shadows; |
|||
|
|||
// In order to avoid shader variants explosion we only do hard shadows when sampling shadowmap in the lit pass.
|
|||
// GLES2 platform is forced to hard single cascade shadows.
|
|||
if (!m_ShadowSettings.screenSpace) |
|||
m_DirectionalShadowmapQuality = LightShadows.Hard; |
|||
|
|||
SetupDirectionalShadowReceiverConstants(cmd, shadowLight, ref context); |
|||
} |
|||
|
|||
context.ExecuteCommandBuffer(cmd); |
|||
CommandBufferPool.Release(cmd); |
|||
return success; |
|||
} |
|||
|
|||
private void RenderLocalShadowmapAtlas(ref CullResults cullResults, ref LightData lightData, ref ScriptableRenderContext context) |
|||
{ |
|||
List<int> localLightIndices = lightData.localLightIndices; |
|||
List<VisibleLight> visibleLights = lightData.visibleLights; |
|||
|
|||
int shadowCastingLightsCount = 0; |
|||
int localLightsCount = localLightIndices.Count; |
|||
for (int i = 0; i < localLightsCount; ++i) |
|||
{ |
|||
VisibleLight shadowLight = visibleLights[localLightIndices[i]]; |
|||
|
|||
if (shadowLight.lightType == LightType.Spot && shadowLight.light.shadows != LightShadows.None) |
|||
shadowCastingLightsCount++; |
|||
} |
|||
|
|||
if (shadowCastingLightsCount == 0) |
|||
return; |
|||
|
|||
CommandBuffer cmd = CommandBufferPool.Get("Prepare Local Lights Shadowmap"); |
|||
Matrix4x4 view, proj; |
|||
Bounds bounds; |
|||
|
|||
// TODO: Add support to point light shadows. We make a simplification here that only works
|
|||
// for spot lights and with max spot shadows per pass.
|
|||
int atlasWidth = m_ShadowSettings.localShadowAtlasWidth; |
|||
int atlasHeight = m_ShadowSettings.localShadowAtlasHeight; |
|||
int sliceResolution = GetMaxTileResolutionInAtlas(atlasWidth, atlasHeight, shadowCastingLightsCount); |
|||
int shadowSampling = 0; |
|||
|
|||
m_LocalShadowmapTexture = RenderTexture.GetTemporary(m_LocalShadowmapDescriptor); |
|||
m_LocalShadowmapTexture.filterMode = FilterMode.Bilinear; |
|||
m_LocalShadowmapTexture.wrapMode = TextureWrapMode.Clamp; |
|||
|
|||
CoreUtils.SetRenderTarget(cmd, m_LocalShadowmapTexture, ClearFlag.Depth); |
|||
|
|||
for (int i = 0; i < localLightsCount; ++i) |
|||
{ |
|||
int shadowLightIndex = localLightIndices[i]; |
|||
VisibleLight shadowLight = visibleLights[shadowLightIndex]; |
|||
Light light = shadowLight.light; |
|||
|
|||
// TODO: Add support to point light shadows
|
|||
if (shadowLight.lightType != LightType.Spot || shadowLight.light.shadows == LightShadows.None) |
|||
continue; |
|||
|
|||
if (!cullResults.GetShadowCasterBounds(shadowLightIndex, out bounds)) |
|||
continue; |
|||
|
|||
var settings = new DrawShadowsSettings(cullResults, shadowLightIndex); |
|||
|
|||
if (cullResults.ComputeSpotShadowMatricesAndCullingPrimitives(shadowLightIndex, out view, out proj, out settings.splitData)) |
|||
{ |
|||
// This way of computing the shadow slice only work for spots and with most 4 shadow casting lights per pass
|
|||
// Change this when point lights are supported.
|
|||
Debug.Assert(localLightsCount <= 4 && shadowLight.lightType == LightType.Spot); |
|||
|
|||
// TODO: We need to pass bias and scale list to shader to be able to support multiple
|
|||
// shadow casting local lights.
|
|||
m_LocalLightSlices[i].offsetX = (i % 2) * sliceResolution; |
|||
m_LocalLightSlices[i].offsetY = (i / 2) * sliceResolution; |
|||
m_LocalLightSlices[i].resolution = sliceResolution; |
|||
m_LocalLightSlices[i].shadowTransform = GetShadowTransform(proj, view); |
|||
|
|||
if (shadowCastingLightsCount > 1) |
|||
ApplySliceTransform(ref m_LocalLightSlices[i], atlasWidth, atlasHeight); |
|||
|
|||
SetupShadowCasterConstants(cmd, ref shadowLight, proj, sliceResolution); |
|||
RenderShadowSlice(cmd, ref context, ref m_LocalLightSlices[i], proj, view, settings); |
|||
m_LocalShadowStrength[i] = light.shadowStrength; |
|||
shadowSampling = Math.Max(shadowSampling, (int)light.shadows); |
|||
} |
|||
} |
|||
|
|||
SetupLocalLightsShadowReceiverConstants(cmd, ref context); |
|||
|
|||
m_LocalShadowmapQuality = (LightShadows)Math.Min(shadowSampling, (int)m_ShadowSettings.directionalShadowQuality); |
|||
context.ExecuteCommandBuffer(cmd); |
|||
CommandBufferPool.Release(cmd); |
|||
} |
|||
|
|||
private Matrix4x4 GetShadowTransform(Matrix4x4 proj, Matrix4x4 view) |
|||
{ |
|||
// Currently CullResults ComputeDirectionalShadowMatricesAndCullingPrimitives doesn't
|
|||
// apply z reversal to projection matrix. We need to do it manually here.
|
|||
if (SystemInfo.usesReversedZBuffer) |
|||
{ |
|||
proj.m20 = -proj.m20; |
|||
proj.m21 = -proj.m21; |
|||
proj.m22 = -proj.m22; |
|||
proj.m23 = -proj.m23; |
|||
} |
|||
|
|||
Matrix4x4 worldToShadow = proj * view; |
|||
|
|||
var textureScaleAndBias = Matrix4x4.identity; |
|||
textureScaleAndBias.m00 = 0.5f; |
|||
textureScaleAndBias.m11 = 0.5f; |
|||
textureScaleAndBias.m22 = 0.5f; |
|||
textureScaleAndBias.m03 = 0.5f; |
|||
textureScaleAndBias.m23 = 0.5f; |
|||
textureScaleAndBias.m13 = 0.5f; |
|||
|
|||
// Apply texture scale and offset to save a MAD in shader.
|
|||
return textureScaleAndBias * worldToShadow; |
|||
} |
|||
|
|||
private void ApplySliceTransform(ref ShadowSliceData shadowSliceData, int atlasWidth, int atlasHeight) |
|||
{ |
|||
Matrix4x4 sliceTransform = Matrix4x4.identity; |
|||
float oneOverAtlasWidth = 1.0f / atlasWidth; |
|||
float oneOverAtlasHeight = 1.0f / atlasHeight; |
|||
sliceTransform.m00 = shadowSliceData.resolution * oneOverAtlasWidth; |
|||
sliceTransform.m11 = shadowSliceData.resolution * oneOverAtlasHeight; |
|||
sliceTransform.m03 = shadowSliceData.offsetX * oneOverAtlasWidth; |
|||
sliceTransform.m13 = shadowSliceData.offsetY * oneOverAtlasHeight; |
|||
|
|||
// Apply shadow slice scale and offset
|
|||
shadowSliceData.shadowTransform = sliceTransform * shadowSliceData.shadowTransform; |
|||
} |
|||
|
|||
private void RenderShadowSlice(CommandBuffer cmd, ref ScriptableRenderContext context, ref ShadowSliceData shadowSliceData, |
|||
Matrix4x4 proj, Matrix4x4 view, DrawShadowsSettings settings) |
|||
{ |
|||
cmd.SetViewport(new Rect(shadowSliceData.offsetX, shadowSliceData.offsetY, shadowSliceData.resolution, shadowSliceData.resolution)); |
|||
cmd.EnableScissorRect(new Rect(shadowSliceData.offsetX + 4, shadowSliceData.offsetY + 4, shadowSliceData.resolution - 8, shadowSliceData.resolution - 8)); |
|||
|
|||
cmd.SetViewProjectionMatrices(view, proj); |
|||
context.ExecuteCommandBuffer(cmd); |
|||
cmd.Clear(); |
|||
context.DrawShadows(ref settings); |
|||
cmd.DisableScissorRect(); |
|||
context.ExecuteCommandBuffer(cmd); |
|||
cmd.Clear(); |
|||
} |
|||
|
|||
private int GetMaxTileResolutionInAtlas(int atlasWidth, int atlasHeight, int tileCount) |
|||
{ |
|||
int resolution = Mathf.Min(atlasWidth, atlasHeight); |
|||
if (tileCount > Mathf.Log(resolution)) |
|||
{ |
|||
Debug.LogError( |
|||
String.Format( |
|||
"Cannot fit {0} tiles into current shadowmap atlas of size ({1}, {2}). ShadowMap Resolution set to zero.", |
|||
tileCount, atlasWidth, atlasHeight)); |
|||
return 0; |
|||
} |
|||
|
|||
int currentTileCount = atlasWidth / resolution * atlasHeight / resolution; |
|||
while (currentTileCount < tileCount) |
|||
{ |
|||
resolution = resolution >> 1; |
|||
currentTileCount = atlasWidth / resolution * atlasHeight / resolution; |
|||
} |
|||
return resolution; |
|||
} |
|||
|
|||
private void SetupShadowCasterConstants(CommandBuffer cmd, ref VisibleLight visibleLight, Matrix4x4 proj, float cascadeResolution) |
|||
{ |
|||
Light light = visibleLight.light; |
|||
float bias = 0.0f; |
|||
float normalBias = 0.0f; |
|||
|
|||
// Use same kernel radius as built-in pipeline so we can achieve same bias results
|
|||
// with the default light bias parameters.
|
|||
const float kernelRadius = 3.65f; |
|||
|
|||
if (visibleLight.lightType == LightType.Directional) |
|||
{ |
|||
// Scale bias by cascade's world space depth range.
|
|||
// Directional shadow lights have orthogonal projection.
|
|||
// proj.m22 = -2 / (far - near) since the projection's depth range is [-1.0, 1.0]
|
|||
// In order to be correct we should multiply bias by 0.5 but this introducing aliasing along cascades more visible.
|
|||
float sign = (SystemInfo.usesReversedZBuffer) ? 1.0f : -1.0f; |
|||
bias = light.shadowBias * proj.m22 * sign; |
|||
|
|||
// Currently only square POT cascades resolutions are used.
|
|||
// We scale normalBias
|
|||
double frustumWidth = 2.0 / (double)proj.m00; |
|||
double frustumHeight = 2.0 / (double)proj.m11; |
|||
float texelSizeX = (float)(frustumWidth / (double)cascadeResolution); |
|||
float texelSizeY = (float)(frustumHeight / (double)cascadeResolution); |
|||
float texelSize = Mathf.Max(texelSizeX, texelSizeY); |
|||
|
|||
// Since we are applying normal bias on caster side we want an inset normal offset
|
|||
// thus we use a negative normal bias.
|
|||
normalBias = -light.shadowNormalBias * texelSize * kernelRadius; |
|||
} |
|||
else if (visibleLight.lightType == LightType.Spot) |
|||
{ |
|||
float sign = (SystemInfo.usesReversedZBuffer) ? -1.0f : 1.0f; |
|||
bias = light.shadowBias * sign; |
|||
normalBias = 0.0f; |
|||
} |
|||
else |
|||
{ |
|||
Debug.LogWarning("Only spot and directional shadow casters are supported in lightweight pipeline"); |
|||
} |
|||
|
|||
Vector3 lightDirection = -visibleLight.localToWorld.GetColumn(2); |
|||
cmd.SetGlobalVector("_ShadowBias", new Vector4(bias, normalBias, 0.0f, 0.0f)); |
|||
cmd.SetGlobalVector("_LightDirection", new Vector4(lightDirection.x, lightDirection.y, lightDirection.z, 0.0f)); |
|||
} |
|||
|
|||
private void SetupDirectionalShadowReceiverConstants(CommandBuffer cmd, VisibleLight shadowLight, ref ScriptableRenderContext context) |
|||
{ |
|||
Light light = shadowLight.light; |
|||
|
|||
int cascadeCount = m_ShadowCasterCascadesCount; |
|||
for (int i = 0; i < kMaxCascades; ++i) |
|||
m_DirectionalShadowMatrices[i] = (cascadeCount >= i) ? m_CascadeSlices[i].shadowTransform : Matrix4x4.identity; |
|||
|
|||
// We setup and additional a no-op WorldToShadow matrix in the last index
|
|||
// because the ComputeCascadeIndex function in Shadows.hlsl can return an index
|
|||
// out of bounds. (position not inside any cascade) and we want to avoid branching
|
|||
Matrix4x4 noOpShadowMatrix = Matrix4x4.zero; |
|||
noOpShadowMatrix.m33 = (SystemInfo.usesReversedZBuffer) ? 1.0f : 0.0f; |
|||
m_DirectionalShadowMatrices[kMaxCascades] = noOpShadowMatrix; |
|||
|
|||
float invShadowAtlasWidth = 1.0f / m_ShadowSettings.directionalShadowAtlasWidth; |
|||
float invShadowAtlasHeight = 1.0f / m_ShadowSettings.directionalShadowAtlasHeight; |
|||
float invHalfShadowAtlasWidth = 0.5f * invShadowAtlasWidth; |
|||
float invHalfShadowAtlasHeight = 0.5f * invShadowAtlasHeight; |
|||
cmd.SetGlobalTexture(m_DirectionalShadowmapID, m_DirectionalShadowmapTexture); |
|||
cmd.SetGlobalMatrixArray(DirectionalShadowConstantBuffer._WorldToShadow, m_DirectionalShadowMatrices); |
|||
cmd.SetGlobalVector(DirectionalShadowConstantBuffer._ShadowData, new Vector4(light.shadowStrength, 0.0f, 0.0f, 0.0f)); |
|||
cmd.SetGlobalVectorArray(DirectionalShadowConstantBuffer._DirShadowSplitSpheres, m_CascadeSplitDistances); |
|||
cmd.SetGlobalVector(DirectionalShadowConstantBuffer._DirShadowSplitSphereRadii, m_CascadeSplitRadii); |
|||
cmd.SetGlobalVector(DirectionalShadowConstantBuffer._ShadowOffset0, new Vector4(-invHalfShadowAtlasWidth, -invHalfShadowAtlasHeight, 0.0f, 0.0f)); |
|||
cmd.SetGlobalVector(DirectionalShadowConstantBuffer._ShadowOffset1, new Vector4(invHalfShadowAtlasWidth, -invHalfShadowAtlasHeight, 0.0f, 0.0f)); |
|||
cmd.SetGlobalVector(DirectionalShadowConstantBuffer._ShadowOffset2, new Vector4(-invHalfShadowAtlasWidth, invHalfShadowAtlasHeight, 0.0f, 0.0f)); |
|||
cmd.SetGlobalVector(DirectionalShadowConstantBuffer._ShadowOffset3, new Vector4(invHalfShadowAtlasWidth, invHalfShadowAtlasHeight, 0.0f, 0.0f)); |
|||
cmd.SetGlobalVector(DirectionalShadowConstantBuffer._ShadowmapSize, new Vector4(invShadowAtlasWidth, invShadowAtlasHeight, |
|||
m_ShadowSettings.directionalShadowAtlasWidth, m_ShadowSettings.directionalShadowAtlasHeight)); |
|||
context.ExecuteCommandBuffer(cmd); |
|||
cmd.Clear(); |
|||
} |
|||
|
|||
private void SetupLocalLightsShadowReceiverConstants(CommandBuffer cmd, ref ScriptableRenderContext context) |
|||
{ |
|||
for (int i = 0; i < m_LocalLightSlices.Length; ++i) |
|||
m_LocalShadowMatrices[i] = m_LocalLightSlices[i].shadowTransform; |
|||
|
|||
float invShadowAtlasWidth = 1.0f / m_ShadowSettings.localShadowAtlasWidth; |
|||
float invShadowAtlasHeight = 1.0f / m_ShadowSettings.localShadowAtlasHeight; |
|||
float invHalfShadowAtlasWidth = 0.5f * invShadowAtlasWidth; |
|||
float invHalfShadowAtlasHeight = 0.5f * invShadowAtlasHeight; |
|||
|
|||
cmd.SetGlobalTexture(m_LocalShadowmapID, m_LocalShadowmapTexture); |
|||
cmd.SetGlobalMatrixArray(LocalShadowConstantBuffer._LocalWorldToShadowAtlas, m_LocalShadowMatrices); |
|||
cmd.SetGlobalFloatArray(LocalShadowConstantBuffer._LocalShadowStrength, m_LocalShadowStrength); |
|||
cmd.SetGlobalVector(LocalShadowConstantBuffer._LocalShadowOffset0, new Vector4(-invHalfShadowAtlasWidth, -invHalfShadowAtlasHeight, 0.0f, 0.0f)); |
|||
cmd.SetGlobalVector(LocalShadowConstantBuffer._LocalShadowOffset1, new Vector4(invHalfShadowAtlasWidth, -invHalfShadowAtlasHeight, 0.0f, 0.0f)); |
|||
cmd.SetGlobalVector(LocalShadowConstantBuffer._LocalShadowOffset2, new Vector4(-invHalfShadowAtlasWidth, invHalfShadowAtlasHeight, 0.0f, 0.0f)); |
|||
cmd.SetGlobalVector(LocalShadowConstantBuffer._LocalShadowOffset3, new Vector4(invHalfShadowAtlasWidth, invHalfShadowAtlasHeight, 0.0f, 0.0f)); |
|||
cmd.SetGlobalVector(LocalShadowConstantBuffer._LocalShadowmapSize, new Vector4(invShadowAtlasWidth, invShadowAtlasHeight, |
|||
m_ShadowSettings.localShadowAtlasWidth, m_ShadowSettings.localShadowAtlasHeight)); |
|||
context.ExecuteCommandBuffer(cmd); |
|||
cmd.Clear(); |
|||
} |
|||
}; |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 51015cd4dddd59d4b95f01cf645067bd |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
#ifndef LIGHTWEIGHT_INPUT_SURFACE_COMMON_INCLUDED |
|||
#define LIGHTWEIGHT_INPUT_SURFACE_COMMON_INCLUDED |
|||
|
|||
#include "Core.hlsl" |
|||
#include "CoreRP/ShaderLibrary/Packing.hlsl" |
|||
#include "CoreRP/ShaderLibrary/CommonMaterial.hlsl" |
|||
|
|||
TEXTURE2D(_MainTex); SAMPLER(sampler_MainTex); |
|||
TEXTURE2D(_BumpMap); SAMPLER(sampler_BumpMap); |
|||
TEXTURE2D(_EmissionMap); SAMPLER(sampler_EmissionMap); |
|||
|
|||
// Must match Lightweigth ShaderGraph master node |
|||
struct SurfaceData |
|||
{ |
|||
half3 albedo; |
|||
half3 specular; |
|||
half metallic; |
|||
half smoothness; |
|||
half3 normalTS; |
|||
half3 emission; |
|||
half occlusion; |
|||
half alpha; |
|||
}; |
|||
|
|||
/////////////////////////////////////////////////////////////////////////////// |
|||
// Material Property Helpers // |
|||
/////////////////////////////////////////////////////////////////////////////// |
|||
half Alpha(half albedoAlpha, half4 color, half cutoff) |
|||
{ |
|||
#if !defined(_SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A) && !defined(_GLOSSINESS_FROM_BASE_ALPHA) |
|||
half alpha = albedoAlpha * color.a; |
|||
#else |
|||
half alpha = color.a; |
|||
#endif |
|||
|
|||
#if defined(_ALPHATEST_ON) |
|||
clip(alpha - cutoff); |
|||
#endif |
|||
|
|||
return alpha; |
|||
} |
|||
|
|||
half4 SampleAlbedoAlpha(float2 uv, TEXTURE2D_ARGS(albedoAlphaMap, sampler_albedoAlphaMap)) |
|||
{ |
|||
return SAMPLE_TEXTURE2D(albedoAlphaMap, sampler_albedoAlphaMap, uv); |
|||
} |
|||
|
|||
half3 SampleNormal(float2 uv, TEXTURE2D_ARGS(bumpMap, sampler_bumpMap), half scale = 1.0h) |
|||
{ |
|||
#if _NORMALMAP |
|||
half4 n = SAMPLE_TEXTURE2D(bumpMap, sampler_bumpMap, uv); |
|||
#if BUMP_SCALE_NOT_SUPPORTED |
|||
return UnpackNormal(n); |
|||
#else |
|||
return UnpackNormalScale(n, scale); |
|||
#endif |
|||
#else |
|||
return half3(0.0h, 0.0h, 1.0h); |
|||
#endif |
|||
} |
|||
|
|||
half3 SampleEmission(float2 uv, half3 emissionColor, TEXTURE2D_ARGS(emissionMap, sampler_emissionMap)) |
|||
{ |
|||
#ifndef _EMISSION |
|||
return 0; |
|||
#else |
|||
return SAMPLE_TEXTURE2D(emissionMap, sampler_emissionMap, uv).rgb * emissionColor; |
|||
#endif |
|||
} |
|||
|
|||
#endif // LIGHTWEIGHT_INPUT_SURFACE_COMMON_INCLUDED |
|
|||
#ifndef LIGHTWEIGHT_INPUT_SURFACE_PBR_INCLUDED |
|||
#define LIGHTWEIGHT_INPUT_SURFACE_PBR_INCLUDED |
|||
|
|||
#include "Core.hlsl" |
|||
#include "CoreRP/ShaderLibrary/CommonMaterial.hlsl" |
|||
#include "InputSurfaceCommon.hlsl" |
|||
|
|||
CBUFFER_START(UnityPerMaterial) |
|||
float4 _MainTex_ST; |
|||
half4 _Color; |
|||
half4 _SpecColor; |
|||
half4 _EmissionColor; |
|||
half _Cutoff; |
|||
half _Glossiness; |
|||
half _GlossMapScale; |
|||
half _Metallic; |
|||
half _BumpScale; |
|||
half _OcclusionStrength; |
|||
CBUFFER_END |
|||
|
|||
TEXTURE2D(_OcclusionMap); SAMPLER(sampler_OcclusionMap); |
|||
TEXTURE2D(_MetallicGlossMap); SAMPLER(sampler_MetallicGlossMap); |
|||
TEXTURE2D(_SpecGlossMap); SAMPLER(sampler_SpecGlossMap); |
|||
|
|||
#ifdef _SPECULAR_SETUP |
|||
#define SAMPLE_METALLICSPECULAR(uv) SAMPLE_TEXTURE2D(_SpecGlossMap, sampler_SpecGlossMap, uv) |
|||
#else |
|||
#define SAMPLE_METALLICSPECULAR(uv) SAMPLE_TEXTURE2D(_MetallicGlossMap, sampler_MetallicGlossMap, uv) |
|||
#endif |
|||
|
|||
half4 SampleMetallicSpecGloss(float2 uv, half albedoAlpha) |
|||
{ |
|||
half4 specGloss; |
|||
|
|||
#ifdef _METALLICSPECGLOSSMAP |
|||
specGloss = SAMPLE_METALLICSPECULAR(uv); |
|||
#ifdef _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A |
|||
specGloss.a = albedoAlpha * _GlossMapScale; |
|||
#else |
|||
specGloss.a *= _GlossMapScale; |
|||
#endif |
|||
#else // _METALLICSPECGLOSSMAP |
|||
#if _SPECULAR_SETUP |
|||
specGloss.rgb = _SpecColor.rgb; |
|||
#else |
|||
specGloss.rgb = _Metallic.rrr; |
|||
#endif |
|||
|
|||
#ifdef _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A |
|||
specGloss.a = albedoAlpha * _GlossMapScale; |
|||
#else |
|||
specGloss.a = _Glossiness; |
|||
#endif |
|||
#endif |
|||
|
|||
return specGloss; |
|||
} |
|||
|
|||
half SampleOcclusion(float2 uv) |
|||
{ |
|||
#ifdef _OCCLUSIONMAP |
|||
#if (SHADER_TARGET < 30) |
|||
// SM20: instruction count limitation |
|||
// SM20: simpler occlusion |
|||
return SAMPLE_TEXTURE2D(_OcclusionMap, sampler_OcclusionMap, uv).g; |
|||
#else |
|||
half occ = SAMPLE_TEXTURE2D(_OcclusionMap, sampler_OcclusionMap, uv).g; |
|||
return LerpWhiteTo(occ, _OcclusionStrength); |
|||
#endif |
|||
#else |
|||
return 1.0; |
|||
#endif |
|||
} |
|||
|
|||
inline void InitializeStandardLitSurfaceData(float2 uv, out SurfaceData outSurfaceData) |
|||
{ |
|||
half4 albedoAlpha = SampleAlbedoAlpha(uv, TEXTURE2D_PARAM(_MainTex, sampler_MainTex)); |
|||
outSurfaceData.alpha = Alpha(albedoAlpha.a, _Color, _Cutoff); |
|||
|
|||
half4 specGloss = SampleMetallicSpecGloss(uv, albedoAlpha.a); |
|||
outSurfaceData.albedo = albedoAlpha.rgb * _Color.rgb; |
|||
|
|||
#if _SPECULAR_SETUP |
|||
outSurfaceData.metallic = 1.0h; |
|||
outSurfaceData.specular = specGloss.rgb; |
|||
#else |
|||
outSurfaceData.metallic = specGloss.r; |
|||
outSurfaceData.specular = half3(0.0h, 0.0h, 0.0h); |
|||
#endif |
|||
|
|||
outSurfaceData.smoothness = specGloss.a; |
|||
outSurfaceData.normalTS = SampleNormal(uv, TEXTURE2D_PARAM(_BumpMap, sampler_BumpMap), _BumpScale); |
|||
outSurfaceData.occlusion = SampleOcclusion(uv); |
|||
outSurfaceData.emission = SampleEmission(uv, _EmissionColor.rgb, TEXTURE2D_PARAM(_EmissionMap, sampler_EmissionMap)); |
|||
} |
|||
|
|||
#endif // LIGHTWEIGHT_INPUT_SURFACE_PBR_INCLUDED |
|
|||
fileFormatVersion: 2 |
|||
guid: c46f85bf266d7496d9b3659acfbdc711 |
|||
ShaderImporter: |
|||
externalObjects: {} |
|||
defaultTextures: [] |
|||
nonModifiableTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
#ifndef LIGHTWEIGHT_INPUT_SURFACE_SIMPLE_INCLUDED |
|||
#define LIGHTWEIGHT_INPUT_SURFACE_SIMPLE_INCLUDED |
|||
|
|||
#include "Core.hlsl" |
|||
#include "InputSurfaceCommon.hlsl" |
|||
|
|||
CBUFFER_START(UnityPerMaterial) |
|||
float4 _MainTex_ST; |
|||
half4 _Color; |
|||
half4 _SpecColor; |
|||
half4 _EmissionColor; |
|||
half _Cutoff; |
|||
half _Shininess; |
|||
CBUFFER_END |
|||
|
|||
TEXTURE2D(_SpecGlossMap); SAMPLER(sampler_SpecGlossMap); |
|||
|
|||
half4 SampleSpecularGloss(half2 uv, half alpha, half4 specColor, TEXTURE2D_ARGS(specGlossMap, sampler_specGlossMap)) |
|||
{ |
|||
half4 specularGloss = half4(0.0h, 0.0h, 0.0h, 1.0h); |
|||
#ifdef _SPECGLOSSMAP |
|||
specularGloss = SAMPLE_TEXTURE2D(specGlossMap, sampler_specGlossMap, uv); |
|||
#elif defined(_SPECULAR_COLOR) |
|||
specularGloss = specColor; |
|||
#endif |
|||
|
|||
#ifdef _GLOSSINESS_FROM_BASE_ALPHA |
|||
specularGloss.a = alpha; |
|||
#endif |
|||
return specularGloss; |
|||
} |
|||
|
|||
#endif // LIGHTWEIGHT_INPUT_SURFACE_SIMPLE_INCLUDED |
|
|||
fileFormatVersion: 2 |
|||
guid: ad863d097888f42c6bcf419efb2946c5 |
|||
ShaderImporter: |
|||
externalObjects: {} |
|||
defaultTextures: [] |
|||
nonModifiableTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
#ifndef LIGHTWEIGHT_INPUT_SURFACE_UNLIT_INCLUDED |
|||
#define LIGHTWEIGHT_INPUT_SURFACE_UNLIT_INCLUDED |
|||
|
|||
#include "Core.hlsl" |
|||
#include "InputSurfaceCommon.hlsl" |
|||
|
|||
CBUFFER_START(UnityPerMaterial) |
|||
float4 _MainTex_ST; |
|||
half4 _Color; |
|||
half _Cutoff; |
|||
half _Glossiness; |
|||
half _Metallic; |
|||
CBUFFER_END |
|||
|
|||
#endif // LIGHTWEIGHT_INPUT_SURFACE_UNLIT_INCLUDED |
|
|||
fileFormatVersion: 2 |
|||
guid: e7ba75cc852b14b7f934978b5697bf1b |
|||
ShaderImporter: |
|||
externalObjects: {} |
|||
defaultTextures: [] |
|||
nonModifiableTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
#ifndef LIGHTWEIGHT_PASS_LIT_INCLUDED |
|||
#define LIGHTWEIGHT_PASS_LIT_INCLUDED |
|||
|
|||
#include "LWRP/ShaderLibrary/Lighting.hlsl" |
|||
|
|||
struct LightweightVertexInput |
|||
{ |
|||
float4 vertex : POSITION; |
|||
float3 normal : NORMAL; |
|||
float4 tangent : TANGENT; |
|||
float2 texcoord : TEXCOORD0; |
|||
float2 lightmapUV : TEXCOORD1; |
|||
UNITY_VERTEX_INPUT_INSTANCE_ID |
|||
}; |
|||
|
|||
struct LightweightVertexOutput |
|||
{ |
|||
float2 uv : TEXCOORD0; |
|||
DECLARE_LIGHTMAP_OR_SH(lightmapUV, vertexSH, 1); |
|||
|
|||
float4 posWSShininess : TEXCOORD2; // xyz: posWS, w: Shininess * 128 |
|||
|
|||
#ifdef _NORMALMAP |
|||
half4 normal : TEXCOORD3; // xyz: normal, w: viewDir.x |
|||
half4 tangent : TEXCOORD4; // xyz: tangent, w: viewDir.y |
|||
half4 binormal : TEXCOORD5; // xyz: binormal, w: viewDir.z |
|||
#else |
|||
half3 normal : TEXCOORD3; |
|||
half3 viewDir : TEXCOORD4; |
|||
#endif |
|||
|
|||
half4 fogFactorAndVertexLight : TEXCOORD6; // x: fogFactor, yzw: vertex light |
|||
|
|||
#ifdef _SHADOWS_ENABLED |
|||
float4 shadowCoord : TEXCOORD7; |
|||
#endif |
|||
|
|||
float4 clipPos : SV_POSITION; |
|||
UNITY_VERTEX_INPUT_INSTANCE_ID |
|||
UNITY_VERTEX_OUTPUT_STEREO |
|||
}; |
|||
|
|||
void InitializeInputData(LightweightVertexOutput IN, half3 normalTS, out InputData inputData) |
|||
{ |
|||
inputData.positionWS = IN.posWSShininess.xyz; |
|||
|
|||
#ifdef _NORMALMAP |
|||
half3 viewDir = half3(IN.normal.w, IN.tangent.w, IN.binormal.w); |
|||
inputData.normalWS = TangentToWorldNormal(normalTS, IN.tangent.xyz, IN.binormal.xyz, IN.normal.xyz); |
|||
#else |
|||
half3 viewDir = IN.viewDir; |
|||
inputData.normalWS = FragmentNormalWS(IN.normal); |
|||
#endif |
|||
|
|||
inputData.viewDirectionWS = FragmentViewDirWS(viewDir); |
|||
#ifdef _SHADOWS_ENABLED |
|||
inputData.shadowCoord = IN.shadowCoord; |
|||
#else |
|||
inputData.shadowCoord = float4(0, 0, 0, 0); |
|||
#endif |
|||
inputData.fogCoord = IN.fogFactorAndVertexLight.x; |
|||
inputData.vertexLighting = IN.fogFactorAndVertexLight.yzw; |
|||
inputData.bakedGI = SAMPLE_GI(IN.lightmapUV, IN.vertexSH, inputData.normalWS); |
|||
} |
|||
|
|||
/////////////////////////////////////////////////////////////////////////////// |
|||
// Vertex and Fragment functions // |
|||
/////////////////////////////////////////////////////////////////////////////// |
|||
|
|||
// Used in Standard (Simple Lighting) shader |
|||
LightweightVertexOutput LitPassVertexSimple(LightweightVertexInput v) |
|||
{ |
|||
LightweightVertexOutput o = (LightweightVertexOutput)0; |
|||
|
|||
UNITY_SETUP_INSTANCE_ID(v); |
|||
UNITY_TRANSFER_INSTANCE_ID(v, o); |
|||
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); |
|||
|
|||
o.uv = TRANSFORM_TEX(v.texcoord, _MainTex); |
|||
|
|||
o.posWSShininess.xyz = TransformObjectToWorld(v.vertex.xyz); |
|||
o.posWSShininess.w = _Shininess * 128.0; |
|||
o.clipPos = TransformWorldToHClip(o.posWSShininess.xyz); |
|||
|
|||
half3 viewDir = VertexViewDirWS(GetCameraPositionWS() - o.posWSShininess.xyz); |
|||
|
|||
#ifdef _NORMALMAP |
|||
o.normal.w = viewDir.x; |
|||
o.tangent.w = viewDir.y; |
|||
o.binormal.w = viewDir.z; |
|||
#else |
|||
o.viewDir = viewDir; |
|||
#endif |
|||
|
|||
// initializes o.normal and if _NORMALMAP also o.tangent and o.binormal |
|||
OUTPUT_NORMAL(v, o); |
|||
|
|||
// We either sample GI from lightmap or SH. |
|||
// Lightmap UV and vertex SH coefficients use the same interpolator ("float2 lightmapUV" for lightmap or "half3 vertexSH" for SH) |
|||
// see DECLARE_LIGHTMAP_OR_SH macro. |
|||
// The following funcions initialize the correct variable with correct data |
|||
OUTPUT_LIGHTMAP_UV(v.lightmapUV, unity_LightmapST, o.lightmapUV); |
|||
OUTPUT_SH(o.normal.xyz, o.vertexSH); |
|||
|
|||
half3 vertexLight = VertexLighting(o.posWSShininess.xyz, o.normal.xyz); |
|||
half fogFactor = ComputeFogFactor(o.clipPos.z); |
|||
o.fogFactorAndVertexLight = half4(fogFactor, vertexLight); |
|||
|
|||
#ifdef _SHADOWS_ENABLED |
|||
#if SHADOWS_SCREEN |
|||
o.shadowCoord = ComputeShadowCoord(o.clipPos); |
|||
#else |
|||
o.shadowCoord = TransformWorldToShadowCoord(o.posWSShininess.xyz); |
|||
#endif |
|||
#endif |
|||
|
|||
return o; |
|||
} |
|||
|
|||
// Used for StandardSimpleLighting shader |
|||
half4 LitPassFragmentSimple(LightweightVertexOutput IN) : SV_Target |
|||
{ |
|||
UNITY_SETUP_INSTANCE_ID(IN); |
|||
|
|||
float2 uv = IN.uv; |
|||
half4 diffuseAlpha = SampleAlbedoAlpha(uv, TEXTURE2D_PARAM(_MainTex, sampler_MainTex)); |
|||
half3 diffuse = diffuseAlpha.rgb * _Color.rgb; |
|||
|
|||
half alpha = diffuseAlpha.a * _Color.a; |
|||
AlphaDiscard(alpha, _Cutoff); |
|||
#ifdef _ALPHAPREMULTIPLY_ON |
|||
diffuse *= alpha; |
|||
#endif |
|||
|
|||
half3 normalTS = SampleNormal(uv, TEXTURE2D_PARAM(_BumpMap, sampler_BumpMap)); |
|||
half3 emission = SampleEmission(uv, _EmissionColor.rgb, TEXTURE2D_PARAM(_EmissionMap, sampler_EmissionMap)); |
|||
half4 specularGloss = SampleSpecularGloss(uv, diffuseAlpha.a, _SpecColor, TEXTURE2D_PARAM(_SpecGlossMap, sampler_SpecGlossMap)); |
|||
half shininess = IN.posWSShininess.w; |
|||
|
|||
InputData inputData; |
|||
InitializeInputData(IN, normalTS, inputData); |
|||
|
|||
return LightweightFragmentBlinnPhong(inputData, diffuse, specularGloss, shininess, emission, alpha); |
|||
}; |
|||
|
|||
#endif |
|
|||
fileFormatVersion: 2 |
|||
guid: ee447e65526c7db45a978c16b28827a9 |
|||
timeCreated: 1488965025 |
|||
licenseType: Pro |
|||
ShaderImporter: |
|||
defaultTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
#ifndef LIGHTWEIGHT_PASS_META_PBR_INCLUDED |
|||
#define LIGHTWEIGHT_PASS_META_PBR_INCLUDED |
|||
|
|||
#include "LightweightPassMetaCommon.hlsl" |
|||
|
|||
half4 LightweightFragmentMeta(MetaVertexOuput i) : SV_Target |
|||
{ |
|||
SurfaceData surfaceData; |
|||
InitializeStandardLitSurfaceData(i.uv, surfaceData); |
|||
|
|||
BRDFData brdfData; |
|||
InitializeBRDFData(surfaceData.albedo, surfaceData.metallic, surfaceData.specular, surfaceData.smoothness, surfaceData.alpha, brdfData); |
|||
|
|||
MetaInput o; |
|||
o.Albedo = brdfData.diffuse + brdfData.specular * brdfData.roughness * 0.5; |
|||
o.SpecularColor = surfaceData.specular; |
|||
o.Emission = surfaceData.emission; |
|||
|
|||
return MetaFragment(o); |
|||
} |
|||
|
|||
#endif // LIGHTWEIGHT_PASS_META_PBR_INCLUDED |
|
|||
fileFormatVersion: 2 |
|||
guid: dcf4e762d48204e33b575f8007e3d563 |
|||
ShaderImporter: |
|||
externalObjects: {} |
|||
defaultTextures: [] |
|||
nonModifiableTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
部分文件因为文件数量过多而无法显示
撰写
预览
正在加载...
取消
保存
Reference in new issue