浏览代码

Update planer reflections.

/main
Tim Cooper 6 年前
当前提交
b751bcc7
共有 7 个文件被更改,包括 350 次插入308 次删除
  1. 30
      Assets/Scripts/Rendering/WaterFXPass.cs
  2. 128
      Assets/scenes/Island.unity
  3. 20
      Packages/manifest.json
  4. 239
      Assets/Scripts/Rendering/PlanerReflections.cs
  5. 233
      Assets/Scripts/Rendering/MyLWRenderer.cs
  6. 8
      Assets/scenes/Testing/PackedPBR shader.meta
  7. 0
      /Assets/Scripts/Rendering/PlanerReflections.cs.meta

30
Assets/Scripts/Rendering/WaterFXPass.cs


using UnityEngine.Experimental.Rendering;
using UnityEngine.Experimental.Rendering.LightweightPipeline;
public class WaterFXPass : ScriptableRenderPass
[ImageEffectAllowedInSceneView]
public class WaterFXPass : MonoBehaviour, IAfterSkyboxPass
{
private WaterFXPassImpl m_WaterFXPass;
WaterFXPassImpl waterFxPass
{
get
{
if (m_WaterFXPass == null)
m_WaterFXPass = new WaterFXPassImpl();
return m_WaterFXPass;
}
}
public ScriptableRenderPass GetPassToEnqueue(RenderTextureDescriptor baseDescriptor, RenderTargetHandle colorHandle, RenderTargetHandle depthHandle)
{
return waterFxPass;
}
}
public class WaterFXPassImpl : ScriptableRenderPass
{
const string k_RenderWaterFXTag = "Render Water FX";
private RenderTargetHandle m_WaterFX = RenderTargetHandle.CameraTarget;

public WaterFXPass()
public WaterFXPassImpl()
{
RegisterShaderPassName("WaterFX");
m_WaterFX.Init("_WaterFXMap");

};
}
public override void Execute(ref ScriptableRenderContext context, ref CullResults cullResults, ref RenderingData renderingData)
public override void Execute(LightweightRenderer renderer, ref ScriptableRenderContext context, ref CullResults cullResults, ref RenderingData renderingData)
RenderTextureDescriptor descriptor = LightweightForwardRenderer.CreateRTDesc(ref renderingData.cameraData);
RenderTextureDescriptor descriptor = LightweightRenderer.CreateRTDesc(ref renderingData.cameraData);
descriptor.width = (int)(descriptor.width * 0.5f);
descriptor.height = (int)(descriptor.height * 0.5f);

128
Assets/scenes/Island.unity


objectReference: {fileID: 0}
- target: {fileID: 4510310561805642, guid: cb2fae9bfdf2e44f6a5973fccdc7cf71, type: 3}
propertyPath: m_LocalRotation.y
value: -0.52148503
value: -0.521485
objectReference: {fileID: 0}
- target: {fileID: 4510310561805642, guid: cb2fae9bfdf2e44f6a5973fccdc7cf71, type: 3}
propertyPath: m_LocalRotation.z

propertyPath: m_LocalRotation.w
value: 0.8360893
value: 0.83608925
objectReference: {fileID: 0}
- target: {fileID: 4510310561805642, guid: cb2fae9bfdf2e44f6a5973fccdc7cf71, type: 3}
propertyPath: m_RootOrder

m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 153441711}
m_LocalRotation: {x: 0.052879594, y: -0.88563937, z: 0.2282839, w: 0.40091553}
m_LocalRotation: {x: 0.05298489, y: -0.8854593, z: 0.22821505, w: 0.40133816}
m_LocalPosition: {x: -47.200478, y: 5.10427, z: -51.03091}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:

m_CorrespondingSourceObject: {fileID: 4055554008734936, guid: 9d8d890a22a144f41be1b8cc475bc6de, type: 3}
m_PrefabInstance: {fileID: 785261426}
m_PrefabAsset: {fileID: 0}
--- !u!28 &786329216
Texture2D:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {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: ffcfffffffb6fafaff9cf5f5ff83f0f0ff69ebebff50e6e6ff36e1e1ff22ddddff21dadaff21d7d7ff20d4d5ff1fd1d2ff1ececfff1dcccdff1cc9caff1bc6c7ff1bc3c4ff1ac0c2ff19bdbfff18bbbcff17b8baff16b5b7ff15b2b4ff15afb2ff14acafff13aaacff12a7a9ff11a4a7ff10a1a4ff0f9ea1ff0f9b9fff0e999cff0d9699ff0c9397ff0b9094ff0a8d91ff098a8eff09878cff088589ff078286ff067f84ff057d82ff057b81ff057a81ff057981ff057880ff057680ff05757fff05747fff04737fff04727eff04707eff046f7dff046e7dff046d7dff046b7cff046a7cff03697bff03687bff03667bff03657aff03647aff036379ff036179ff036079ff025f78ff025e78ff025d77ff025b77ff025a77ff025976ff025876ff025675ff025575ff015475ff015374ff015174ff015073ff014f73ff014e73ff014c72ff014b72ff004a71ff004971ff004871ff004670ff00456eff00436bff004169ff004066ff003e63ff003d61ff003b5eff00395cff003859ff003656ff003454ff003351ff00314eff002f4cff002e49ff002c47ff002b44ff002941ff00273fff00263cff00243aff002237ff002134ff001f32ff001d2fff001c2cff001a2aff001927ff001725ff001522ff00141fff00121dff00101aff000f18ff000d15ff000b12ff000a10ff00080dff00070aff000508ff000305ff000203ff000000ff010505ff020b09ff03100eff041612ff051b17ff06211bff072620ff092c24ff0a3129ff0b362dff0c3c32ff0d4136ff0e473bff0f4c3fff105244ff115748ff125d4dff136251ff146756ff156957ff156957ff156a58ff156a58ff166a58ff166b58ff166b59ff166c59ff176c59ff176c5aff176d5aff176d5aff186d5bff186e5bff186e5bff196f5cff196f5cff196f5cff19705cff1a705dff1a715dff1a715dff1a715eff1b725eff1b725eff1b725fff1b735fff1c735fff1c745fff1c7460ff1c7460ff1d7560ff1d7561ff1d7661ff1d7662ff1d7863ff1d7965ff1c7b66ff1c7c68ff1c7e6aff1b7f6bff1b816dff1b826eff1a8470ff1a8572ff198773ff198975ff198a76ff188c78ff188d7aff188f7bff17907dff17927eff179380ff169582ff169683ff169885ff159986ff159b88ff149c8aff149e8bff149f8dff13a18eff13a290ff13a492ff12a593ff12a795ff12a996ff11aa98ff11ac9aff11ad9bff10af9dff10b09eff0fb2a0ff0fb3a2ff0fb5a3ff0eb6a5ff0eb8a6ff0eb9a8ff0dbbaaff0dbcabff0dbeadff0cbfaeff0cc1b0ff0cc2b2ff0bc4b3ff0bc5b5ff0ac7b6ff0ac9b8ff0acab9ff09ccbbff09cdbdff09cfbeff08d0c0ff08d2c1ff08d3c3ff07d5c5ff07d6c6ff07d8c8ff06d9c9ff06dbcbff05dccdff05deceff05dfd0ff04e1d1ff04e2d3ff04e4d5ff03e5d6ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000009ff000018ff000028ff000039ff00004aff00005aff00006aff00007aff00008aff000099ff0000a7ff0002b5ff0009c1ff0011cdff0018d8ff001fe2ff0026ebff002ef4ff0035fbff003cffff0043faff004af6ff0050f2ff0056edff005ce9ff0062e5ff0067e1ff006edcff0073d9ff0078d5ff007dd1ff0081ceff0085caff0089c7ff008ec3ff0092c0ff0095bdff0099baff009cb7ff00a0b4ff00a3b2ff00a6afff00a9adff00acaaff00aea7ff00b1a5ff00b3a3ff00b6a1ff00b89eff00bb9bff00be99ff00c097ff00c295ff00c593ff00c790ff00c98eff02cc8cff04ce89ff05d087ff07d385ff0ad682ff0cd880ff0eda7dff11dd7aff14e077ff16e375ff19e671ff1ce96eff1fec6bff22ef67ff26f264ff2af560ff2df85cff32fd58ff36ff54ff3bfe4fff40fb4bff45f947ff4bf542ff51f23cff57ef37ff5deb32ff64e72dff6ce328ff73de22ff7bd91cff83d416ff8bcf11ff95c90bff9dc305ffa7bd00ffb1b600ffbaaf00ffc4a900ffcfa2000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
m_StreamData:
offset: 0
size: 0
path:
--- !u!1001 &790020458
PrefabInstance:
m_ObjectHideFlags: 0

m_CorrespondingSourceObject: {fileID: 4856872047518046, guid: 526627d64ac8a4499965c7cfed5416aa, type: 3}
m_PrefabInstance: {fileID: 844403682}
m_PrefabAsset: {fileID: 0}
--- !u!28 &847308462
Texture2D:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {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: ffcfffffffb6fafaff9cf5f5ff83f0f0ff69ebebff50e6e6ff36e1e1ff22ddddff21dadaff21d7d7ff20d4d5ff1fd1d2ff1ececfff1dcccdff1cc9caff1bc6c7ff1bc3c4ff1ac0c2ff19bdbfff18bbbcff17b8baff16b5b7ff15b2b4ff15afb2ff14acafff13aaacff12a7a9ff11a4a7ff10a1a4ff0f9ea1ff0f9b9fff0e999cff0d9699ff0c9397ff0b9094ff0a8d91ff098a8eff09878cff088589ff078286ff067f84ff057d82ff057b81ff057a81ff057981ff057880ff057680ff05757fff05747fff04737fff04727eff04707eff046f7dff046e7dff046d7dff046b7cff046a7cff03697bff03687bff03667bff03657aff03647aff036379ff036179ff036079ff025f78ff025e78ff025d77ff025b77ff025a77ff025976ff025876ff025675ff025575ff015475ff015374ff015174ff015073ff014f73ff014e73ff014c72ff014b72ff004a71ff004971ff004871ff004670ff00456eff00436bff004169ff004066ff003e63ff003d61ff003b5eff00395cff003859ff003656ff003454ff003351ff00314eff002f4cff002e49ff002c47ff002b44ff002941ff00273fff00263cff00243aff002237ff002134ff001f32ff001d2fff001c2cff001a2aff001927ff001725ff001522ff00141fff00121dff00101aff000f18ff000d15ff000b12ff000a10ff00080dff00070aff000508ff000305ff000203ff000000ff010505ff020b09ff03100eff041612ff051b17ff06211bff072620ff092c24ff0a3129ff0b362dff0c3c32ff0d4136ff0e473bff0f4c3fff105244ff115748ff125d4dff136251ff146756ff156957ff156957ff156a58ff156a58ff166a58ff166b58ff166b59ff166c59ff176c59ff176c5aff176d5aff176d5aff186d5bff186e5bff186e5bff196f5cff196f5cff196f5cff19705cff1a705dff1a715dff1a715dff1a715eff1b725eff1b725eff1b725fff1b735fff1c735fff1c745fff1c7460ff1c7460ff1d7560ff1d7561ff1d7661ff1d7662ff1d7863ff1d7965ff1c7b66ff1c7c68ff1c7e6aff1b7f6bff1b816dff1b826eff1a8470ff1a8572ff198773ff198975ff198a76ff188c78ff188d7aff188f7bff17907dff17927eff179380ff169582ff169683ff169885ff159986ff159b88ff149c8aff149e8bff149f8dff13a18eff13a290ff13a492ff12a593ff12a795ff12a996ff11aa98ff11ac9aff11ad9bff10af9dff10b09eff0fb2a0ff0fb3a2ff0fb5a3ff0eb6a5ff0eb8a6ff0eb9a8ff0dbbaaff0dbcabff0dbeadff0cbfaeff0cc1b0ff0cc2b2ff0bc4b3ff0bc5b5ff0ac7b6ff0ac9b8ff0acab9ff09ccbbff09cdbdff09cfbeff08d0c0ff08d2c1ff08d3c3ff07d5c5ff07d6c6ff07d8c8ff06d9c9ff06dbcbff05dccdff05deceff05dfd0ff04e1d1ff04e2d3ff04e4d5ff03e5d6ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff000009ff000018ff000028ff000039ff00004aff00005aff00006aff00007aff00008aff000099ff0000a7ff0002b5ff0009c1ff0011cdff0018d8ff001fe2ff0026ebff002ef4ff0035fbff003cffff0043faff004af6ff0050f2ff0056edff005ce9ff0062e5ff0067e1ff006edcff0073d9ff0078d5ff007dd1ff0081ceff0085caff0089c7ff008ec3ff0092c0ff0095bdff0099baff009cb7ff00a0b4ff00a3b2ff00a6afff00a9adff00acaaff00aea7ff00b1a5ff00b3a3ff00b6a1ff00b89eff00bb9bff00be99ff00c097ff00c295ff00c593ff00c790ff00c98eff02cc8cff04ce89ff05d087ff07d385ff0ad682ff0cd880ff0eda7dff11dd7aff14e077ff16e375ff19e671ff1ce96eff1fec6bff22ef67ff26f264ff2af560ff2df85cff32fd58ff36ff54ff3bfe4fff40fb4bff45f947ff4bf542ff51f23cff57ef37ff5deb32ff64e72dff6ce328ff73de22ff7bd91cff83d416ff8bcf11ff95c90bff9dc305ffa7bd00ffb1b600ffbaaf00ffc4a900ffcfa2000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
m_StreamData:
offset: 0
size: 0
path:
--- !u!1001 &849047459
PrefabInstance:
m_ObjectHideFlags: 0

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

m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1017609894}
m_LocalRotation: {x: 0.052879594, y: -0.88563937, z: 0.2282839, w: 0.40091553}
m_LocalRotation: {x: 0.05298489, y: -0.8854593, z: 0.22821505, w: 0.40133816}
m_LocalPosition: {x: -47.200478, y: 5.10427, z: -51.03091}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []

m_BeforeTransparentBundles: []
m_BeforeStackBundles: []
m_AfterStackBundles: []
--- !u!114 &1017609900
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1017609894}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: c61a0c521779544ee8bf7890846c4d21, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!114 &1017609901
MonoBehaviour:
m_ObjectHideFlags: 0

m_Script: {fileID: 11500000, guid: 62d2ec625e93e8d40b72db412b9db648, type: 3}
m_Name:
m_EditorClassIdentifier:
m_addToSceneCamera: 1
m_settings:
m_ResolutionMultiplier: 2
m_ClipPlaneOffset: 0.07
m_ReflectLayers:
serializedVersion: 2
m_Bits: 4294967295
--- !u!114 &1017609903
MonoBehaviour:
m_ObjectHideFlags: 0

m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1072933540}
m_LocalRotation: {x: 0.024982631, y: -0.78030825, z: 0.031235142, w: 0.6241149}
m_LocalRotation: {x: 0.024982633, y: -0.7803083, z: 0.031235151, w: 0.6241148}
m_LocalPosition: {x: -50.76289, y: 2.2, z: -53.19036}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:

m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1143740434}
m_LocalRotation: {x: -0.0020261959, y: 0.94002676, z: -0.0055841235, w: -0.341049}
m_LocalRotation: {x: -0.002025402, y: 0.9400753, z: -0.00558441, w: -0.3409154}
m_LocalPosition: {x: 42, y: 2.51, z: 62.1}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:

m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1214797992}
m_LocalRotation: {x: 0.04506648, y: 0.7262534, z: -0.047830928, w: 0.6842787}
m_LocalRotation: {x: 0.04506648, y: 0.72625333, z: -0.047830928, w: 0.68427867}
m_LocalPosition: {x: 93.90462, y: 16.68996, z: 22.234848}
m_LocalScale: {x: 1, y: 0.9999999, z: 1}
m_Children:

