浏览代码
allow arfoundation-samples to support LWRP, with a little help from ARFoundation. we could take the changes in the LWRPSupport folder and make them into a separate package (they already have their own assembly). The main idea is when you upgrade to LWRP (by setting up a LWRP settings asset in the graphics settings), you will at the same time, create a LWRPBackgroundRendererAsset, add the two materials in the folder to it, and set it as Custom Renderer Asset on your CameraBackground component on ARCamera.
/1.5-preview
allow arfoundation-samples to support LWRP, with a little help from ARFoundation. we could take the changes in the LWRPSupport folder and make them into a separate package (they already have their own assembly). The main idea is when you upgrade to LWRP (by setting up a LWRP settings asset in the graphics settings), you will at the same time, create a LWRPBackgroundRendererAsset, add the two materials in the folder to it, and set it as Custom Renderer Asset on your CameraBackground component on ARCamera.
/1.5-preview
Jimmy Alamparambil
6 年前
当前提交
2c980b8d
共有 24 个文件被更改,包括 718 次插入 和 56 次删除
-
128Assets/Scenes/SampleScene.unity
-
7ProjectSettings/GraphicsSettings.asset
-
8Assets/LWRPSupport.meta
-
29Assets/Prefabs/LightweightRP.asset
-
8Assets/Prefabs/LightweightRP.asset.meta
-
56Assets/LWRPSupport/ARCoreBackgroundLWRP.shader
-
9Assets/LWRPSupport/ARCoreBackgroundLWRP.shader.meta
-
87Assets/LWRPSupport/ARCoreBackgroundLWRPMaterial.mat
-
8Assets/LWRPSupport/ARCoreBackgroundLWRPMaterial.mat.meta
-
95Assets/LWRPSupport/ARKitLWRPMaterial.mat
-
8Assets/LWRPSupport/ARKitLWRPMaterial.mat.meta
-
77Assets/LWRPSupport/ARKitLWRPShader.shader
-
9Assets/LWRPSupport/ARKitLWRPShader.shader.meta
-
56Assets/LWRPSupport/LWRPBackgroundRenderer.cs
-
11Assets/LWRPSupport/LWRPBackgroundRenderer.cs.meta
-
17Assets/LWRPSupport/LWRPBackroundRendererAsset.asset
-
8Assets/LWRPSupport/LWRPBackroundRendererAsset.asset.meta
-
73Assets/LWRPSupport/LWRPBackroundRendererAsset.cs
-
11Assets/LWRPSupport/LWRPBackroundRendererAsset.cs.meta
-
35Assets/LWRPSupport/LWRPBeforeCameraRender.cs
-
11Assets/LWRPSupport/LWRPBeforeCameraRender.cs.meta
-
16Assets/LWRPSupport/Unity.XR.ARFoundation.LWRPSupport.asmdef
-
7Assets/LWRPSupport/Unity.XR.ARFoundation.LWRPSupport.asmdef.meta
|
|||
fileFormatVersion: 2 |
|||
guid: 276a124b17bce4dfb829de86ace2732f |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
%YAML 1.1 |
|||
%TAG !u! tag:unity3d.com,2011: |
|||
--- !u!114 &11400000 |
|||
MonoBehaviour: |
|||
m_ObjectHideFlags: 0 |
|||
m_PrefabParentObject: {fileID: 0} |
|||
m_PrefabInternal: {fileID: 0} |
|||
m_GameObject: {fileID: 0} |
|||
m_Enabled: 1 |
|||
m_EditorHideFlags: 0 |
|||
m_Script: {fileID: 11500000, guid: bf2edee5c58d82540a51f03df9d42094, type: 3} |
|||
m_Name: LightweightRP |
|||
m_EditorClassIdentifier: |
|||
kAssetVersion: 2 |
|||
m_MaxPixelLights: 4 |
|||
m_SupportsVertexLight: 0 |
|||
m_RequireDepthTexture: 0 |
|||
m_RequireSoftParticles: 0 |
|||
m_SupportsHDR: 0 |
|||
m_MSAA: 4 |
|||
m_RenderScale: 1 |
|||
m_ShadowType: 1 |
|||
m_ShadowAtlasResolution: 2048 |
|||
m_ShadowNearPlaneOffset: 2 |
|||
m_ShadowDistance: 50 |
|||
m_ShadowCascades: 2 |
|||
m_Cascade2Split: 0.25 |
|||
m_Cascade4Split: {x: 0.067, y: 0.2, z: 0.467} |
|||
m_ResourcesAsset: {fileID: 11400000, guid: aac5a08c32552a14c89394b703f1978a, type: 2} |
|
|||
fileFormatVersion: 2 |
|||
guid: b01a4952003554c0191ed57356e5830a |
|||
NativeFormatImporter: |
|||
externalObjects: {} |
|||
mainObjectFileID: 11400000 |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
Shader "Unlit/ARCoreBackgroundLWRP" |
|||
{ |
|||
Properties |
|||
{ |
|||
_MainTex("Texture", 2D) = "white" {} |
|||
} |
|||
|
|||
// For GLES3 |
|||
SubShader |
|||
{ |
|||
Pass |
|||
{ |
|||
ZWrite Off |
|||
|
|||
GLSLPROGRAM |
|||
|
|||
#pragma only_renderers gles3 |
|||
|
|||
#ifdef SHADER_API_GLES3 |
|||
#extension GL_OES_EGL_image_external_essl3 : require |
|||
#endif |
|||
|
|||
uniform mat4 _UnityDisplayTransform; |
|||
|
|||
#ifdef VERTEX |
|||
varying vec2 textureCoord; |
|||
|
|||
void main() |
|||
{ |
|||
#ifdef SHADER_API_GLES3 |
|||
float flippedV = 1.0 - gl_MultiTexCoord0.y; |
|||
textureCoord.x = _UnityDisplayTransform[0].x * gl_MultiTexCoord0.x + _UnityDisplayTransform[1].x * flippedV + _UnityDisplayTransform[2].x; |
|||
textureCoord.y = _UnityDisplayTransform[0].y * gl_MultiTexCoord0.x + _UnityDisplayTransform[1].y * flippedV + _UnityDisplayTransform[2].y; |
|||
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; |
|||
#endif |
|||
} |
|||
#endif |
|||
|
|||
#ifdef FRAGMENT |
|||
varying vec2 textureCoord; |
|||
uniform samplerExternalOES _MainTex; |
|||
|
|||
void main() |
|||
{ |
|||
#ifdef SHADER_API_GLES3 |
|||
gl_FragColor = texture(_MainTex, textureCoord); |
|||
#endif |
|||
} |
|||
|
|||
#endif |
|||
ENDGLSL |
|||
} |
|||
} |
|||
|
|||
FallBack Off |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: f5b5c0be693bb45f9b7b9f28210c1c87 |
|||
ShaderImporter: |
|||
externalObjects: {} |
|||
defaultTextures: [] |
|||
nonModifiableTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
%YAML 1.1 |
|||
%TAG !u! tag:unity3d.com,2011: |
|||
--- !u!21 &2100000 |
|||
Material: |
|||
serializedVersion: 6 |
|||
m_ObjectHideFlags: 0 |
|||
m_CorrespondingSourceObject: {fileID: 0} |
|||
m_PrefabInstance: {fileID: 0} |
|||
m_PrefabAsset: {fileID: 0} |
|||
m_Name: ARCoreBackgroundLWRPMaterial |
|||
m_Shader: {fileID: 4800000, guid: f5b5c0be693bb45f9b7b9f28210c1c87, type: 3} |
|||
m_ShaderKeywords: |
|||
m_LightmapFlags: 4 |
|||
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: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
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 |
|||
- _ReceiveShadows: 1 |
|||
- _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.2, g: 0.2, b: 0.2, a: 1} |
|
|||
fileFormatVersion: 2 |
|||
guid: 5bd0883a437ba4ed8a4572cda9d2e23d |
|||
NativeFormatImporter: |
|||
externalObjects: {} |
|||
mainObjectFileID: 2100000 |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
%YAML 1.1 |
|||
%TAG !u! tag:unity3d.com,2011: |
|||
--- !u!21 &2100000 |
|||
Material: |
|||
serializedVersion: 6 |
|||
m_ObjectHideFlags: 0 |
|||
m_CorrespondingSourceObject: {fileID: 0} |
|||
m_PrefabInstance: {fileID: 0} |
|||
m_PrefabAsset: {fileID: 0} |
|||
m_Name: ARKitLWRPMaterial |
|||
m_Shader: {fileID: 4800000, guid: 5c791e8fa990e481990e754655cd123d, type: 3} |
|||
m_ShaderKeywords: |
|||
m_LightmapFlags: 4 |
|||
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: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
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} |
|||
- _textureCbCr: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _textureY: |
|||
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 |
|||
- _ReceiveShadows: 1 |
|||
- _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.2, g: 0.2, b: 0.2, a: 1} |
|
|||
fileFormatVersion: 2 |
|||
guid: 91c809f5df4d84941a85f4cd21a290f7 |
|||
NativeFormatImporter: |
|||
externalObjects: {} |
|||
mainObjectFileID: 2100000 |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
Shader "Unlit/ARKitLWRP" |
|||
{ |
|||
Properties |
|||
{ |
|||
_textureY ("TextureY", 2D) = "white" {} |
|||
_textureCbCr ("TextureCbCr", 2D) = "black" {} |
|||
} |
|||
|
|||
SubShader |
|||
{ |
|||
Tags { "RenderType" = "Opaque" "RenderPipeline" = "LightweightPipeline"} |
|||
LOD 100 |
|||
|
|||
Pass |
|||
{ |
|||
Name "Default" |
|||
Tags { "LightMode" = "LightweightForward"} |
|||
|
|||
ZTest Always ZWrite Off |
|||
|
|||
HLSLPROGRAM |
|||
// Required to compile gles 2.0 with standard srp library |
|||
#pragma prefer_hlslcc gles |
|||
#pragma exclude_renderers d3d11_9x |
|||
#pragma vertex Vertex |
|||
#pragma fragment Fragment |
|||
|
|||
#include "LWRP/ShaderLibrary/Core.hlsl" |
|||
|
|||
float4x4 _UnityDisplayTransform; |
|||
|
|||
struct VertexInput |
|||
{ |
|||
float4 vertex : POSITION; |
|||
float2 uv : TEXCOORD0; |
|||
}; |
|||
|
|||
struct VertexOutput |
|||
{ |
|||
half4 pos : SV_POSITION; |
|||
half2 uv : TEXCOORD0; |
|||
}; |
|||
|
|||
|
|||
TEXTURE2D(_textureY); |
|||
SAMPLER(sampler_textureY); |
|||
TEXTURE2D(_textureCbCr); |
|||
SAMPLER(sampler_textureCbCr); |
|||
|
|||
VertexOutput Vertex(VertexInput i) |
|||
{ |
|||
VertexOutput o; |
|||
o.pos = TransformObjectToHClip(i.vertex.xyz); |
|||
o.uv.x = (_UnityDisplayTransform[0].x * i.uv.x + _UnityDisplayTransform[1].x * (i.uv.y) + _UnityDisplayTransform[2].x); |
|||
o.uv.y = (_UnityDisplayTransform[0].y * i.uv.x + _UnityDisplayTransform[1].y * (i.uv.y) + _UnityDisplayTransform[2].y); |
|||
return o; |
|||
} |
|||
|
|||
half4 Fragment(VertexOutput i) : SV_Target |
|||
{ |
|||
half y = SAMPLE_TEXTURE2D(_textureY, sampler_textureY, i.uv).r; |
|||
half4 ycbcr = half4(y, SAMPLE_TEXTURE2D(_textureCbCr, sampler_textureCbCr, i.uv).rg, 1.0); |
|||
|
|||
const half4x4 ycbcrToRGBTransform = half4x4( |
|||
half4(1.0, +0.0000, +1.4020, -0.7010), |
|||
half4(1.0, -0.3441, -0.7141, +0.5291), |
|||
half4(1.0, +1.7720, +0.0000, -0.8860), |
|||
half4(0.0, +0.0000, +0.0000, +1.0000) |
|||
); |
|||
|
|||
return mul(ycbcrToRGBTransform, ycbcr); |
|||
} |
|||
ENDHLSL |
|||
} |
|||
} |
|||
|
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 5c791e8fa990e481990e754655cd123d |
|||
ShaderImporter: |
|||
externalObjects: {} |
|||
defaultTextures: [] |
|||
nonModifiableTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
|
|||
namespace UnityEngine.XR.ARFoundation.LWRPSupport |
|||
{ |
|||
|
|||
public class LWRPBackgroundRenderer : ARFoundationBackgroundRenderer |
|||
{ |
|||
CameraClearFlags _savedClearFlags; |
|||
LWRPBeforeCameraRender _lwrpBeforeCameraRender; |
|||
|
|||
protected override bool EnableARBackgroundRendering() |
|||
{ |
|||
if (m_BackgroundMaterial == null) |
|||
return false; |
|||
|
|||
camera = m_Camera ? m_Camera : Camera.main; |
|||
|
|||
if (camera == null) |
|||
return false; |
|||
|
|||
// Clear flags
|
|||
_savedClearFlags = camera.clearFlags; |
|||
camera.clearFlags = CameraClearFlags.Depth; |
|||
|
|||
if (_lwrpBeforeCameraRender == null) |
|||
{ |
|||
_lwrpBeforeCameraRender = camera.gameObject.GetComponent<LWRPBeforeCameraRender>(); |
|||
} |
|||
|
|||
_lwrpBeforeCameraRender.SetupBlitMaterial(m_BackgroundMaterial); |
|||
|
|||
return true; |
|||
|
|||
} |
|||
|
|||
|
|||
protected override void DisableARBackgroundRendering() |
|||
{ |
|||
if (m_BackgroundMaterial == null) |
|||
return; |
|||
|
|||
camera = m_Camera ? m_Camera : Camera.main; |
|||
if (camera == null) |
|||
return; |
|||
camera.clearFlags = _savedClearFlags; |
|||
|
|||
if (_lwrpBeforeCameraRender != null) |
|||
{ |
|||
_lwrpBeforeCameraRender.SetupBlitMaterial(null); |
|||
_lwrpBeforeCameraRender = null; |
|||
} |
|||
|
|||
} |
|||
|
|||
} |
|||
|
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 8ac2dfa07b5724f759d9f7fa54ba3713 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
%YAML 1.1 |
|||
%TAG !u! tag:unity3d.com,2011: |
|||
--- !u!114 &11400000 |
|||
MonoBehaviour: |
|||
m_ObjectHideFlags: 0 |
|||
m_CorrespondingSourceObject: {fileID: 0} |
|||
m_PrefabInstance: {fileID: 0} |
|||
m_PrefabAsset: {fileID: 0} |
|||
m_GameObject: {fileID: 0} |
|||
m_Enabled: 1 |
|||
m_EditorHideFlags: 0 |
|||
m_Script: {fileID: 11500000, guid: 3974c4b6d5b67422c935da45b02d23f2, type: 3} |
|||
m_Name: LWRPBackroundRendererAsset |
|||
m_EditorClassIdentifier: |
|||
MaterialsUsed: |
|||
- {fileID: 2100000, guid: 91c809f5df4d84941a85f4cd21a290f7, type: 2} |
|||
- {fileID: 2100000, guid: 5bd0883a437ba4ed8a4572cda9d2e23d, type: 2} |
|
|||
fileFormatVersion: 2 |
|||
guid: 2310b94e2d8f5463ab592fa99eefbe6f |
|||
NativeFormatImporter: |
|||
externalObjects: {} |
|||
mainObjectFileID: 11400000 |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
|
|||
using System; |
|||
using UnityEngine.Experimental.Rendering.LightweightPipeline; |
|||
using UnityEngine.Rendering; |
|||
|
|||
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>
|
|||
public Material[] MaterialsUsed; |
|||
|
|||
public override ARFoundationBackgroundRenderer CreateARBackgroundRenderer() |
|||
{ |
|||
var bUseRenderPipeline = GraphicsSettings.renderPipelineAsset != null; |
|||
return bUseRenderPipeline ? new LWRPBackgroundRenderer() : new ARFoundationBackgroundRenderer(); |
|||
} |
|||
|
|||
public override void CreateHelperComponents(GameObject cameraGameObject) |
|||
{ |
|||
var bUseRenderPipeline = GraphicsSettings.renderPipelineAsset != null; |
|||
|
|||
if (bUseRenderPipeline) |
|||
{ |
|||
var lbcr = cameraGameObject.GetComponent<LWRPBeforeCameraRender>(); |
|||
if (lbcr == null) |
|||
{ |
|||
cameraGameObject.AddComponent<LWRPBeforeCameraRender>(); |
|||
} |
|||
|
|||
var lacd = cameraGameObject.GetComponent<LightweightAdditionalCameraData>(); |
|||
if (lacd == null) |
|||
{ |
|||
lacd = cameraGameObject.AddComponent<LightweightAdditionalCameraData>(); |
|||
} |
|||
|
|||
lacd.renderShadows = false; |
|||
lacd.requiresColorTexture = false; |
|||
lacd.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.
|
|||
string 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); |
|||
} |
|||
} |
|||
|
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 3974c4b6d5b67422c935da45b02d23f2 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
|
|||
|
|||
using UnityEngine.Experimental.Rendering; |
|||
using UnityEngine.Rendering; |
|||
using UnityEngine.Experimental.Rendering.LightweightPipeline; |
|||
|
|||
namespace UnityEngine.XR.ARFoundation |
|||
{ |
|||
|
|||
public class LWRPBeforeCameraRender : MonoBehaviour, LightweightPipeline.IBeforeCameraRender |
|||
{ |
|||
const string k_ARBlitTag = "ARBackground Blit Pass"; |
|||
|
|||
Material BlitMaterial { get; set; } |
|||
|
|||
public void SetupBlitMaterial(Material material) |
|||
{ |
|||
this.BlitMaterial = material; |
|||
} |
|||
|
|||
public void ExecuteBeforeCameraRender(ScriptableRenderContext context, Camera camera, LightweightPipeline.PipelineSettings pipelineSettings, |
|||
ScriptableRenderer renderer) |
|||
{ |
|||
if (BlitMaterial == null) return; |
|||
|
|||
CommandBuffer cmd = CommandBufferPool.Get(k_ARBlitTag); |
|||
|
|||
cmd.Blit(null, BuiltinRenderTextureType.CameraTarget, BlitMaterial); |
|||
|
|||
context.ExecuteCommandBuffer(cmd); |
|||
CommandBufferPool.Release(cmd); |
|||
|
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: f99128193f4d0421f95800f6ccd0c2c3 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
{ |
|||
"name": "Unity.XR.ARFoundation.LWRPSupport", |
|||
"references": [ |
|||
"Unity.XR.ARFoundation", |
|||
"Unity.RenderPipelines.Lightweight.Runtime", |
|||
"Unity.RenderPipelines.Core.Runtime" |
|||
], |
|||
"optionalUnityReferences": [], |
|||
"includePlatforms": [], |
|||
"excludePlatforms": [], |
|||
"allowUnsafeCode": false, |
|||
"overrideReferences": false, |
|||
"precompiledReferences": [], |
|||
"autoReferenced": true, |
|||
"defineConstraints": [] |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 2a16b207c1243468a9f3d32431fa21b2 |
|||
AssemblyDefinitionImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue