soundvision/UnityProject/Assets/Scripts/Kinect/MovementBakerRenderTexture.cs

47 lines
1.4 KiB
C#
Raw Normal View History

2019-12-13 15:14:22 +00:00
using UnityEngine;
2019-12-12 16:48:03 +00:00
namespace cylvester
{
public class MovementBakerRenderTexture : MonoBehaviour
{
[SerializeField] private RenderTexture input;
[SerializeField] private ComputeShader computeShader;
[SerializeField] private float factor = 1;
private RenderTexture resultTexture_;
private RenderTexture previousFrameTexture_;
private int kernelHandle_;
private Renderer renderer_;
private void Start()
{
resultTexture_ = new RenderTexture(input.width, input.height, 0, input.graphicsFormat) { enableRandomWrite = true };
resultTexture_.Create();
previousFrameTexture_ = new RenderTexture(input.width, input.height, 0, input.graphicsFormat) { enableRandomWrite = true };
previousFrameTexture_.Create();
kernelHandle_ = computeShader.FindKernel("CSMain");
renderer_ = GetComponent<Renderer>();
}
2019-12-13 15:14:22 +00:00
public void OnAzureUpdated()
2019-12-12 16:48:03 +00:00
{
computeShader.SetTexture(kernelHandle_, "Input", input);
computeShader.SetTexture(kernelHandle_, "Previous", previousFrameTexture_);
computeShader.SetTexture(kernelHandle_, "Result", resultTexture_);
computeShader.SetFloat("Factor", factor);
computeShader.Dispatch(kernelHandle_, 1, 1, 1);
2019-12-13 15:14:22 +00:00
renderer_.material.SetTexture("_BaseColorMap", resultTexture_);
2019-12-12 16:48:03 +00:00
}
}
}