m_Script: {fileID: 11500000, guid: 301a6cf3893eb4e2b9a5de3e341ac44b, type: 3}
m_Name:
m_EditorClassIdentifier:
m_settings:
m_ResolutionMultiplier: 2
m_ClipPlaneOffset: 0.24
m_ReflectLayers:
serializedVersion: 2
m_Bits: 3367
enableShadows: 0
maxLODLevel: 2
--- !u!114 &1442025835
MonoBehaviour:
m_ObjectHideFlags: 0

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

m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1768035350}
m_LocalRotation: {x: -0.0010585708, y: 0.99894106, z: -0.03298411, w: -0.032059364}
m_LocalRotation: {x: -0.0010585701, y: 0.998941, z: -0.03298413, w: -0.032059327}
m_LocalPosition: {x: -48.237194, y: 6.099838, z: 32.51896}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:

m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1973407761}
m_LocalRotation: {x: 0.028355375, y: 0.8831073, z: -0.053826973, w: 0.4652099}
m_LocalRotation: {x: 0.028355379, y: 0.8831073, z: -0.05382698, w: 0.4652099}
m_LocalPosition: {x: -53.12651, y: 1.3000001, z: -57.111008}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:

20
Packages/manifest.json


{
"registry": "https://staging-packages.unity.com",
"dependencies": {
"com.unity.analytics": "2.0.16",
"com.unity.ads": "2.0.8",
"com.unity.analytics": "3.0.5",
"com.unity.collab-proxy": "1.2.6",
"com.unity.package-manager-ui": "2.0.0-preview.3",
"com.unity.purchasing": "2.0.1",
"com.unity.render-pipelines.lightweight": "3.0.0-preview",
"com.unity.package-manager-ui": "2.0.0-preview.6",
"com.unity.purchasing": "2.0.1",
"com.unity.render-pipelines.core": "file:d:\\code\\ScriptableRenderPipeline\\com.unity.render-pipelines.core",
"com.unity.render-pipelines.lightweight": "file:d:\\code\\ScriptableRenderPipeline\\com.unity.render-pipelines.lightweight",
"com.unity.shadergraph": "file:d:\\code\\ScriptableRenderPipeline\\com.unity.shadergraph",
"com.unity.modules.cloth": "1.0.0",
"com.unity.modules.director": "1.0.0",
"com.unity.modules.imageconversion": "1.0.0",
"com.unity.modules.imgui": "1.0.0",

"com.unity.modules.screencapture": "1.0.0",
"com.unity.modules.terrain": "1.0.0",
"com.unity.modules.terrainphysics": "1.0.0",
"com.unity.modules.tilemap": "1.0.0",
"com.unity.modules.unitywebrequest": "1.0.0",
"com.unity.modules.unitywebrequestassetbundle": "1.0.0",
"com.unity.modules.unitywebrequestaudio": "1.0.0",
"com.unity.modules.unitywebrequesttexture": "1.0.0",
"com.unity.modules.unitywebrequestwww": "1.0.0",
"com.unity.modules.vehicles": "1.0.0",
"com.unity.modules.video": "1.0.0",
"com.unity.modules.vr": "1.0.0",
"com.unity.modules.wind": "1.0.0",

239
Assets/Scripts/Rendering/PlanerReflections.cs


using System;
using Unity.Mathematics;
using UnityEngine.Rendering;
using WaterSystem;
namespace UnityEngine.Experimental.Rendering.LightweightPipeline
{
[ImageEffectAllowedInSceneView]
public class PlanerReflections : MonoBehaviour, LightweightPipeline.IBeforeCameraRender
{
[System.Serializable]
public enum ResolutionMulltiplier
{
Full,
Half,
Third,
Quarter
}
[System.Serializable]
public class PlanarReflectionSettings
{
public ResolutionMulltiplier m_ResolutionMultiplier = ResolutionMulltiplier.Third;
public float m_ClipPlaneOffset = 0.07f;
public LayerMask m_ReflectLayers = -1;
}
[SerializeField]
public PlanarReflectionSettings m_settings = new PlanarReflectionSettings();
public GameObject target;
private Camera m_ReflectionCamera;
private int2 m_TextureSize = new int2(256, 128);
private RenderTexture m_ReflectionTexture = null;
private int2 m_OldReflectionTextureSize;
// Cleanup all the objects we possibly have created
void OnDisable()
{
if(m_ReflectionCamera)
{
m_ReflectionCamera.targetTexture = null;
DestroyImmediate(m_ReflectionCamera.gameObject);
}
if (m_ReflectionTexture)
{
DestroyImmediate(m_ReflectionTexture);
}
}
private void UpdateCamera(Camera src, Camera dest)
{
if (dest == null)
return;
// set camera to clear the same way as current camera
dest.clearFlags = src.clearFlags;
dest.backgroundColor = src.backgroundColor;
// update other values to match current camera.
// even if we are supplying custom camera&projection matrices,
// some of values are used elsewhere (e.g. skybox uses far plane)
dest.farClipPlane = src.farClipPlane;
dest.nearClipPlane = src.nearClipPlane;
dest.orthographic = src.orthographic;
dest.fieldOfView = src.fieldOfView;
dest.allowHDR = src.allowHDR;
dest.useOcclusionCulling = false;
dest.aspect = src.aspect;
dest.orthographicSize = src.orthographicSize;
}
private void UpdateReflectionCamera(Camera realCamera)
{
if (m_ReflectionCamera == null)
m_ReflectionCamera = CreateMirrorObjects(realCamera);
// find out the reflection plane: position and normal in world space
Vector3 pos = target.transform.position;
Vector3 normal = target.transform.up;
UpdateCamera(realCamera, m_ReflectionCamera);
// Render reflection
// Reflect camera around reflection plane
float d = -Vector3.Dot(normal, pos) - m_settings.m_ClipPlaneOffset;
Vector4 reflectionPlane = new Vector4(normal.x, normal.y, normal.z, d);
Matrix4x4 reflection = Matrix4x4.identity;
reflection *= Matrix4x4.Scale(new Vector3(1, -1, 1));
CalculateReflectionMatrix(ref reflection, reflectionPlane);
Vector3 oldpos = realCamera.transform.position - new Vector3(0, target.transform.position.y * 2, 0);
Vector3 newpos = ReflectPosition(oldpos);
m_ReflectionCamera.transform.forward = Vector3.Scale(realCamera.transform.forward, new Vector3(1, -1, 1));
m_ReflectionCamera.worldToCameraMatrix = realCamera.worldToCameraMatrix * reflection;
// Setup oblique projection matrix so that near plane is our reflection
// plane. This way we clip everything below/above it for free.
Vector4 clipPlane = CameraSpacePlane(m_ReflectionCamera, pos - Vector3.up * 0.1f, normal, 1.0f);
Matrix4x4 projection = realCamera.CalculateObliqueMatrix(clipPlane);
m_ReflectionCamera.projectionMatrix = projection;
m_ReflectionCamera.cullingMask = m_settings.m_ReflectLayers; // never render water layer
m_ReflectionCamera.transform.position = newpos;
}
// Calculates reflection matrix around the given plane
private static void CalculateReflectionMatrix(ref Matrix4x4 reflectionMat, Vector4 plane)
{
reflectionMat.m00 = (1F - 2F * plane[0] * plane[0]);
reflectionMat.m01 = (-2F * plane[0] * plane[1]);
reflectionMat.m02 = (-2F * plane[0] * plane[2]);
reflectionMat.m03 = (-2F * plane[3] * plane[0]);
reflectionMat.m10 = (-2F * plane[1] * plane[0]);
reflectionMat.m11 = (1F - 2F * plane[1] * plane[1]);
reflectionMat.m12 = (-2F * plane[1] * plane[2]);
reflectionMat.m13 = (-2F * plane[3] * plane[1]);
reflectionMat.m20 = (-2F * plane[2] * plane[0]);
reflectionMat.m21 = (-2F * plane[2] * plane[1]);
reflectionMat.m22 = (1F - 2F * plane[2] * plane[2]);
reflectionMat.m23 = (-2F * plane[3] * plane[2]);
reflectionMat.m30 = 0F;
reflectionMat.m31 = 0F;
reflectionMat.m32 = 0F;
reflectionMat.m33 = 1F;
}
private static Vector3 ReflectPosition(Vector3 pos)
{
Vector3 newPos = new Vector3(pos.x, -pos.y, pos.z);
return newPos;
}
private float GetScaleValue()
{
switch(m_settings.m_ResolutionMultiplier)
{
case ResolutionMulltiplier.Full:
return 1f;
case ResolutionMulltiplier.Half:
return 0.5f;
case ResolutionMulltiplier.Third:
return 0.33f;
case ResolutionMulltiplier.Quarter:
return 0.25f;
}
return 0.5f; // default to half res
}
// Compare two int2
private static bool Int2Compare(int2 a, int2 b)
{
if(a.x == b.x && a.y == b.y)
return true;
else
return false;
}
// Given position/normal of the plane, calculates plane in camera space.
private Vector4 CameraSpacePlane(Camera cam, Vector3 pos, Vector3 normal, float sideSign)
{
Vector3 offsetPos = pos + normal * m_settings.m_ClipPlaneOffset;
Matrix4x4 m = cam.worldToCameraMatrix;
Vector3 cpos = m.MultiplyPoint(offsetPos);
Vector3 cnormal = m.MultiplyVector(normal).normalized * sideSign;
return new Vector4(cnormal.x, cnormal.y, cnormal.z, -Vector3.Dot(cpos, cnormal));
}
private Camera CreateMirrorObjects(Camera currentCamera)
{
LightweightPipelineAsset lwAsset = (LightweightPipelineAsset) GraphicsSettings.renderPipelineAsset;
var resMulti = lwAsset.renderScale * GetScaleValue();
m_TextureSize.x = (int) Mathf.Pow(2, Mathf.RoundToInt(Mathf.Log(currentCamera.pixelWidth * resMulti, 2)));
m_TextureSize.y = (int) Mathf.Pow(2, Mathf.RoundToInt(Mathf.Log(currentCamera.pixelHeight * resMulti, 2)));
// Reflection render texture
if (Int2Compare(m_TextureSize, m_OldReflectionTextureSize) || !m_ReflectionTexture)
{
if (m_ReflectionTexture)
DestroyImmediate(m_ReflectionTexture);
m_ReflectionTexture = new RenderTexture(m_TextureSize.x, m_TextureSize.y, 16,
currentCamera.allowHDR ? RenderTextureFormat.DefaultHDR : RenderTextureFormat.Default);
m_ReflectionTexture.useMipMap = m_ReflectionTexture.autoGenerateMips = false;
m_ReflectionTexture.autoGenerateMips = false; // no need for mips(unless wanting cheap roughness)
m_ReflectionTexture.name = "_PlanarReflection" + GetInstanceID();
m_ReflectionTexture.isPowerOfTwo = true;
m_ReflectionTexture.hideFlags = HideFlags.DontSave;
m_OldReflectionTextureSize = m_TextureSize;
}
m_ReflectionTexture.DiscardContents();
GameObject go =
new GameObject("Planar Refl Camera id" + GetInstanceID() + " for " + currentCamera.GetInstanceID(),
typeof(Camera), typeof(Skybox));
LightweightAdditionalCameraData lwrpCamData =
go.AddComponent(typeof(LightweightAdditionalCameraData)) as LightweightAdditionalCameraData;
lwrpCamData.renderShadows = false; // turn off shadows for the reflection camera
var reflectionCamera = go.GetComponent<Camera>();
reflectionCamera.transform.SetPositionAndRotation(transform.position, transform.rotation);
reflectionCamera.targetTexture = m_ReflectionTexture;
reflectionCamera.allowMSAA = true;
reflectionCamera.depth = -10;
reflectionCamera.enabled = false;
go.hideFlags = HideFlags.HideAndDontSave;
Shader.SetGlobalTexture("_PlanarReflectionTexture", m_ReflectionTexture);
return reflectionCamera;
}
public void ExecuteBeforeCameraRender(
ScriptableRenderContext context,
Camera camera,
LightweightPipeline.PipelineSettings pipelineSettings,
LightweightRenderer renderer)
{
if (!enabled)
return;
GL.invertCulling = true;
RenderSettings.fog = false;
UpdateReflectionCamera(camera);
CullResults cullResults = new CullResults();
LightweightPipeline.RenderSingleCamera(context, pipelineSettings, m_ReflectionCamera, ref cullResults, new DefaultRendererSetup(), renderer);
GL.invertCulling = false;
RenderSettings.fog = true;
}
}
}

233
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;
#if UNITY_EDITOR
private SceneViewDepthCopyPass m_SceneViewDepthCopyPass;
#endif
private RenderTargetHandle Color;
private RenderTargetHandle DepthAttachment;
private RenderTargetHandle DepthTexture;
private RenderTargetHandle OpaqueColor;
private RenderTargetHandle DirectionalShadowmap;
private RenderTargetHandle LocalShadowmap;
private RenderTargetHandle ScreenSpaceShadowmap;
[NonSerialized]
private bool m_Initialized = false;
public bool m_addToSceneCamera = true;
private void Init(LightweightForwardRenderer renderer)
{
if (m_Initialized)
return;
// Add this custom renderer component to the scene camera(I'm not looking at removing so could cause issues)
if(m_addToSceneCamera)
{
Object[] cameras = Resources.FindObjectsOfTypeAll(typeof(Camera));
for (var i = 0; i < cameras.Length; i++)
{
Camera cam = cameras[i] as Camera;
if(cam.cameraType == CameraType.SceneView)
{
if(cam.gameObject.GetComponent(this.GetType()) == null)
{
cam.gameObject.AddComponent(this.GetType());
}
}
}
}
m_DepthOnlyPass = new DepthOnlyPass();
m_DirectionalShadowPass = new DirectionalShadowsPass();
m_LocalShadowPass = new LocalShadowsPass();
m_SetupForwardRenderingPass = new SetupForwardRenderingPass();
m_ScreenSpaceShadowResovePass = new ScreenSpaceShadowResolvePass(renderer.GetMaterial(MaterialHandles.ScrenSpaceShadow));
m_CreateLightweightRenderTexturesPass = new CreateLightweightRenderTexturesPass();
m_BeginXrRenderingPass = new BeginXRRenderingPass();
m_SetupLightweightConstants = new SetupLightweightConstanstPass();
m_RenderOpaqueForwardPass = new RenderOpaqueForwardPass(renderer.GetMaterial(MaterialHandles.Error));
m_OpaquePostProcessPass = new OpaquePostProcessPass();
m_DrawSkyboxPass = new DrawSkyboxPass();
m_CopyDepthPass = new CopyDepthPass(renderer.GetMaterial(MaterialHandles.DepthCopy));
m_CopyColorPass = new CopyColorPass(renderer.GetMaterial(MaterialHandles.Sampling));
m_RenderTransparentForwardPass = new RenderTransparentForwardPass(renderer.GetMaterial(MaterialHandles.Error));
m_TransparentPostProcessPass = new TransparentPostProcessPass();
m_FinalBlitPass = new FinalBlitPass(renderer.GetMaterial(MaterialHandles.Blit));
m_EndXrRenderingPass = new EndXRRenderingPass();
m_WaterFXPass = new WaterFXPass();
#if UNITY_EDITOR
m_SceneViewDepthCopyPass = new SceneViewDepthCopyPass(renderer.GetMaterial(MaterialHandles.DepthCopy));
#endif
// RenderTexture format depends on camera and pipeline (HDR, non HDR, etc)
// Samples (MSAA) depend on camera and pipeline
Color.Init("_CameraColorTexture");
DepthAttachment.Init("_CameraDepthAttachment");
DepthTexture.Init("_CameraDepthTexture");
OpaqueColor.Init("_CameraOpaqueTexture");
DirectionalShadowmap.Init("_DirectionalShadowmapTexture");
LocalShadowmap.Init("_LocalShadowmapTexture");
ScreenSpaceShadowmap.Init("_ScreenSpaceShadowMapTexture");
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 = LightweightForwardRenderer.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)
{
m_DirectionalShadowPass.Setup(DirectionalShadowmap);
renderer.EnqueuePass(m_DirectionalShadowPass);
}
if (renderingData.shadowData.renderLocalShadows)
{
m_LocalShadowPass.Setup(LocalShadowmap, renderer.maxVisibleLocalLights);
renderer.EnqueuePass(m_LocalShadowPass);
}
renderer.EnqueuePass(m_SetupForwardRenderingPass);
if (requiresDepthPrepass)
{
m_DepthOnlyPass.Setup(baseDescriptor, DepthTexture, SampleCount.One);
renderer.EnqueuePass(m_DepthOnlyPass);
}
if (renderingData.shadowData.renderDirectionalShadows &&
renderingData.shadowData.requiresScreenSpaceShadowResolve)
{
m_ScreenSpaceShadowResovePass.Setup(baseDescriptor, ScreenSpaceShadowmap);
renderer.EnqueuePass(m_ScreenSpaceShadowResovePass);
}
bool requiresDepthAttachment = requiresCameraDepth && !requiresDepthPrepass;
bool requiresColorAttachment =
LightweightForwardRenderer.RequiresIntermediateColorTexture(
ref renderingData.cameraData,
baseDescriptor,
requiresDepthAttachment);
RenderTargetHandle colorHandle = (requiresColorAttachment) ? Color : RenderTargetHandle.CameraTarget;
RenderTargetHandle depthHandle = (requiresDepthAttachment) ? DepthAttachment : RenderTargetHandle.CameraTarget;
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);
Camera camera = renderingData.cameraData.camera;
bool dynamicBatching = renderingData.supportsDynamicBatching;
RendererConfiguration rendererConfiguration = LightweightForwardRenderer.GetRendererConfiguration(renderingData.lightData.totalAdditionalLightsCount);
m_SetupLightweightConstants.Setup(renderer.maxVisibleLocalLights, renderer.perObjectLightIndices);
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(renderer.postProcessRenderContext, baseDescriptor, colorHandle);
renderer.EnqueuePass(m_OpaquePostProcessPass);
}
if (camera.clearFlags == CameraClearFlags.Skybox)
renderer.EnqueuePass(m_DrawSkyboxPass);
if (depthHandle != RenderTargetHandle.CameraTarget)
{
m_CopyDepthPass.Setup(depthHandle, DepthTexture);
renderer.EnqueuePass(m_CopyDepthPass);
}
if (renderingData.cameraData.requiresOpaqueTexture)
{
m_CopyColorPass.Setup(colorHandle, OpaqueColor);
renderer.EnqueuePass(m_CopyColorPass);
}
renderer.EnqueuePass(m_WaterFXPass);
m_RenderTransparentForwardPass.Setup(baseDescriptor, colorHandle, depthHandle, ClearFlag.None, camera.backgroundColor, rendererConfiguration, dynamicBatching);
renderer.EnqueuePass(m_RenderTransparentForwardPass);
if (renderingData.cameraData.postProcessEnabled)
{
m_TransparentPostProcessPass.Setup(renderer.postProcessRenderContext, baseDescriptor, colorHandle);
renderer.EnqueuePass(m_TransparentPostProcessPass);
}
else if (!renderingData.cameraData.isOffscreenRender && colorHandle != RenderTargetHandle.CameraTarget)
{
m_FinalBlitPass.Setup(baseDescriptor, colorHandle);
renderer.EnqueuePass(m_FinalBlitPass);
}
if (renderingData.cameraData.isStereoEnabled)
{
renderer.EnqueuePass(m_EndXrRenderingPass);
}
#if UNITY_EDITOR
if (renderingData.cameraData.isSceneViewCamera)
{
m_SceneViewDepthCopyPass.Setup(DepthTexture);
renderer.EnqueuePass(m_SceneViewDepthCopyPass);
}
#endif
}
}
}

8
Assets/scenes/Testing/PackedPBR shader.meta


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

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

正在加载...
取消
保存