trying to scale the result
This commit is contained in:
parent
27339bdda4
commit
4924f9abe5
|
@ -369,6 +369,10 @@ MonoBehaviour:
|
||||||
_computeShader: {fileID: 7200000, guid: 3df3413c2fff3cc41a2eb5505b4c260c, type: 3}
|
_computeShader: {fileID: 7200000, guid: 3df3413c2fff3cc41a2eb5505b4c260c, type: 3}
|
||||||
_inputTexture: {fileID: 10309, guid: 0000000000000000f000000000000000, type: 0}
|
_inputTexture: {fileID: 10309, guid: 0000000000000000f000000000000000, type: 0}
|
||||||
_resultTexture: {fileID: 0}
|
_resultTexture: {fileID: 0}
|
||||||
|
_width: 0
|
||||||
|
_height: 0
|
||||||
|
_scale: 5
|
||||||
|
_resize: 0
|
||||||
--- !u!1 &963194225
|
--- !u!1 &963194225
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
@ -404,8 +408,8 @@ Camera:
|
||||||
m_GameObject: {fileID: 963194225}
|
m_GameObject: {fileID: 963194225}
|
||||||
m_Enabled: 1
|
m_Enabled: 1
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
m_ClearFlags: 1
|
m_ClearFlags: 2
|
||||||
m_BackGroundColor: {r: 1, g: 1, b: 1, a: 0}
|
m_BackGroundColor: {r: 0.21960786, g: 0.21960786, b: 0.21960786, a: 0}
|
||||||
m_projectionMatrixMode: 1
|
m_projectionMatrixMode: 1
|
||||||
m_GateFitMode: 2
|
m_GateFitMode: 2
|
||||||
m_FOVAxisMode: 0
|
m_FOVAxisMode: 0
|
||||||
|
|
|
@ -1,34 +1,70 @@
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.Serialization;
|
using UnityEngine.Serialization;
|
||||||
|
using UnityEngine.UIElements;
|
||||||
|
|
||||||
public class ComputeController : MonoBehaviour
|
public class ComputeController : MonoBehaviour
|
||||||
{
|
{
|
||||||
|
[Header("Conections")]
|
||||||
[SerializeField] private ComputeShader _computeShader;
|
[SerializeField] private ComputeShader _computeShader;
|
||||||
[SerializeField] private Texture2D _inputTexture;
|
[SerializeField] private Texture2D _inputTexture;
|
||||||
[SerializeField] private RenderTexture _resultTexture;
|
[SerializeField] private RenderTexture _resultTexture;
|
||||||
|
|
||||||
|
[Header("Config")]
|
||||||
|
[SerializeField] private int _width;
|
||||||
|
[SerializeField] private int _height;
|
||||||
|
[SerializeField] private float _scale = 1;
|
||||||
|
[SerializeField] private bool _resize;
|
||||||
|
|
||||||
private int _kernelHandle;
|
private int _kernelHandle;
|
||||||
private static readonly int Result = Shader.PropertyToID("result");
|
private static readonly int Result = Shader.PropertyToID("result");
|
||||||
private static readonly int SourceTexture = Shader.PropertyToID("source_texture");
|
private static readonly int SourceTexture = Shader.PropertyToID("source_texture");
|
||||||
|
|
||||||
|
private static readonly int _threadgroupX = 8;
|
||||||
|
private static readonly int _threadgroupY = 8;
|
||||||
|
|
||||||
private void Start()
|
private void Start()
|
||||||
{
|
{
|
||||||
|
SetWidthHeight();
|
||||||
|
|
||||||
|
|
||||||
_kernelHandle = _computeShader.FindKernel("cs_main");
|
_kernelHandle = _computeShader.FindKernel("cs_main");
|
||||||
|
|
||||||
_resultTexture = new(512, 512, 24);
|
RunComputeShader();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void RunComputeShader()
|
||||||
|
{
|
||||||
|
_resultTexture = new(_width, _height, 24);
|
||||||
_resultTexture.name = "ResultTexture";
|
_resultTexture.name = "ResultTexture";
|
||||||
_resultTexture.enableRandomWrite = true;
|
_resultTexture.enableRandomWrite = true;
|
||||||
_resultTexture.Create();
|
_resultTexture.Create();
|
||||||
|
|
||||||
_computeShader.SetTexture(_kernelHandle, Result, _resultTexture);
|
|
||||||
_computeShader.SetTexture(_kernelHandle, SourceTexture, _inputTexture);
|
_computeShader.SetTexture(_kernelHandle, SourceTexture, _inputTexture);
|
||||||
|
_computeShader.SetTexture(_kernelHandle, Result, _resultTexture);
|
||||||
|
|
||||||
_computeShader.Dispatch(_kernelHandle, _resultTexture.width / 8, _resultTexture.height / 8, 1);
|
_computeShader.Dispatch(_kernelHandle, _width / _threadgroupX, _height / _threadgroupY, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnGUI()
|
private void OnGUI()
|
||||||
{
|
{
|
||||||
GUI.DrawTexture(new Rect(0, 0, _resultTexture.width, _resultTexture.height), _resultTexture);
|
CheckScale();
|
||||||
GUI.DrawTexture(new Rect(0, 0, _inputTexture.width, _inputTexture.height), _inputTexture);
|
GUI.DrawTexture(new Rect(0, 0, _width, _height), _inputTexture);
|
||||||
|
GUI.DrawTexture(new Rect(0, _height, _width, _height), _resultTexture);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CheckScale()
|
||||||
|
{
|
||||||
|
if (_resize)
|
||||||
|
{
|
||||||
|
_resize = false;
|
||||||
|
SetWidthHeight();
|
||||||
|
RunComputeShader();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetWidthHeight()
|
||||||
|
{
|
||||||
|
_width = Mathf.RoundToInt(_inputTexture.width * _scale);
|
||||||
|
_height = Mathf.RoundToInt(_inputTexture.height * _scale);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -12,5 +12,6 @@ void cs_main(uint3 id : SV_DispatchThreadID)
|
||||||
float4 color = source_texture[id.xy];
|
float4 color = source_texture[id.xy];
|
||||||
color.rgb = 1 - color.rgb;
|
color.rgb = 1 - color.rgb;
|
||||||
//color.rgb = float4(0, 1, 1, 0);
|
//color.rgb = float4(0, 1, 1, 0);
|
||||||
|
//color.rgb = float4(0, 1, 1, 0);
|
||||||
result[id.xy] = color;
|
result[id.xy] = color;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue