AR Foundation演示项目,使用 AR Foundation 4.1.7 并围绕某些功能演示更高级功能。
您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 

53 行
1.5 KiB

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.XR.ARFoundation;
public class CameraGrainURP : MonoBehaviour
{
[SerializeField]
ARCameraManager m_CameraManager;
public ARCameraManager cameraManager
{
get { return m_CameraManager; }
set { m_CameraManager = value; }
}
Renderer m_Renderer;
const string k_NoiseTextureProperty = "_NoiseTex";
const string k_NoiseIntensityProperty = "_NoiseIntensity";
void OnEnable()
{
if(m_CameraManager == null)
{
m_CameraManager = FindObjectOfType<ARCameraManager>();
}
m_Renderer = GetComponent<Renderer>();
m_CameraManager.frameReceived += OnReceivedFrame;
}
void OnDisable()
{
m_CameraManager.frameReceived -= OnReceivedFrame;
}
void OnReceivedFrame(ARCameraFrameEventArgs eventArgs)
{
#if UNITY_IOS
if(m_Renderer != null && eventArgs.cameraGrainTexture != null)
{
if (m_Renderer.material.HasProperty(k_NoiseTextureProperty))
{
m_Renderer.material.SetTexture(k_NoiseTextureProperty, eventArgs.cameraGrainTexture);
}
if (m_Renderer.material.HasProperty(k_NoiseIntensityProperty))
{
m_Renderer.material.SetFloat(k_NoiseIntensityProperty, eventArgs.noiseIntensity);
}
}
#endif
}
}