浏览代码
ibeforerender changes - background rendering works, but the rest of the shaders don't work with this change
/lwrp-support-2018.3-with-1.5
ibeforerender changes - background rendering works, but the rest of the shaders don't work with this change
/lwrp-support-2018.3-with-1.5
Jimmy Alamparambil
6 年前
当前提交
1e4a9806
共有 18 个文件被更改,包括 316 次插入 和 144 次删除
-
2Assets/LWRPSupport/ARKitLWRPShader.shader
-
2Assets/LWRPSupport/LWRPBackgroundRendererAsset.asset
-
31Assets/LWRPSupport/LWRPBeforeCameraRender.cs
-
6Assets/LWRPSupport/Unity.XR.ARFoundation.LWRPSupport.asmdef
-
7Assets/Materials/LWRPCube.mat
-
7Assets/Materials/LWRPPlane.mat
-
116Assets/Scenes/SampleLWRPScene.unity
-
11Packages/manifest.json
-
44ProjectSettings/EditorSettings.asset
-
9ProjectSettings/GraphicsSettings.asset
-
13ProjectSettings/ProjectSettings.asset
-
2ProjectSettings/ProjectVersion.txt
-
1ProjectSettings/UnityConnectSettings.asset
-
63Assets/LWRPSupport/LWRPBackgroundRenderPass.cs
-
11Assets/LWRPSupport/LWRPBackgroundRenderPass.cs.meta
-
61Assets/LWRPSupport/LWRPBackgroundRendererAsset.cs
-
74Assets/LWRPSupport/LWRPBackroundRendererAsset.cs
-
0/Assets/LWRPSupport/LWRPBackgroundRendererAsset.cs.meta
|
|||
using UnityEngine.Experimental.Rendering; |
|||
using UnityEngine.Rendering; |
|||
using UnityEngine.Experimental.Rendering.LWRP; |
|||
namespace UnityEngine.XR.ARFoundation |
|||
namespace UnityEngine.XR.ARFoundation.LWRPSupport |
|||
public class LWRPBeforeCameraRender : MonoBehaviour, LightweightPipeline.IBeforeCameraRender |
|||
public class LWRPBeforeCameraRender : MonoBehaviour, IBeforeRender |
|||
public void ExecuteBeforeCameraRender(ScriptableRenderContext context, Camera currentCamera, LightweightPipeline.PipelineSettings pipelineSettings, |
|||
ScriptableRenderer currentRenderer) |
|||
/// <summary>
|
|||
/// Create, setup and return a ScriptableRenderPass that will blit the pass-thru video when this GameObject is rendered.
|
|||
/// </summary>
|
|||
/// <param name="baseDescriptor">RenderTextureDescriptor for this pass. </param>
|
|||
/// <param name="colorHandle">RenderTargetHandle for color buffer.</param>
|
|||
/// <param name="depthHandle">RenderTargetHandle for depth buffer.</param>
|
|||
/// <param name="clearFlag">ClearFlag used for rendering.</param>
|
|||
/// <returns></returns>
|
|||
public ScriptableRenderPass GetPassToEnqueue(RenderTextureDescriptor baseDescriptor, RenderTargetHandle colorHandle, |
|||
RenderTargetHandle depthHandle, ClearFlag clearFlag) |
|||
if (blitMaterial == null) |
|||
return; |
|||
|
|||
var cmd = CommandBufferPool.Get(k_ARBlitTag); |
|||
|
|||
cmd.Blit(null, BuiltinRenderTextureType.CameraTarget, blitMaterial); |
|||
|
|||
context.ExecuteCommandBuffer(cmd); |
|||
CommandBufferPool.Release(cmd); |
|||
LWRPBackgroundRenderPass lwrpBackgroundRenderPass = new LWRPBackgroundRenderPass(); |
|||
lwrpBackgroundRenderPass.Setup(blitMaterial, colorHandle.Identifier(), depthHandle.Identifier(), |
|||
baseDescriptor); |
|||
return lwrpBackgroundRenderPass; |
|||
} |
|||
} |
|||
} |
|
|||
{ |
|||
"dependencies": { |
|||
"com.unity.collab-proxy": "1.2.9", |
|||
"com.unity.package-manager-ui": "2.0.0-preview.7", |
|||
"com.unity.render-pipelines.lightweight": "3.3.0-preview", |
|||
"com.unity.collab-proxy": "1.2.15", |
|||
"com.unity.package-manager-ui": "2.0.3", |
|||
"com.unity.shadergraph": "file:/Users/jimmy/Documents/Projects/DevUnity/Packages/ScriptableRenderPipeline/com.unity.shadergraph", |
|||
"com.unity.render-pipelines.core": "file:/Users/jimmy/Documents/Projects/DevUnity/Packages/ScriptableRenderPipeline/com.unity.render-pipelines.core", |
|||
"com.unity.render-pipelines.lightweight": "file:/Users/jimmy/Documents/Projects/DevUnity/Packages/ScriptableRenderPipeline/com.unity.render-pipelines.lightweight", |
|||
"com.unity.modules.jsonserialize": "1.0.0", |
|||
"com.unity.modules.unityanalytics": "1.0.0", |
|||
"com.unity.modules.unitywebrequest": "1.0.0", |
|||
"com.unity.modules.vr": "1.0.0", |
|||
"com.unity.modules.xr": "1.0.0" |
|||
} |
|
|||
%YAML 1.1 |
|||
%TAG !u! tag:unity3d.com,2011: |
|||
--- !u!159 &1 |
|||
EditorSettings: |
|||
m_ObjectHideFlags: 0 |
|||
serializedVersion: 7 |
|||
m_ExternalVersionControlSupport: Visible Meta Files |
|||
m_SerializationMode: 2 |
|||
m_LineEndingsForNewScripts: 2 |
|||
m_DefaultBehaviorMode: 0 |
|||
m_SpritePackerMode: 0 |
|||
m_SpritePackerPaddingPower: 1 |
|||
m_EtcTextureCompressorBehavior: 1 |
|||
m_EtcTextureFastCompressor: 1 |
|||
m_EtcTextureNormalCompressor: 2 |
|||
m_EtcTextureBestCompressor: 4 |
|||
m_ProjectGenerationIncludedExtensions: txt;xml;fnt;cd |
|||
m_ProjectGenerationRootNamespace: |
|||
m_UserGeneratedProjectSuffix: |
|||
m_CollabEditorSettings: |
|||
inProgressEnabled: 1 |
|||
%YAML 1.1 |
|||
%TAG !u! tag:unity3d.com,2011: |
|||
--- !u!159 &1 |
|||
EditorSettings: |
|||
m_ObjectHideFlags: 0 |
|||
serializedVersion: 7 |
|||
m_ExternalVersionControlSupport: Visible Meta Files |
|||
m_SerializationMode: 2 |
|||
m_LineEndingsForNewScripts: 2 |
|||
m_DefaultBehaviorMode: 0 |
|||
m_PrefabRegularEnvironment: {fileID: 0} |
|||
m_PrefabUIEnvironment: {fileID: 0} |
|||
m_SpritePackerMode: 0 |
|||
m_SpritePackerPaddingPower: 1 |
|||
m_EtcTextureCompressorBehavior: 1 |
|||
m_EtcTextureFastCompressor: 1 |
|||
m_EtcTextureNormalCompressor: 2 |
|||
m_EtcTextureBestCompressor: 4 |
|||
m_ProjectGenerationIncludedExtensions: txt;xml;fnt;cd;asmdef |
|||
m_ProjectGenerationRootNamespace: |
|||
m_CollabEditorSettings: |
|||
inProgressEnabled: 1 |
|||
m_EnableTextureStreamingInPlayMode: 1 |
|
|||
m_EditorVersion: 2018.3.0b2 |
|||
m_EditorVersion: 2018.3.0f2 |
|
|||
using System; |
|||
using UnityEngine.Experimental.Rendering; |
|||
using UnityEngine.Experimental.Rendering.LightweightPipeline; |
|||
using UnityEngine.Rendering; |
|||
|
|||
namespace UnityEngine.XR.ARFoundation.LWRPSupport |
|||
{ |
|||
public class LWRPBackgroundRenderPass : ScriptableRenderPass |
|||
{ |
|||
Material m_BlitMaterial; |
|||
RenderTargetIdentifier m_DepthIdentifier; |
|||
RenderTargetIdentifier m_TargetIdentifier; |
|||
RenderTextureDescriptor m_Descriptor; |
|||
const string k_ARBlitTag = "ARBackground Blit Pass"; |
|||
|
|||
/// <summary>
|
|||
/// This render pass will need to be setup with the following parameters to be able to execute when called to do so.
|
|||
/// In this case, this method is called from GetPassToEnqueue in IBeforeRender interface.
|
|||
/// </summary>
|
|||
/// <param name="mat"> Material to be used to clear the screen. </param>
|
|||
/// <param name="ident"> RenderTargetIdentifier for the color buffer. </param>
|
|||
/// <param name="depthIdent"> RenderTargetIdentifier for the depth buffer.</param>
|
|||
/// <param name="descript"> RenderTextureDescriptor for the target RenderTexture. </param>
|
|||
/// <returns> True if the material set is not null. </returns>
|
|||
public bool Setup(Material mat, RenderTargetIdentifier ident, RenderTargetIdentifier depthIdent, RenderTextureDescriptor descript) |
|||
{ |
|||
m_BlitMaterial = mat; |
|||
m_TargetIdentifier = ident; |
|||
m_DepthIdentifier = depthIdent; |
|||
m_Descriptor = descript; |
|||
return m_BlitMaterial != null; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Custom rendering for clearing the background with the pass-thru video for AR happens here. We use the parameters passed in via setup
|
|||
/// to create command buffer that clears the render target and blits to it using the clear material.
|
|||
/// </summary>
|
|||
/// <param name="renderer"> The ScriptableRenderer that is being used. </param>
|
|||
/// <param name="context"> The ScriptableRenderContext used to execute the command buffer that we create. </param>
|
|||
/// <param name="renderingData"> RenderingData (unused here). </param>
|
|||
/// <exception cref="ArgumentNullException"> Throw this exception if the renderer is null. </exception>
|
|||
public override void Execute(ScriptableRenderer renderer, ScriptableRenderContext context, ref RenderingData renderingData) |
|||
{ |
|||
if (renderer == null) |
|||
throw new ArgumentNullException("renderer"); |
|||
|
|||
var cmd = CommandBufferPool.Get(k_ARBlitTag); |
|||
|
|||
RenderBufferLoadAction colorLoadOp = RenderBufferLoadAction.DontCare; |
|||
RenderBufferStoreAction colorStoreOp = RenderBufferStoreAction.Store; |
|||
|
|||
RenderBufferLoadAction depthLoadOp = RenderBufferLoadAction.DontCare; |
|||
RenderBufferStoreAction depthStoreOp = RenderBufferStoreAction.Store; |
|||
|
|||
SetRenderTarget(cmd, m_TargetIdentifier, colorLoadOp, colorStoreOp, |
|||
m_DepthIdentifier, depthLoadOp, depthStoreOp, ClearFlag.All, Color.clear, m_Descriptor.dimension); |
|||
|
|||
cmd.Blit(null, m_TargetIdentifier, m_BlitMaterial); |
|||
context.ExecuteCommandBuffer(cmd); |
|||
CommandBufferPool.Release(cmd); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 566adfba2b318447fb941a2ea4f3f84f |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
|
|||
using System; |
|||
using UnityEngine.Rendering; |
|||
|
|||
namespace UnityEngine.XR.ARFoundation.LWRPSupport |
|||
{ |
|||
[CreateAssetMenu(fileName = "LWRPBackgroundRendererAsset", menuName = "XR/LWRPBackgroundRendererAsset")] |
|||
public class LWRPBackgroundRendererAsset : ARBackgroundRendererAsset |
|||
{ |
|||
/// <summary>
|
|||
/// we're going to reference all materials that we want to use so that they get built into the project
|
|||
/// </summary>
|
|||
[SerializeField] |
|||
Material[] m_MaterialsUsed; |
|||
|
|||
static bool useRenderPipeline { get { return GraphicsSettings.renderPipelineAsset != null; } } |
|||
|
|||
public override ARFoundationBackgroundRenderer CreateARBackgroundRenderer() |
|||
{ |
|||
return useRenderPipeline ? new LWRPBackgroundRenderer() : new ARFoundationBackgroundRenderer(); |
|||
} |
|||
|
|||
public override void CreateHelperComponents(GameObject cameraGameObject) |
|||
{ |
|||
if (useRenderPipeline) |
|||
{ |
|||
var lwrpBeforeCameraRender = cameraGameObject.GetComponent<LWRPBeforeCameraRender>(); |
|||
if (lwrpBeforeCameraRender == null) |
|||
{ |
|||
cameraGameObject.AddComponent<LWRPBeforeCameraRender>(); |
|||
} |
|||
} |
|||
} |
|||
|
|||
public override Material CreateCustomMaterial() |
|||
{ |
|||
var cameraSubsystem = ARSubsystemManager.cameraSubsystem; |
|||
if (cameraSubsystem == null) |
|||
return null; |
|||
|
|||
// Try to create a material from the plugin's provided shader.
|
|||
var shaderName = ""; |
|||
if (!cameraSubsystem.TryGetShaderName(ref shaderName)) |
|||
return null; |
|||
|
|||
shaderName = shaderName + "LWRP"; |
|||
|
|||
var shader = Shader.Find(shaderName); |
|||
if (shader == null) |
|||
{ |
|||
throw new InvalidOperationException(string.Format( |
|||
"Could not find shader named \"{0}\" required for LWRP video overlay on camera subsystem named \"{1}\".", |
|||
shaderName, |
|||
cameraSubsystem.SubsystemDescriptor.id)); |
|||
} |
|||
|
|||
return new Material(shader); |
|||
} |
|||
} |
|||
|
|||
} |
|
|||
|
|||
using System; |
|||
using UnityEngine.Experimental.Rendering.LightweightPipeline; |
|||
using UnityEngine.Rendering; |
|||
using UnityEngine.Serialization; |
|||
|
|||
namespace UnityEngine.XR.ARFoundation.LWRPSupport |
|||
{ |
|||
[CreateAssetMenu(fileName = "LWRPBackroundRendererAsset", menuName = "XR/LWRPBackroundRendererAsset")] |
|||
public class LWRPBackroundRendererAsset : ARBackgroundRendererAsset |
|||
{ |
|||
/// <summary>
|
|||
/// we're going to reference all materials that we want to use so that they get built into the project
|
|||
/// </summary>
|
|||
[SerializeField] |
|||
Material[] m_MaterialsUsed; |
|||
|
|||
static bool useRenderPipeline { get { return GraphicsSettings.renderPipelineAsset != null; } } |
|||
|
|||
public override ARFoundationBackgroundRenderer CreateARBackgroundRenderer() |
|||
{ |
|||
return useRenderPipeline ? new LWRPBackgroundRenderer() : new ARFoundationBackgroundRenderer(); |
|||
} |
|||
|
|||
public override void CreateHelperComponents(GameObject cameraGameObject) |
|||
{ |
|||
if (useRenderPipeline) |
|||
{ |
|||
var lwrpBeforeCameraRender = cameraGameObject.GetComponent<LWRPBeforeCameraRender>(); |
|||
if (lwrpBeforeCameraRender == null) |
|||
{ |
|||
cameraGameObject.AddComponent<LWRPBeforeCameraRender>(); |
|||
} |
|||
|
|||
var lightweightAdditionalCameraData = cameraGameObject.GetComponent<LightweightAdditionalCameraData>(); |
|||
if (lightweightAdditionalCameraData == null) |
|||
{ |
|||
lightweightAdditionalCameraData = cameraGameObject.AddComponent<LightweightAdditionalCameraData>(); |
|||
} |
|||
|
|||
lightweightAdditionalCameraData.renderShadows = false; |
|||
lightweightAdditionalCameraData.requiresColorTexture = false; |
|||
lightweightAdditionalCameraData.requiresDepthTexture = false; |
|||
|
|||
} |
|||
} |
|||
|
|||
public override Material CreateCustomMaterial() |
|||
{ |
|||
var cameraSubsystem = ARSubsystemManager.cameraSubsystem; |
|||
if (cameraSubsystem == null) |
|||
return null; |
|||
|
|||
// Try to create a material from the plugin's provided shader.
|
|||
var shaderName = ""; |
|||
if (!cameraSubsystem.TryGetShaderName(ref shaderName)) |
|||
return null; |
|||
|
|||
shaderName = shaderName + "LWRP"; |
|||
|
|||
var shader = Shader.Find(shaderName); |
|||
if (shader == null) |
|||
{ |
|||
throw new InvalidOperationException(string.Format( |
|||
"Could not find shader named \"{0}\" required for LWRP video overlay on camera subsystem named \"{1}\".", |
|||
shaderName, |
|||
cameraSubsystem.SubsystemDescriptor.id)); |
|||
} |
|||
|
|||
return new Material(shader); |
|||
} |
|||
} |
|||
|
|||
} |
撰写
预览
正在加载...
取消
保存
Reference in new issue