浏览代码

Added WaterFXPass to MyLWRenderer

Minor project cleanup
Added packed PBR shader
/main
Andre McGrail 7 年前
当前提交
dc6b492f
共有 27 个文件被更改,包括 558 次插入989 次删除
  1. 9
      Assets/LightweightAsset.asset
  2. 5
      Assets/Shaders/WaterFXFoamOnly.shader
  3. 4
      Assets/Shaders/WaterFXShader.shader
  4. 114
      Assets/scenes/Island.unity
  5. 2
      ProjectSettings/ProjectVersion.txt
  6. 8
      Assets/Scripts/Rendering.meta
  7. 8
      Assets/Shaders/PackedPBR.meta
  8. 8
      Assets/scenes/Testing/PackedPBR shader.meta
  9. 170
      Assets/Scripts/Rendering/MyLWRenderer.cs
  10. 67
      Assets/Scripts/Rendering/WaterFXPass.cs
  11. 11
      Assets/Scripts/Rendering/WaterFXPass.cs.meta
  12. 32
      Assets/Shaders/PackedPBR/InputSurfacePackedDialectric.hlsl
  13. 9
      Assets/Shaders/PackedPBR/InputSurfacePackedDialectric.hlsl.meta
  14. 151
      Assets/Shaders/PackedPBR/LightweightPackedDialectric.shader
  15. 9
      Assets/Shaders/PackedPBR/LightweightPackedDialectric.shader.meta
  16. 580
      Assets/Generated_PBR.shader
  17. 9
      Assets/Generated_PBR.shader.meta
  18. 61
      Assets/NewUnlitShader.shader
  19. 9
      Assets/NewUnlitShader.shader.meta
  20. 85
      Assets/Test.mat
  21. 8
      Assets/Test.mat.meta
  22. 188
      Assets/MyLWRenderer.cs
  23. 0
      /Assets/Shaders/PBR_HUE.ShaderGraph
  24. 0
      /Assets/Shaders/PBR_HUE.ShaderGraph.meta
  25. 0
      /Assets/Scripts/Rendering/MyLWRenderer.cs.meta

9
Assets/LightweightAsset.asset


k_AssetVersion: 3
m_MaxPixelLights: 1
m_SupportsVertexLight: 0
m_RequireDepthTexture: 0
m_RequireDepthTexture: 1
m_RequireSoftParticles: 0
m_RequireOpaqueTexture: 1
m_OpaqueDownsampling: 1

m_KeepLocalShadowVariants: 1
m_KeepSoftShadowVariants: 1
m_ResourcesAsset: {fileID: 11400000, guid: aac5a08c32552a14c89394b703f1978a, type: 2}
m_SavedXRConfig:
renderScale: 1
viewportScale: 1
useOcclusionMesh: 1
occlusionMaskScale: 1
showDeviceView: 1
gameViewRenderMode: 3
m_ShadowType: 2

5
Assets/Shaders/WaterFXFoamOnly.shader


Pass
{
Name "WaterFX"
Tags{"LightMode" = "WaterFX"}
// make fog work
#pragma multi_compile_fog
#define _NORMALMAP 1

4
Assets/Shaders/WaterFXShader.shader


Pass
{
Name "WaterFX"
Tags{"LightMode" = "WaterFX"}
// make fog work
#pragma multi_compile_fog
#pragma shader_feature _INVERT_ON
#define _NORMALMAP 1

114
Assets/scenes/Island.unity


m_CorrespondingSourceObject: {fileID: 4407848929593064, guid: 93a21ad838562455fbfdd84d54fca009,
type: 2}
m_PrefabInternal: {fileID: 2093689}
--- !u!28 &5468263
Texture2D:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_Name:
m_ImageContentsHash:
serializedVersion: 2
Hash: 00000000000000000000000000000000
m_ForcedFallbackFormat: 4
m_DownscaleFallback: 0
serializedVersion: 2
m_Width: 128
m_Height: 4
m_CompleteImageSize: 2048
m_TextureFormat: 5
m_MipCount: 1
m_IsReadable: 1
m_StreamingMipmaps: 0
m_StreamingMipmapsPriority: 0
m_AlphaIsTransparency: 0
m_ImageCount: 1
m_TextureDimension: 2
m_TextureSettings:
serializedVersion: 2
m_FilterMode: 1
m_Aniso: 1
m_MipBias: 0
m_WrapU: 1
m_WrapV: 1
m_WrapW: 1
m_LightmapFormat: 0
m_ColorSpace: 1
image data: 2048
_typelessdata: ffffffffffe9fcfcffd4f8f8ffbef5f5ffa8f2f2ff93eeeeff7debebff67e8e8ff51e4e4ff3ce1e1ff26dedeff22dbdbff21d8d8ff20d4d5ff1fd1d2ff1ececfff1dcbccff1cc8c9ff1bc5c6ff1ac1c3ff19bec0ff18bbbdff17b8baff16b5b7ff15b2b4ff14aeb1ff13abaeff12a8abff12a5a8ff11a2a5ff109fa2ff0f9c9fff0e989cff0d9599ff0c9296ff0b8f93ff0a8c90ff09898dff08858aff078287ff067f84ff057d82ff057b81ff057a81ff057981ff057880ff057680ff05757fff05747fff04737fff04727eff04707eff046f7dff046e7dff046d7dff046b7cff046a7cff03697bff03687bff03667bff03657aff03647aff036379ff036179ff036079ff025f78ff025e78ff025d77ff025b77ff025a77ff025976ff025876ff025675ff025575ff015475ff015374ff015174ff015073ff014f73ff014e73ff014c72ff014b72ff004a71ff004971ff004871ff004670ff00456eff00436bff004169ff004066ff003e63ff003d61ff003b5eff00395cff003859ff003656ff003454ff003351ff00314eff002f4cff002e49ff002c47ff002b44ff002941ff00273fff00263cff00243aff002237ff002134ff001f32ff001d2fff001c2cff001a2aff001927ff001725ff001522ff00141fff00121dff00101aff000f18ff000d15ff000b12ff000a10ff00080dff00070aff000508ff000305ff000203ff000000ff010505ff020b09ff03100eff041612ff051b17ff06211bff072620ff092c24ff0a3129ff0b362dff0c3c32ff0d4136ff0e473bff0f4c3fff105244ff115748ff125d4dff136251ff146756ff156957ff156957ff156a58ff156a58ff166a58ff166b58ff166b59ff166c59ff176c59ff176c5aff176d5aff176d5aff186d5bff186e5bff186e5bff196f5cff196f5cff196f5cff19705cff1a705dff1a715dff1a715dff1a715eff1b725eff1b725eff1b725fff1b735fff1c735fff1c745fff1c7460ff1c7460ff1d7560ff1d7561ff1d7661ff1d7662ff1d7863ff1d7965ff1c7b66ff1c7c68ff1c7e6aff1b7f6bff1b816dff1b826eff1a8470ff1a8572ff198773ff198975ff198a76ff188c78ff188d7aff188f7bff17907dff17927eff179380ff169582ff169683ff169885ff159986ff159b88ff149c8aff149e8bff149f8dff13a18eff13a290ff13a492ff12a593ff12a795ff12a996ff11aa98ff11ac9aff11ad9bff10af9dff10b09eff0fb2a0ff0fb3a2ff0fb5a3ff0eb6a5ff0eb8a6ff0eb9a8ff0dbbaaff0dbcabff0dbeadff0cbfaeff0cc1b0ff0cc2b2ff0bc4b3ff0bc5b5ff0ac7b6ff0ac9b8ff0acab9ff09ccbbff09cdbdff09cfbeff08d0c0ff08d2c1ff08d3c3ff07d5c5ff07d6c6ff07d8c8ff06d9c9ff06dbcbff05dccdff05deceff05dfd0ff04e1d1ff04e2d3ff04e4d5ff03e5d6ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000009ff000018ff000028ff000039ff00004aff00005aff00006aff00007aff00008aff000099ff0000a7ff0002b5ff0009c1ff0011cdff0018d8ff001fe2ff0026ebff002ef4ff0035fbff003cffff0043faff004af6ff0050f2ff0056edff005ce9ff0062e5ff0067e1ff006edcff0073d9ff0078d5ff007dd1ff0081ceff0085caff0089c7ff008ec3ff0092c0ff0095bdff0099baff009cb7ff00a0b4ff00a3b2ff00a6afff00a9adff00acaaff00aea7ff00b1a5ff00b3a3ff00b6a1ff00b89eff00bb9bff00be99ff00c097ff00c295ff00c593ff00c790ff00c98eff02cc8cff04ce89ff05d087ff07d385ff0ad682ff0cd880ff0eda7dff11dd7aff14e077ff16e375ff19e671ff1ce96eff1fec6bff22ef67ff26f264ff2af560ff2df85cff32fd58ff36ff54ff3bfe4fff40fb4bff45f947ff4bf542ff51f23cff57ef37ff5deb32ff64e72dff6ce328ff73de22ff7bd91cff83d416ff8bcf11ff95c90bff9dc305ffa7bd00ffb1b600ffbaaf00ffc4a900ffcfa2000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
m_StreamData:
offset: 0
size: 0
path:
--- !u!1001 &6044211
Prefab:
m_ObjectHideFlags: 0

m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 153441711}
m_LocalRotation: {x: 0.05242487, y: -0.8858119, z: 0.22707313, w: 0.4012813}
m_LocalRotation: {x: 0.052425224, y: -0.8858113, z: 0.22707291, w: 0.40128273}
m_LocalPosition: {x: -47.20285, y: 5.104526, z: -51.02964}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:

m_CorrespondingSourceObject: {fileID: 4759700577955508, guid: 851454441f29b4ab9a78308458eafccb,
type: 2}
m_PrefabInternal: {fileID: 577297147}
--- !u!28 &577734623
Texture2D:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_Name:
m_ImageContentsHash:
serializedVersion: 2
Hash: 00000000000000000000000000000000
m_ForcedFallbackFormat: 4
m_DownscaleFallback: 0
serializedVersion: 2
m_Width: 128
m_Height: 4
m_CompleteImageSize: 2048
m_TextureFormat: 5
m_MipCount: 1
m_IsReadable: 1
m_StreamingMipmaps: 0
m_StreamingMipmapsPriority: 0
m_AlphaIsTransparency: 0
m_ImageCount: 1
m_TextureDimension: 2
m_TextureSettings:
serializedVersion: 2
m_FilterMode: 1
m_Aniso: 1
m_MipBias: 0
m_WrapU: 1
m_WrapV: 1
m_WrapW: 1
m_LightmapFormat: 0
m_ColorSpace: 1
image data: 2048
_typelessdata: ffffffffffe9fcfcffd4f8f8ffbef5f5ffa8f2f2ff93eeeeff7debebff67e8e8ff51e4e4ff3ce1e1ff26dedeff22dbdbff21d8d8ff20d4d5ff1fd1d2ff1ececfff1dcbccff1cc8c9ff1bc5c6ff1ac1c3ff19bec0ff18bbbdff17b8baff16b5b7ff15b2b4ff14aeb1ff13abaeff12a8abff12a5a8ff11a2a5ff109fa2ff0f9c9fff0e989cff0d9599ff0c9296ff0b8f93ff0a8c90ff09898dff08858aff078287ff067f84ff057d82ff057b81ff057a81ff057981ff057880ff057680ff05757fff05747fff04737fff04727eff04707eff046f7dff046e7dff046d7dff046b7cff046a7cff03697bff03687bff03667bff03657aff03647aff036379ff036179ff036079ff025f78ff025e78ff025d77ff025b77ff025a77ff025976ff025876ff025675ff025575ff015475ff015374ff015174ff015073ff014f73ff014e73ff014c72ff014b72ff004a71ff004971ff004871ff004670ff00456eff00436bff004169ff004066ff003e63ff003d61ff003b5eff00395cff003859ff003656ff003454ff003351ff00314eff002f4cff002e49ff002c47ff002b44ff002941ff00273fff00263cff00243aff002237ff002134ff001f32ff001d2fff001c2cff001a2aff001927ff001725ff001522ff00141fff00121dff00101aff000f18ff000d15ff000b12ff000a10ff00080dff00070aff000508ff000305ff000203ff000000ff010505ff020b09ff03100eff041612ff051b17ff06211bff072620ff092c24ff0a3129ff0b362dff0c3c32ff0d4136ff0e473bff0f4c3fff105244ff115748ff125d4dff136251ff146756ff156957ff156957ff156a58ff156a58ff166a58ff166b58ff166b59ff166c59ff176c59ff176c5aff176d5aff176d5aff186d5bff186e5bff186e5bff196f5cff196f5cff196f5cff19705cff1a705dff1a715dff1a715dff1a715eff1b725eff1b725eff1b725fff1b735fff1c735fff1c745fff1c7460ff1c7460ff1d7560ff1d7561ff1d7661ff1d7662ff1d7863ff1d7965ff1c7b66ff1c7c68ff1c7e6aff1b7f6bff1b816dff1b826eff1a8470ff1a8572ff198773ff198975ff198a76ff188c78ff188d7aff188f7bff17907dff17927eff179380ff169582ff169683ff169885ff159986ff159b88ff149c8aff149e8bff149f8dff13a18eff13a290ff13a492ff12a593ff12a795ff12a996ff11aa98ff11ac9aff11ad9bff10af9dff10b09eff0fb2a0ff0fb3a2ff0fb5a3ff0eb6a5ff0eb8a6ff0eb9a8ff0dbbaaff0dbcabff0dbeadff0cbfaeff0cc1b0ff0cc2b2ff0bc4b3ff0bc5b5ff0ac7b6ff0ac9b8ff0acab9ff09ccbbff09cdbdff09cfbeff08d0c0ff08d2c1ff08d3c3ff07d5c5ff07d6c6ff07d8c8ff06d9c9ff06dbcbff05dccdff05deceff05dfd0ff04e1d1ff04e2d3ff04e4d5ff03e5d6ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000009ff000018ff000028ff000039ff00004aff00005aff00006aff00007aff00008aff000099ff0000a7ff0002b5ff0009c1ff0011cdff0018d8ff001fe2ff0026ebff002ef4ff0035fbff003cffff0043faff004af6ff0050f2ff0056edff005ce9ff0062e5ff0067e1ff006edcff0073d9ff0078d5ff007dd1ff0081ceff0085caff0089c7ff008ec3ff0092c0ff0095bdff0099baff009cb7ff00a0b4ff00a3b2ff00a6afff00a9adff00acaaff00aea7ff00b1a5ff00b3a3ff00b6a1ff00b89eff00bb9bff00be99ff00c097ff00c295ff00c593ff00c790ff00c98eff02cc8cff04ce89ff05d087ff07d385ff0ad682ff0cd880ff0eda7dff11dd7aff14e077ff16e375ff19e671ff1ce96eff1fec6bff22ef67ff26f264ff2af560ff2df85cff32fd58ff36ff54ff3bfe4fff40fb4bff45f947ff4bf542ff51f23cff57ef37ff5deb32ff64e72dff6ce328ff73de22ff7bd91cff83d416ff8bcf11ff95c90bff9dc305ffa7bd00ffb1b600ffbaaf00ffc4a900ffcfa2000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
m_StreamData:
offset: 0
size: 0
path:
--- !u!4 &578482325 stripped
Transform:
m_CorrespondingSourceObject: {fileID: 4590211134741006, guid: cf92f64c366a83f42b7636e1086fec18,

- component: {fileID: 1017609899}
- component: {fileID: 1017609903}
- component: {fileID: 1017609900}
- component: {fileID: 1017609901}
- component: {fileID: 1017609902}
m_Layer: 0
m_Name: Main Camera
m_TagString: MainCamera

m_Depth: -5
m_CullingMask:
serializedVersion: 2
m_Bits: 4294966783
m_Bits: 4294967295
m_RenderingPath: -1
m_TargetTexture: {fileID: 0}
m_TargetDisplay: 0

m_Script: {fileID: 11500000, guid: 8f298356512114623ab427c6707d5eae, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!114 &1017609901
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1017609894}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: ba6af5eaa8d821f4e93093fd37ee3484, type: 3}
m_Name:
m_EditorClassIdentifier:
renderShadows: 1
requiresDepthTexture: 1
requiresColorTexture: 1
m_Version: 1
--- !u!114 &1017609902
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1017609894}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 62d2ec625e93e8d40b72db412b9db648, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!114 &1017609903
MonoBehaviour:
m_ObjectHideFlags: 0

m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1143740434}
m_LocalRotation: {x: -0.0019954052, y: 0.94006014, z: -0.005502155, w: -0.34095865}
m_LocalRotation: {x: -0.0019920208, y: 0.9400609, z: -0.0054928837, w: -0.34095666}
m_LocalPosition: {x: 42, y: 2.51, z: 62.1}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:

m_Script: {fileID: 11500000, guid: b6edb8448c9b94f018953ca2a6fa5891, type: 3}
m_Name:
m_EditorClassIdentifier:
_rampTexture: {fileID: 5468263}
_rampTexture: {fileID: 577734623}
_waves:
- amplitude: 0.4072035
direction: -167.8483

2
ProjectSettings/ProjectVersion.txt


m_EditorVersion: 2018.2.0b8
m_EditorVersion: 2018.2.0b11

8
Assets/Scripts/Rendering.meta


fileFormatVersion: 2
guid: de0358983d1724e078d3f85e29d3d0a8
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

8
Assets/Shaders/PackedPBR.meta


fileFormatVersion: 2
guid: 169ccfffe27834dd89f43a5f0edc67ec
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

8
Assets/scenes/Testing/PackedPBR shader.meta


fileFormatVersion: 2
guid: 77a2fc799d4174f6296bedcb42fe5097
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

170
Assets/Scripts/Rendering/MyLWRenderer.cs


using System;
using UnityEngine.Rendering;
namespace UnityEngine.Experimental.Rendering.LightweightPipeline
{
public class MyLWRenderer : MonoBehaviour, IRendererSetup
{
private DepthOnlyPass m_DepthOnlyPass;
private DirectionalShadowsPass m_DirectionalShadowPass;
private LocalShadowsPass m_LocalShadowPass;
private SetupForwardRenderingPass m_SetupForwardRenderingPass;
private ScreenSpaceShadowResolvePass m_ScreenSpaceShadowResovePass;
private CreateLightweightRenderTexturesPass m_CreateLightweightRenderTexturesPass;
private BeginXRRenderingPass m_BeginXrRenderingPass;
private SetupLightweightConstanstPass m_SetupLightweightConstants;
private RenderOpaqueForwardPass m_RenderOpaqueForwardPass;
private OpaquePostProcessPass m_OpaquePostProcessPass;
private DrawSkyboxPass m_DrawSkyboxPass;
private CopyDepthPass m_CopyDepthPass;
private CopyColorPass m_CopyColorPass;
private RenderTransparentForwardPass m_RenderTransparentForwardPass;
private TransparentPostProcessPass m_TransparentPostProcessPass;
private FinalBlitPass m_FinalBlitPass;
private EndXRRenderingPass m_EndXrRenderingPass;
private WaterFXPass m_WaterFXPass;
[NonSerialized]
private bool m_Initialized = false;
private void Init(LightweightForwardRenderer renderer)
{
if (m_Initialized)
return;
m_DepthOnlyPass = new DepthOnlyPass(renderer);
m_DirectionalShadowPass = new DirectionalShadowsPass(renderer);
m_LocalShadowPass = new LocalShadowsPass(renderer);
m_SetupForwardRenderingPass = new SetupForwardRenderingPass(renderer);
m_ScreenSpaceShadowResovePass = new ScreenSpaceShadowResolvePass(renderer);
m_CreateLightweightRenderTexturesPass = new CreateLightweightRenderTexturesPass(renderer);
m_BeginXrRenderingPass = new BeginXRRenderingPass(renderer);
m_SetupLightweightConstants = new SetupLightweightConstanstPass(renderer);
m_RenderOpaqueForwardPass = new RenderOpaqueForwardPass(renderer);
m_OpaquePostProcessPass = new OpaquePostProcessPass(renderer);
m_DrawSkyboxPass = new DrawSkyboxPass(renderer);
m_CopyDepthPass = new CopyDepthPass(renderer);
m_CopyColorPass = new CopyColorPass(renderer);
m_RenderTransparentForwardPass = new RenderTransparentForwardPass(renderer);
m_TransparentPostProcessPass = new TransparentPostProcessPass(renderer);
m_FinalBlitPass = new FinalBlitPass(renderer);
m_EndXrRenderingPass = new EndXRRenderingPass(renderer);
m_WaterFXPass = new WaterFXPass(renderer);
m_Initialized = true;
}
public void Setup(LightweightForwardRenderer renderer, ref ScriptableRenderContext context,
ref CullResults cullResults, ref RenderingData renderingData)
{
Init(renderer);
renderer.Clear();
renderer.SetupPerObjectLightIndices(ref cullResults, ref renderingData.lightData);
RenderTextureDescriptor baseDescriptor = renderer.CreateRTDesc(ref renderingData.cameraData);
RenderTextureDescriptor shadowDescriptor = baseDescriptor;
shadowDescriptor.dimension = TextureDimension.Tex2D;
bool requiresCameraDepth = renderingData.cameraData.requiresDepthTexture;
bool requiresDepthPrepass = renderingData.shadowData.requiresScreenSpaceShadowResolve ||
renderingData.cameraData.isSceneViewCamera ||
(requiresCameraDepth &&
!LightweightForwardRenderer.CanCopyDepth(ref renderingData.cameraData));
// For now VR requires a depth prepass until we figure out how to properly resolve texture2DMS in stereo
requiresDepthPrepass |= renderingData.cameraData.isStereoEnabled;
if (renderingData.shadowData.renderDirectionalShadows)
renderer.EnqueuePass(m_DirectionalShadowPass);
if (renderingData.shadowData.renderLocalShadows)
renderer.EnqueuePass(m_LocalShadowPass);
renderer.EnqueuePass(m_SetupForwardRenderingPass);
if (requiresDepthPrepass)
{
m_DepthOnlyPass.Setup(baseDescriptor, RenderTargetHandles.DepthTexture, SampleCount.One);
renderer.EnqueuePass(m_DepthOnlyPass);
}
if (renderingData.shadowData.renderDirectionalShadows &&
renderingData.shadowData.requiresScreenSpaceShadowResolve)
{
m_ScreenSpaceShadowResovePass.Setup(baseDescriptor, RenderTargetHandles.ScreenSpaceShadowmap);
renderer.EnqueuePass(m_ScreenSpaceShadowResovePass);
}
bool requiresDepthAttachment = requiresCameraDepth && !requiresDepthPrepass;
bool requiresColorAttachment =
LightweightForwardRenderer.RequiresIntermediateColorTexture(
ref renderingData.cameraData,
baseDescriptor,
requiresDepthAttachment);
RenderTargetHandle colorHandle = (requiresColorAttachment) ? RenderTargetHandles.Color : RenderTargetHandle.BackBuffer;
RenderTargetHandle depthHandle = (requiresDepthAttachment) ? RenderTargetHandles.DepthAttachment : RenderTargetHandle.BackBuffer;
var sampleCount = (SampleCount)renderingData.cameraData.msaaSamples;
m_CreateLightweightRenderTexturesPass.Setup(baseDescriptor, colorHandle, depthHandle, sampleCount);
renderer.EnqueuePass(m_CreateLightweightRenderTexturesPass);
if (renderingData.cameraData.isStereoEnabled)
renderer.EnqueuePass(m_BeginXrRenderingPass);
renderer.EnqueuePass(m_WaterFXPass);
Camera camera = renderingData.cameraData.camera;
bool dynamicBatching = renderingData.supportsDynamicBatching;
RendererConfiguration rendererConfiguration = LightweightForwardRenderer.GetRendererConfiguration(renderingData.lightData.totalAdditionalLightsCount);
renderer.EnqueuePass(m_SetupLightweightConstants);
m_RenderOpaqueForwardPass.Setup(baseDescriptor, colorHandle, depthHandle, LightweightForwardRenderer.GetCameraClearFlag(camera), camera.backgroundColor, rendererConfiguration, dynamicBatching);
renderer.EnqueuePass(m_RenderOpaqueForwardPass);
if (renderingData.cameraData.postProcessEnabled &&
renderingData.cameraData.postProcessLayer.HasOpaqueOnlyEffects(renderer.postProcessRenderContext))
{
m_OpaquePostProcessPass.Setup(baseDescriptor, colorHandle);
renderer.EnqueuePass(m_OpaquePostProcessPass);
}
if (camera.clearFlags == CameraClearFlags.Skybox)
renderer.EnqueuePass(m_DrawSkyboxPass);
if (depthHandle != RenderTargetHandle.BackBuffer)
{
m_CopyDepthPass.Setup(depthHandle);
renderer.EnqueuePass(m_CopyDepthPass);
}
if (renderingData.cameraData.requiresOpaqueTexture)
{
m_CopyColorPass.Setup(colorHandle);
renderer.EnqueuePass(m_CopyColorPass);
}
m_RenderTransparentForwardPass.Setup(baseDescriptor, colorHandle, depthHandle, ClearFlag.None, camera.backgroundColor, rendererConfiguration, dynamicBatching);
renderer.EnqueuePass(m_RenderTransparentForwardPass);
if (renderingData.cameraData.postProcessEnabled)
{
m_TransparentPostProcessPass.Setup(baseDescriptor, colorHandle);
renderer.EnqueuePass(m_TransparentPostProcessPass);
}
else if (!renderingData.cameraData.isOffscreenRender && colorHandle != RenderTargetHandle.BackBuffer)
{
m_FinalBlitPass.Setup(baseDescriptor, colorHandle);
renderer.EnqueuePass(m_FinalBlitPass);
}
if (renderingData.cameraData.isStereoEnabled)
{
renderer.EnqueuePass(m_EndXrRenderingPass);
}
}
}
}

67
Assets/Scripts/Rendering/WaterFXPass.cs


using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Experimental.Rendering;
using UnityEngine.Experimental.Rendering.LightweightPipeline;
public class WaterFXPass : ScriptableRenderPass
{
const string k_RenderWaterFXTag = "Render Water FX";
RenderTexture m_WaterFXTexture;
public WaterFXPass(LightweightForwardRenderer renderer) : base(renderer)
{
RegisterShaderPassName("WaterFX");
}
public override void Execute(ref ScriptableRenderContext context, ref CullResults cullResults, ref RenderingData renderingData)
{
CommandBuffer cmd = CommandBufferPool.Get(k_RenderWaterFXTag);
RenderTextureDescriptor descriptor = renderer.CreateRTDesc(ref renderingData.cameraData);
descriptor.width = (int)(descriptor.width * 0.5f);
descriptor.height = (int)(descriptor.height * 0.5f);
using (new ProfilingSample(cmd, k_RenderWaterFXTag))
{
m_WaterFXTexture = RenderTexture.GetTemporary(descriptor);
m_WaterFXTexture.filterMode = FilterMode.Bilinear;
m_WaterFXTexture.wrapMode = TextureWrapMode.Clamp;
SetRenderTarget(
cmd,
m_WaterFXTexture,
RenderBufferLoadAction.DontCare,
RenderBufferStoreAction.Store,
ClearFlag.Color,
new Color(0.0f, 0.5f, 0.5f, 0.5f),
descriptor.dimension);
context.ExecuteCommandBuffer(cmd);
cmd.Clear();
var drawSettings = CreateDrawRendererSettings(renderingData.cameraData.camera, SortFlags.CommonTransparent, RendererConfiguration.None, renderingData.supportsDynamicBatching);
if (renderingData.cameraData.isStereoEnabled)
{
Camera camera = renderingData.cameraData.camera;
context.StartMultiEye(camera);
context.DrawRenderers(cullResults.visibleRenderers, ref drawSettings, renderer.transparentFilterSettings);
context.StopMultiEye(camera);
}
else
context.DrawRenderers(cullResults.visibleRenderers, ref drawSettings, renderer.transparentFilterSettings);
cmd.SetGlobalTexture("_WaterFXMap", m_WaterFXTexture);
}
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);
}
public override void Dispose(CommandBuffer cmd)
{
if (m_WaterFXTexture)
{
RenderTexture.ReleaseTemporary(m_WaterFXTexture);
m_WaterFXTexture = null;
}
}
}

11
Assets/Scripts/Rendering/WaterFXPass.cs.meta


fileFormatVersion: 2
guid: c61a0c521779544ee8bf7890846c4d21
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

32
Assets/Shaders/PackedPBR/InputSurfacePackedDialectric.hlsl


#ifndef LIGHTWEIGHT_INPUT_PACKED_DIALECTRIC_INCLUDED
#define LIGHTWEIGHT_INPUT_PACKED_DIALECTRIC_INCLUDED
#include "LWRP/ShaderLibrary/Core.hlsl"
#include "CoreRP/ShaderLibrary/CommonMaterial.hlsl"
#include "LWRP/ShaderLibrary/InputSurfaceCommon.hlsl"
CBUFFER_START(UnityPerMaterial)
float4 _MainTex_ST;
half4 _Color; // only temp
half _Cutoff; // only temp
half _BumpScale;
CBUFFER_END
inline void InitializeStandardLitSurfaceData(float2 uv, out SurfaceData outSurfaceData)
{
half4 albedoRoughness = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, uv);
outSurfaceData.alpha = 1;
outSurfaceData.albedo = albedoRoughness.rgb;
outSurfaceData.metallic = 0;
outSurfaceData.specular = half3(0.0h, 0.0h, 0.0h);
outSurfaceData.smoothness = albedoRoughness.a;
half4 normalAO = SAMPLE_TEXTURE2D(_BumpMap, sampler_BumpMap, uv);
outSurfaceData.normalTS = normalAO.rgb * 2 - 1;
outSurfaceData.occlusion = normalAO.a;
outSurfaceData.emission = 0;
}
#endif // LIGHTWEIGHT_INPUT_PACKED_DIALECTRIC_INCLUDED

9
Assets/Shaders/PackedPBR/InputSurfacePackedDialectric.hlsl.meta


fileFormatVersion: 2
guid: 6ff1bcd73ddf944269e34f80b93fc017
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

151
Assets/Shaders/PackedPBR/LightweightPackedDialectric.shader


Shader "LightweightPipeline/PBR/Packed Dialectric"
{
Properties
{
_MainTex("Albedo", 2D) = "white" {} // RGB albedo, A roughness
_BumpMap("Normal Map", 2D) = "bump" {} // RGB normal, A AO
}
SubShader
{
// Lightweight Pipeline tag is required. If Lightweight pipeline is not set in the graphics settings
// this Subshader will fail. One can add a subshader below or fallback to Standard built-in to make this
// material work with both Lightweight Pipeline and Builtin Unity Pipeline
Tags{"RenderType" = "Opaque" "RenderPipeline" = "LightweightPipeline" "IgnoreProjector" = "True"}
LOD 300
// ------------------------------------------------------------------
// Forward pass. Shades all light in a single pass. GI + emission + Fog
Pass
{
// Lightmode matches the ShaderPassName set in LightweightPipeline.cs. SRPDefaultUnlit and passes with
// no LightMode tag are also rendered by Lightweight Pipeline
Name "StandardLit"
Tags{"LightMode" = "LightweightForward"}
//Blend[_SrcBlend][_DstBlend]
//ZWrite[_ZWrite]
//Cull[_Cull]
HLSLPROGRAM
// Required to compile gles 2.0 with standard SRP library
// All shaders must be compiled with HLSLcc and currently only gles is not using HLSLcc by default
#pragma prefer_hlslcc gles
#pragma exclude_renderers d3d11_9x
#pragma target 2.0
// -------------------------------------
// Material Keywords
#pragma shader_feature _NORMALMAP
#pragma shader_feature _OCCLUSIONMAP
// -------------------------------------
// Lightweight Pipeline keywords
#pragma multi_compile _ _ADDITIONAL_LIGHTS
#pragma multi_compile _ _VERTEX_LIGHTS
#pragma multi_compile _ _MIXED_LIGHTING_SUBTRACTIVE
#pragma multi_compile _ _SHADOWS_ENABLED
#pragma multi_compile _ _LOCAL_SHADOWS_ENABLED
#pragma multi_compile _ _SHADOWS_SOFT
#pragma multi_compile _ _SHADOWS_CASCADE
// -------------------------------------
// Unity defined keywords
#pragma multi_compile _ DIRLIGHTMAP_COMBINED
#pragma multi_compile _ LIGHTMAP_ON
#pragma multi_compile_fog
//--------------------------------------
// GPU Instancing
#pragma multi_compile_instancing
#pragma vertex LitPassVertex
#pragma fragment LitPassFragment
#include "InputSurfacePackedDialectric.hlsl"
#include "LWRP/ShaderLibrary/LightweightPassLit.hlsl"
ENDHLSL
}
Pass
{
Name "ShadowCaster"
Tags{"LightMode" = "ShadowCaster"}
ZWrite On
Cull Off
HLSLPROGRAM
// Required to compile gles 2.0 with standard srp library
#pragma prefer_hlslcc gles
#pragma exclude_renderers d3d11_9x
#pragma target 2.0
//--------------------------------------
// GPU Instancing
#pragma multi_compile_instancing
#pragma vertex ShadowPassVertex
#pragma fragment ShadowPassFragment
#include "InputSurfacePackedDialectric.hlsl"
#include "LWRP/ShaderLibrary/LightweightPassShadow.hlsl"
ENDHLSL
}
Pass
{
Name "DepthOnly"
Tags{"LightMode" = "DepthOnly"}
ZWrite On
ColorMask 0
Cull[_Cull]
HLSLPROGRAM
// Required to compile gles 2.0 with standard srp library
#pragma prefer_hlslcc gles
#pragma exclude_renderers d3d11_9x
#pragma target 2.0
#pragma vertex DepthOnlyVertex
#pragma fragment DepthOnlyFragment
//--------------------------------------
// GPU Instancing
#pragma multi_compile_instancing
#include "InputSurfacePackedDialectric.hlsl"
#include "LWRP/ShaderLibrary/LightweightPassDepthOnly.hlsl"
ENDHLSL
}
// This pass it not used during regular rendering, only for lightmap baking.
Pass
{
Name "Meta"
Tags{"LightMode" = "Meta"}
Cull Off
HLSLPROGRAM
// Required to compile gles 2.0 with standard srp library
#pragma prefer_hlslcc gles
#pragma exclude_renderers d3d11_9x
#pragma vertex LightweightVertexMeta
#pragma fragment LightweightFragmentMeta
#pragma shader_feature _METALLICSPECGLOSSMAP
#pragma shader_feature EDITOR_VISUALIZATION
#include "InputSurfacePackedDialectric.hlsl"
#include "LWRP/ShaderLibrary/LightweightPassMetaPBR.hlsl"
ENDHLSL
}
}
FallBack "Hidden/InternalErrorShader"
}

9
Assets/Shaders/PackedPBR/LightweightPackedDialectric.shader.meta


fileFormatVersion: 2
guid: dc06203bc9dae41408e28313d7eab8ed
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

580
Assets/Generated_PBR.shader


Shader "PBR Master"
{
Properties
{
[NoScaleOffset] _MainTex("Albedo_Roughness", 2D) = "white" {}
[NoScaleOffset] Texture2D_DE8BF47E("Normal_AO", 2D) = "white" {}
_Color("MetaColor", Color) = (1,1,1,0)
}
SubShader
{
Tags{ "RenderPipeline" = "LightweightPipeline"}
Tags
{
"RenderPipeline"="HDRenderPipeline"
"RenderType"="Opaque"
"Queue"="Geometry"
}
Pass
{
Tags{"LightMode" = "LightweightForward"}
// Material options generated by graph
Blend One Zero
Cull Back
ZTest LEqual
ZWrite On
HLSLPROGRAM
// Required to compile gles 2.0 with standard srp library
#pragma prefer_hlslcc gles
#pragma exclude_renderers d3d11_9x
#pragma target 2.0
// -------------------------------------
// Lightweight Pipeline keywords
#pragma multi_compile _ _ADDITIONAL_LIGHTS
#pragma multi_compile _ _VERTEX_LIGHTS
#pragma multi_compile _ _MIXED_LIGHTING_SUBTRACTIVE
#pragma multi_compile _ _SHADOWS_ENABLED
#pragma multi_compile _ _LOCAL_SHADOWS_ENABLED
#pragma multi_compile _ _SHADOWS_SOFT
// -------------------------------------
// Unity defined keywords
#pragma multi_compile _ DIRLIGHTMAP_COMBINED
#pragma multi_compile _ LIGHTMAP_ON
#pragma multi_compile_fog
//--------------------------------------
// GPU Instancing
#pragma multi_compile_instancing
#pragma vertex vert
#pragma fragment frag
// Defines generated by graph
#define _NORMALMAP 1
#include "LWRP/ShaderLibrary/Core.hlsl"
#include "LWRP/ShaderLibrary/Lighting.hlsl"
#include "CoreRP/ShaderLibrary/Color.hlsl"
#include "CoreRP/ShaderLibrary/UnityInstancing.hlsl"
#include "ShaderGraphLibrary/Functions.hlsl"
TEXTURE2D(_MainTex); SAMPLER(sampler_MainTex);
TEXTURE2D(Texture2D_DE8BF47E); SAMPLER(samplerTexture2D_DE8BF47E);
float4 _Color;
struct VertexDescriptionInputs
{
float3 ObjectSpacePosition;
};
struct SurfaceDescriptionInputs
{
half4 uv0;
};
void Unity_Subtract_float4(float4 A, float4 B, out float4 Out)
{
Out = A - B;
}
void Unity_Multiply_float (float4 A, float4 B, out float4 Out)
{
Out = A * B;
}
struct VertexDescription
{
float3 Position;
};
VertexDescription PopulateVertexData(VertexDescriptionInputs IN)
{
VertexDescription description = (VertexDescription)0;
description.Position = IN.ObjectSpacePosition;
return description;
}
struct SurfaceDescription
{
float3 Albedo;
float3 Normal;
float3 Emission;
float Metallic;
float Smoothness;
float Occlusion;
float Alpha;
float AlphaClipThreshold;
};
SurfaceDescription PopulateSurfaceData(SurfaceDescriptionInputs IN)
{
SurfaceDescription surface = (SurfaceDescription)0;
float4 _SampleTexture2D_903562CE_RGBA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, IN.uv0.xy);
float _SampleTexture2D_903562CE_R = _SampleTexture2D_903562CE_RGBA.r;
float _SampleTexture2D_903562CE_G = _SampleTexture2D_903562CE_RGBA.g;
float _SampleTexture2D_903562CE_B = _SampleTexture2D_903562CE_RGBA.b;
float _SampleTexture2D_903562CE_A = _SampleTexture2D_903562CE_RGBA.a;
float4 _SampleTexture2D_D53F4AE6_RGBA = SAMPLE_TEXTURE2D(Texture2D_DE8BF47E, samplerTexture2D_DE8BF47E, IN.uv0.xy);
float _SampleTexture2D_D53F4AE6_R = _SampleTexture2D_D53F4AE6_RGBA.r;
float _SampleTexture2D_D53F4AE6_G = _SampleTexture2D_D53F4AE6_RGBA.g;
float _SampleTexture2D_D53F4AE6_B = _SampleTexture2D_D53F4AE6_RGBA.b;
float _SampleTexture2D_D53F4AE6_A = _SampleTexture2D_D53F4AE6_RGBA.a;
float4 _Subtract_2BA4AC9D_Out;
Unity_Subtract_float4(_SampleTexture2D_D53F4AE6_RGBA, float4(0.5, 0.5, 0.5, 0.5), _Subtract_2BA4AC9D_Out);
float4 _Multiply_2407F12D_Out;
Unity_Multiply_float(_Subtract_2BA4AC9D_Out, float4(2, 2, 2, 0), _Multiply_2407F12D_Out);
surface.Albedo = (_SampleTexture2D_903562CE_RGBA.xyz);
surface.Normal = (_Multiply_2407F12D_Out.xyz);
surface.Emission = IsGammaSpace() ? float3(0, 0, 0) : SRGBToLinear(float3(0, 0, 0));
surface.Metallic = 0;
surface.Smoothness = _SampleTexture2D_903562CE_A;
surface.Occlusion = _SampleTexture2D_D53F4AE6_A;
surface.Alpha = 1;
surface.AlphaClipThreshold = 0;
return surface;
}
struct GraphVertexInput
{
float4 vertex : POSITION;
float3 normal : NORMAL;
float4 tangent : TANGENT;
float4 texcoord0 : TEXCOORD0;
float4 texcoord1 : TEXCOORD1;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct GraphVertexOutput
{
float4 clipPos : SV_POSITION;
DECLARE_LIGHTMAP_OR_SH(lightmapUV, vertexSH, 0);
half4 fogFactorAndVertexLight : TEXCOORD1; // x: fogFactor, yzw: vertex light
float4 shadowCoord : TEXCOORD2;
// Interpolators defined by graph
float3 WorldSpacePosition : TEXCOORD3;
float3 WorldSpaceNormal : TEXCOORD4;
float3 WorldSpaceTangent : TEXCOORD5;
float3 WorldSpaceBiTangent : TEXCOORD6;
float3 WorldSpaceViewDirection : TEXCOORD7;
half4 uv0 : TEXCOORD8;
half4 uv1 : TEXCOORD9;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
GraphVertexOutput vert (GraphVertexInput v)
{
GraphVertexOutput o = (GraphVertexOutput)0;
UNITY_SETUP_INSTANCE_ID(v);
UNITY_TRANSFER_INSTANCE_ID(v, o);
// Vertex transformations performed by graph
float3 WorldSpacePosition = mul(UNITY_MATRIX_M,v.vertex);
float3 WorldSpaceNormal = mul(v.normal,(float3x3)UNITY_MATRIX_I_M);
float3 WorldSpaceTangent = mul((float3x3)UNITY_MATRIX_M,v.tangent.xyz);
float3 WorldSpaceBiTangent = normalize(cross(WorldSpaceNormal, WorldSpaceTangent.xyz) * v.tangent.w);
float3 WorldSpaceViewDirection = SafeNormalize(_WorldSpaceCameraPos.xyz - mul(GetObjectToWorldMatrix(), float4(v.vertex.xyz, 1.0)).xyz);
float4 uv0 = v.texcoord0;
float4 uv1 = v.texcoord1;
float3 ObjectSpacePosition = mul(UNITY_MATRIX_I_M,float4(WorldSpacePosition,1.0));
VertexDescriptionInputs vdi = (VertexDescriptionInputs)0;
// Vertex description inputs defined by graph
vdi.ObjectSpacePosition = ObjectSpacePosition;
VertexDescription vd = PopulateVertexData(vdi);
v.vertex.xyz = vd.Position;
// Vertex shader outputs defined by graph
o.WorldSpacePosition = WorldSpacePosition;
o.WorldSpaceNormal = WorldSpaceNormal;
o.WorldSpaceTangent = WorldSpaceTangent;
o.WorldSpaceBiTangent = WorldSpaceBiTangent;
o.WorldSpaceViewDirection = WorldSpaceViewDirection;
o.uv0 = uv0;
o.uv1 = uv1;
float3 lwWNormal = TransformObjectToWorldNormal(v.normal);
float3 lwWorldPos = TransformObjectToWorld(v.vertex.xyz);
float4 clipPos = TransformWorldToHClip(lwWorldPos);
// 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.texcoord1, unity_LightmapST, o.lightmapUV);
OUTPUT_SH(lwWNormal, o.vertexSH);
half3 vertexLight = VertexLighting(lwWorldPos, lwWNormal);
half fogFactor = ComputeFogFactor(clipPos.z);
o.fogFactorAndVertexLight = half4(fogFactor, vertexLight);
o.clipPos = clipPos;
#ifdef _SHADOWS_ENABLED
#if SHADOWS_SCREEN
o.shadowCoord = ComputeShadowCoord(clipPos);
#else
o.shadowCoord = TransformWorldToShadowCoord(lwWorldPos);
#endif
#endif
return o;
}
half4 frag (GraphVertexOutput IN ) : SV_Target
{
UNITY_SETUP_INSTANCE_ID(IN);
// Pixel transformations performed by graph
float3 WorldSpacePosition = IN.WorldSpacePosition;
float3 WorldSpaceNormal = normalize(IN.WorldSpaceNormal);
float3 WorldSpaceTangent = IN.WorldSpaceTangent;
float3 WorldSpaceBiTangent = IN.WorldSpaceBiTangent;
float3 WorldSpaceViewDirection = normalize(IN.WorldSpaceViewDirection);
float4 uv0 = IN.uv0;
float4 uv1 = IN.uv1;
SurfaceDescriptionInputs surfaceInput = (SurfaceDescriptionInputs)0;
// Surface description inputs defined by graph
surfaceInput.uv0 = uv0;
SurfaceDescription surf = PopulateSurfaceData(surfaceInput);
float3 Albedo = float3(0.5, 0.5, 0.5);
float3 Specular = float3(0, 0, 0);
float Metallic = 1;
float3 Normal = float3(0, 0, 1);
float3 Emission = 0;
float Smoothness = 0.5;
float Occlusion = 1;
float Alpha = 1;
float AlphaClipThreshold = 0;
// Surface description remap performed by graph
Albedo = surf.Albedo;
Normal = surf.Normal;
Emission = surf.Emission;
Metallic = surf.Metallic;
Smoothness = surf.Smoothness;
Occlusion = surf.Occlusion;
Alpha = surf.Alpha;
AlphaClipThreshold = surf.AlphaClipThreshold;
InputData inputData;
inputData.positionWS = WorldSpacePosition;
#ifdef _NORMALMAP
inputData.normalWS = TangentToWorldNormal(Normal, WorldSpaceTangent, WorldSpaceBiTangent, WorldSpaceNormal);
#else
#if !SHADER_HINT_NICE_QUALITY
inputData.normalWS = WorldSpaceNormal;
#else
inputData.normalWS = normalize(WorldSpaceNormal);
#endif
#endif
#if !SHADER_HINT_NICE_QUALITY
// viewDirection should be normalized here, but we avoid doing it as it's close enough and we save some ALU.
inputData.viewDirectionWS = WorldSpaceViewDirection;
#else
inputData.viewDirectionWS = normalize(WorldSpaceViewDirection);
#endif
inputData.shadowCoord = IN.shadowCoord;
inputData.fogCoord = IN.fogFactorAndVertexLight.x;
inputData.vertexLighting = IN.fogFactorAndVertexLight.yzw;
inputData.bakedGI = SAMPLE_GI(IN.lightmapUV, IN.vertexSH, inputData.normalWS);
half4 color = LightweightFragmentPBR(
inputData,
Albedo,
Metallic,
Specular,
Smoothness,
Occlusion,
Emission,
Alpha);
// Computes fog factor per-vertex
ApplyFog(color.rgb, IN.fogFactorAndVertexLight.x);
#if _AlphaClip
clip(Alpha - AlphaClipThreshold);
#endif
return float4(inputData.normalWS, 1); //color;
}
ENDHLSL
}
Pass
{
Name "ShadowCaster"
Tags{"LightMode" = "ShadowCaster"}
ZWrite On ZTest LEqual
// Material options generated by graph
Cull Back
HLSLPROGRAM
// Required to compile gles 2.0 with standard srp library
#pragma prefer_hlslcc gles
#pragma exclude_renderers d3d11_9x
#pragma target 2.0
//--------------------------------------
// GPU Instancing
#pragma multi_compile_instancing
#pragma vertex ShadowPassVertex
#pragma fragment ShadowPassFragment
// Defines generated by graph
#include "LWRP/ShaderLibrary/Core.hlsl"
#include "LWRP/ShaderLibrary/Lighting.hlsl"
#include "ShaderGraphLibrary/Functions.hlsl"
#include "CoreRP/ShaderLibrary/Color.hlsl"
TEXTURE2D(_MainTex); SAMPLER(sampler_MainTex);
TEXTURE2D(Texture2D_DE8BF47E); SAMPLER(samplerTexture2D_DE8BF47E);
float4 _Color;
struct VertexDescriptionInputs
{
float3 ObjectSpacePosition;
};
struct VertexDescription
{
float3 Position;
};
VertexDescription PopulateVertexData(VertexDescriptionInputs IN)
{
VertexDescription description = (VertexDescription)0;
description.Position = IN.ObjectSpacePosition;
return description;
}
struct GraphVertexInput
{
float4 vertex : POSITION;
float3 normal : NORMAL;
float4 tangent : TANGENT;
float4 texcoord1 : TEXCOORD1;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct VertexOutput
{
float2 uv : TEXCOORD0;
float4 clipPos : SV_POSITION;
};
// x: global clip space bias, y: normal world space bias
float4 _ShadowBias;
float3 _LightDirection;
VertexOutput ShadowPassVertex(GraphVertexInput v)
{
VertexOutput o;
UNITY_SETUP_INSTANCE_ID(v);
// Vertex transformations performed by graph
float3 WorldSpacePosition = mul(UNITY_MATRIX_M,v.vertex);
float3 WorldSpaceNormal = mul(v.normal,(float3x3)UNITY_MATRIX_I_M);
float4 uv1 = v.texcoord1;
float3 ObjectSpacePosition = mul(UNITY_MATRIX_I_M,float4(WorldSpacePosition,1.0));
VertexDescriptionInputs vdi = (VertexDescriptionInputs)0;
// Vertex description inputs defined by graph
vdi.ObjectSpacePosition = ObjectSpacePosition;
VertexDescription vd = PopulateVertexData(vdi);
v.vertex.xyz = vd.Position;
o.uv = uv1;
float3 positionWS = TransformObjectToWorld(v.vertex.xyz);
float3 normalWS = TransformObjectToWorldDir(v.normal);
float invNdotL = 1.0 - saturate(dot(_LightDirection, normalWS));
float scale = invNdotL * _ShadowBias.y;
// normal bias is negative since we want to apply an inset normal offset
positionWS = normalWS * scale.xxx + positionWS;
float4 clipPos = TransformWorldToHClip(positionWS);
// _ShadowBias.x sign depens on if platform has reversed z buffer
clipPos.z += _ShadowBias.x;
#if UNITY_REVERSED_Z
clipPos.z = min(clipPos.z, clipPos.w * UNITY_NEAR_CLIP_VALUE);
#else
clipPos.z = max(clipPos.z, clipPos.w * UNITY_NEAR_CLIP_VALUE);
#endif
o.clipPos = clipPos;
return o;
}
half4 ShadowPassFragment() : SV_TARGET
{
return 0;
}
ENDHLSL
}
Pass
{
Name "DepthOnly"
Tags{"LightMode" = "DepthOnly"}
ZWrite On
ColorMask 0
// Material options generated by graph
Cull Back
HLSLPROGRAM
// Required to compile gles 2.0 with standard srp library
#pragma prefer_hlslcc gles
#pragma exclude_renderers d3d11_9x
#pragma target 2.0
//--------------------------------------
// GPU Instancing
#pragma multi_compile_instancing
#pragma vertex vert
#pragma fragment frag
// Defines generated by graph
#include "LWRP/ShaderLibrary/Core.hlsl"
#include "LWRP/ShaderLibrary/Lighting.hlsl"
#include "ShaderGraphLibrary/Functions.hlsl"
#include "CoreRP/ShaderLibrary/Color.hlsl"
TEXTURE2D(_MainTex); SAMPLER(sampler_MainTex);
TEXTURE2D(Texture2D_DE8BF47E); SAMPLER(samplerTexture2D_DE8BF47E);
float4 _Color;
struct VertexDescriptionInputs
{
float3 ObjectSpacePosition;
};
struct VertexDescription
{
float3 Position;
};
VertexDescription PopulateVertexData(VertexDescriptionInputs IN)
{
VertexDescription description = (VertexDescription)0;
description.Position = IN.ObjectSpacePosition;
return description;
}
struct GraphVertexInput
{
float4 vertex : POSITION;
float3 normal : NORMAL;
float4 tangent : TANGENT;
float4 texcoord1 : TEXCOORD1;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct VertexOutput
{
float2 uv : TEXCOORD0;
float4 clipPos : SV_POSITION;
};
VertexOutput vert(GraphVertexInput v)
{
VertexOutput o = (VertexOutput)0;
UNITY_SETUP_INSTANCE_ID(v);
// Vertex transformations performed by graph
float3 WorldSpacePosition = mul(UNITY_MATRIX_M,v.vertex);
float3 WorldSpaceNormal = mul(v.normal,(float3x3)UNITY_MATRIX_I_M);
float4 uv1 = v.texcoord1;
float3 ObjectSpacePosition = mul(UNITY_MATRIX_I_M,float4(WorldSpacePosition,1.0));
VertexDescriptionInputs vdi = (VertexDescriptionInputs)0;
// Vertex description inputs defined by graph
vdi.ObjectSpacePosition = ObjectSpacePosition;
VertexDescription vd = PopulateVertexData(vdi);
v.vertex.xyz = vd.Position;
o.uv = uv1;
o.clipPos = TransformObjectToHClip(v.vertex.xyz);
return o;
}
half4 frag() : SV_TARGET
{
return 0;
}
ENDHLSL
}
// This pass it not used during regular rendering, only for lightmap baking.
Pass
{
Name "Meta"
Tags{"LightMode" = "Meta"}
Cull Off
HLSLPROGRAM
// Required to compile gles 2.0 with standard srp library
#pragma prefer_hlslcc gles
#pragma exclude_renderers d3d11_9x
#pragma target 2.0
#pragma vertex LightweightVertexMeta
#pragma fragment LightweightFragmentMeta
#pragma shader_feature _SPECULAR_SETUP
#pragma shader_feature _EMISSION
#pragma shader_feature _METALLICSPECGLOSSMAP
#pragma shader_feature _ _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
#pragma shader_feature EDITOR_VISUALIZATION
#pragma shader_feature _SPECGLOSSMAP
#include "LWRP/ShaderLibrary/InputSurfacePBR.hlsl"
#include "LWRP/ShaderLibrary/LightweightPassMetaPBR.hlsl"
ENDHLSL
}
}
FallBack "Hidden/InternalErrorShader"
}

9
Assets/Generated_PBR.shader.meta


fileFormatVersion: 2
guid: 9206d98c6f87d47f78c5c12e4095ceb3
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

61
Assets/NewUnlitShader.shader


Shader "Unlit/NewUnlitShader"
{
Properties
{
_MainTex ("Texture", 2DArray) = "white" {}
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 100
Pass
{
HLSLPROGRAM
#pragma vertex vert
#pragma fragment frag
// make fog work
#pragma multi_compile_fog
#pragma require 2darray
#include "LWRP/ShaderLibrary/Core.hlsl"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float3 uv : TEXCOORD0;
//UNITY_FOG_COORDS(1)
float4 vertex : SV_POSITION;
};
TEXTURE2D_ARRAY(_MainTex);
SAMPLER(sampler_MainTex);
float4 _MainTex_ST;
v2f vert (appdata v)
{
v2f o;
o.vertex = TransformObjectToHClip(v.vertex);
o.uv.xy = TRANSFORM_TEX(v.uv, _MainTex);
o.uv.z = 0;
//UNITY_TRANSFER_FOG(o,o.vertex);
return o;
}
half4 frag (v2f i) : SV_Target
{
// sample the texture
half4 col = SAMPLE_TEXTURE2D_ARRAY(_MainTex, sampler_MainTex, i.uv.xy, 0);
// apply fog
//UNITY_APPLY_FOG(i.fogCoord, col);
return col;
}
ENDHLSL
}
}
}

9
Assets/NewUnlitShader.shader.meta


fileFormatVersion: 2
guid: b2f73566a373e49e18ecd37f9e9f2386
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

85
Assets/Test.mat


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 6
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_Name: Test
m_Shader: {fileID: 4800000, guid: b2f73566a373e49e18ecd37f9e9f2386, type: 3}
m_ShaderKeywords:
m_LightmapFlags: 6
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
stringTagMap: {}
disabledShaderPasses: []
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _BumpMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailAlbedoMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailMask:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailNormalMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _EmissionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MainTex:
m_Texture: {fileID: 18700000, guid: 55f5374dfda0f48b9a2f9ada26d3c50d, type: 2}
m_Scale: {x: 50, y: 50}
m_Offset: {x: 0, y: 0}
- _MetallicGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _OcclusionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _ParallaxMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _SpecGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- _AlphaClip: 0
- _Blend: 0
- _BumpScale: 1
- _Cull: 2
- _Cutoff: 0.5
- _DetailNormalMapScale: 1
- _DstBlend: 0
- _GlossMapScale: 1
- _Glossiness: 0.5
- _GlossyReflections: 1
- _Metallic: 0
- _OcclusionStrength: 1
- _Parallax: 0.02
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _SrcBlend: 1
- _Surface: 0
- _UVSec: 0
- _WorkflowMode: 1
- _ZWrite: 1
m_Colors:
- _Color: {r: 0.5, g: 0.5, b: 0.5, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
- _SpecColor: {r: 0.19999996, g: 0.19999996, b: 0.19999996, a: 1}

8
Assets/Test.mat.meta


fileFormatVersion: 2
guid: 6748847e6642c4fd3888155d0874af7d
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 2100000
userData:
assetBundleName:
assetBundleVariant:

188
Assets/MyLWRenderer.cs


using System;
using UnityEngine;
using UnityEngine.Experimental.Rendering;
using UnityEngine.Experimental.Rendering.LightweightPipeline;
using UnityEngine.Rendering;
public class MyLWRenderer : MonoBehaviour, IRendererSetup
{
private DepthOnlyPass m_DepthOnlyPass;
private DirectionalShadowsPass m_DirectionalShadowPass;
private LocalShadowsPass m_LocalShadowPass;
private SetupForwardRendering m_SetupForwardRendering;
private ScreenSpaceShadowResolvePass m_ScreenSpaceShadowResovePass;
private ConfigureForwardRTs m_ConfigureForwardRTs;
private BeginXRRendering m_BeginXrRendering;
private RenderOpaqueForward m_RenderOpaqueForward;
private OpaquePostProcessPass m_OpaquePostProcessPass;
private CopyDepthPass m_CopyDepthPass;
private CopyColorPass m_CopyColorPass;
private RenderTransparentForward m_RenderTransparentForward;
private TransparentPostProcessPass m_TransparentPostProcessPass;
private FinalBlitPass m_FinalBlitPass;
private EndXRRendering m_EndXrRendering;
[NonSerialized]
private LightweightForwardRenderer m_Renderer;
[NonSerialized]
private bool m_Initialized = false;
private void Init(LightweightForwardRenderer renderer)
{
if (m_Initialized)
return;
m_DepthOnlyPass = new DepthOnlyPass(renderer);
m_DirectionalShadowPass = new DirectionalShadowsPass(renderer);
m_LocalShadowPass = new LocalShadowsPass(renderer);
m_SetupForwardRendering = new SetupForwardRendering(renderer);
m_ScreenSpaceShadowResovePass = new ScreenSpaceShadowResolvePass(renderer);
m_ConfigureForwardRTs = new ConfigureForwardRTs(renderer);
m_BeginXrRendering = new BeginXRRendering(renderer);
m_RenderOpaqueForward = new RenderOpaqueForward(renderer);
m_OpaquePostProcessPass = new OpaquePostProcessPass(renderer);
m_CopyDepthPass = new CopyDepthPass(renderer);
m_CopyColorPass = new CopyColorPass(renderer);
m_RenderTransparentForward = new RenderTransparentForward(renderer);
m_TransparentPostProcessPass = new TransparentPostProcessPass(renderer);
m_FinalBlitPass = new FinalBlitPass(renderer);
m_EndXrRendering = new EndXRRendering(renderer);
m_Renderer = renderer;
m_Initialized = true;
}
public void Setup(LightweightForwardRenderer renderer, ref ScriptableRenderContext context,
ref CullResults cullResults, ref RenderingData renderingData)
{
Init(renderer);
renderer.Clear();
renderer.SetupPerObjectLightIndices(ref cullResults, ref renderingData.lightData);
RenderTextureDescriptor baseDescriptor = renderer.CreateRTDesc(ref renderingData.cameraData);
RenderTextureDescriptor shadowDescriptor = baseDescriptor;
shadowDescriptor.dimension = TextureDimension.Tex2D;
bool requiresCameraDepth = renderingData.cameraData.requiresDepthTexture;
bool requiresDepthPrepass = renderingData.shadowData.requiresScreenSpaceShadowResolve ||
renderingData.cameraData.isSceneViewCamera ||
(requiresCameraDepth &&
!LightweightForwardRenderer.CanCopyDepth(ref renderingData.cameraData));
// For now VR requires a depth prepass until we figure out how to properly resolve texture2DMS in stereo
requiresDepthPrepass |= renderingData.cameraData.isStereoEnabled;
if (renderingData.shadowData.renderDirectionalShadows)
renderer.EnqueuePass(m_DirectionalShadowPass);
if (renderingData.shadowData.renderLocalShadows)
renderer.EnqueuePass(m_LocalShadowPass);
renderer.EnqueuePass(m_SetupForwardRendering);
if (requiresDepthPrepass)
{
m_DepthOnlyPass.Setup(baseDescriptor, RenderTargetHandles.DepthTexture, SampleCount.One);
renderer.EnqueuePass(m_DepthOnlyPass);
}
if (renderingData.shadowData.renderDirectionalShadows &&
renderingData.shadowData.requiresScreenSpaceShadowResolve)
{
m_ScreenSpaceShadowResovePass.Setup(baseDescriptor, RenderTargetHandles.ScreenSpaceShadowmap);
renderer.EnqueuePass(m_ScreenSpaceShadowResovePass);
}
bool requiresDepthAttachment = requiresCameraDepth && !requiresDepthPrepass;
bool requiresColorAttachment =
LightweightForwardRenderer.RequiresIntermediateColorTexture(
ref renderingData.cameraData,
baseDescriptor,
requiresDepthAttachment);
RenderTargetHandle colorHandle = (requiresColorAttachment) ? RenderTargetHandles.Color : RenderTargetHandle.BackBuffer;
RenderTargetHandle depthHandle = (requiresDepthAttachment) ? RenderTargetHandles.DepthAttachment : RenderTargetHandle.BackBuffer;
var sampleCount = (SampleCount) renderingData.cameraData.msaaSamples;
m_ConfigureForwardRTs.Setup(baseDescriptor, colorHandle, depthHandle, sampleCount);
renderer.EnqueuePass(m_ConfigureForwardRTs);
if (renderingData.cameraData.isStereoEnabled)
renderer.EnqueuePass(m_BeginXrRendering);
Camera camera = renderingData.cameraData.camera;
bool dynamicBatching = renderingData.supportsDynamicBatching;
RendererConfiguration rendererConfiguration = GetRendererConfiguration(renderingData.lightData.totalAdditionalLightsCount);
m_RenderOpaqueForward.Setup(baseDescriptor, colorHandle, depthHandle, GetCameraClearFlag(camera), camera.backgroundColor, rendererConfiguration, dynamicBatching);
renderer.EnqueuePass(m_RenderOpaqueForward);
if (renderingData.cameraData.postProcessEnabled &&
renderingData.cameraData.postProcessLayer.HasOpaqueOnlyEffects(renderer.postProcessRenderContext))
{
m_OpaquePostProcessPass.Setup(baseDescriptor, colorHandle);
renderer.EnqueuePass(m_OpaquePostProcessPass);
}
if (depthHandle != RenderTargetHandle.BackBuffer)
{
m_CopyDepthPass.Setup(depthHandle);
renderer.EnqueuePass(m_CopyDepthPass);
}
if (renderingData.cameraData.requiresOpaqueTexture)
{
m_CopyColorPass.Setup(colorHandle);
renderer.EnqueuePass(m_CopyColorPass);
}
m_RenderTransparentForward.Setup(baseDescriptor, colorHandle, depthHandle, ClearFlag.None, camera.backgroundColor, rendererConfiguration, dynamicBatching);
renderer.EnqueuePass(m_RenderTransparentForward);
if (renderingData.cameraData.postProcessEnabled)
{
m_TransparentPostProcessPass.Setup(baseDescriptor, colorHandle);
renderer.EnqueuePass(m_TransparentPostProcessPass);
}
else if (!renderingData.cameraData.isOffscreenRender && colorHandle != RenderTargetHandle.BackBuffer)
{
m_FinalBlitPass.Setup(baseDescriptor, colorHandle);
renderer.EnqueuePass(m_FinalBlitPass);
}
if (renderingData.cameraData.isStereoEnabled)
{
renderer.EnqueuePass(m_EndXrRendering);
}
}
private static ClearFlag GetCameraClearFlag(Camera camera)
{
ClearFlag clearFlag = ClearFlag.None;
CameraClearFlags cameraClearFlags = camera.clearFlags;
if (cameraClearFlags != CameraClearFlags.Nothing)
{
clearFlag |= ClearFlag.Depth;
if (cameraClearFlags == CameraClearFlags.Color || cameraClearFlags == CameraClearFlags.Skybox)
clearFlag |= ClearFlag.Color;
}
return clearFlag;
}
RendererConfiguration GetRendererConfiguration(int localLightsCount)
{
RendererConfiguration configuration = RendererConfiguration.PerObjectReflectionProbes | RendererConfiguration.PerObjectLightmaps | RendererConfiguration.PerObjectLightProbe;
if (localLightsCount > 0)
{
if (m_Renderer.useComputeBufferForPerObjectLightIndices)
configuration |= RendererConfiguration.ProvideLightIndices;
else
configuration |= RendererConfiguration.PerObjectLightIndices8;
}
return configuration;
}
}

/Assets/Objects/props/props/PBR_HUE.ShaderGraph → /Assets/Shaders/PBR_HUE.ShaderGraph

/Assets/Objects/props/props/PBR_HUE.ShaderGraph.meta → /Assets/Shaders/PBR_HUE.ShaderGraph.meta

/Assets/MyLWRenderer.cs.meta → /Assets/Scripts/Rendering/MyLWRenderer.cs.meta

正在加载...
取消
保存