Unity HDRP-CustomRenderTexture不起作用?

问题描述 投票:0回答:1

我正在尝试用鼠标绘制纹理。鼠标坐标被赋予一个着色器,该着色器输出到渲染纹理(我已经尝试了直接受材质直接影响的常规RenterTexture和CustomRenderTexture),但似乎不起作用。我可以从资料中得知已经获得了鼠标的输入,但是在渲染纹理上看不到任何东西。

我开始怀疑渲染纹理在HDRP中不能完全正常工作?希望有人可以指出可能是真正问题的方向。

我在Unity 2019.3.0f3中,着色器是HDRP Unlit Graph

这是我的脚本:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class DrawWithMouse : MonoBehaviour
{
    public Camera _camera;
    public CustomRenderTexture _splatmap;

    public Material _drawMaterial;

    private RaycastHit _hit;

    [Range(1, 100)]
    public float _brushSize = 1f;
    [Range(0, 10)]
    public float _brushStrength = 1f;

    private readonly float m_GUIsize = 256;
    private readonly int m_RenderTexSize = 1024;

    void Start()
    {
        _splatmap = new CustomRenderTexture(m_RenderTexSize, m_RenderTexSize, RenderTextureFormat.ARGBFloat, RenderTextureReadWrite.Linear)
        {
            name = "splatmap_CRT_generated",
            initializationColor = Color.black,
            initializationSource = CustomRenderTextureInitializationSource.Material,
            initializationMaterial = _drawMaterial,
            material = _drawMaterial,
            doubleBuffered = true,
            updateMode = CustomRenderTextureUpdateMode.OnDemand
        };

        _drawMaterial.SetVector("_DrawColor", Color.red);
        _drawMaterial.SetTexture("_SplatMap", _splatmap);
    }

    void Update()
    {
        if (Input.GetKey(KeyCode.Mouse0))
        {
            if (Physics.Raycast(_camera.ScreenPointToRay(Input.mousePosition), out _hit, 100f))
            {
                _drawMaterial.SetVector("_InputPoint", new Vector4(_hit.textureCoord.x, _hit.textureCoord.y, 0, 0));
                _drawMaterial.SetFloat("_BrushStrength", _brushStrength);
                _drawMaterial.SetFloat("_BrushSize", _brushSize);
            }
        }
    }


    private void OnGUI()
    {
        GUI.DrawTexture(new Rect(0, 0, m_GUIsize, m_GUIsize), _splatmap, ScaleMode.StretchToFill, false, 1);
    }

}
unity3d shader textures
1个回答
0
投票

@@ MadsM您对此有任何更新吗?我在2019.3.0f5中面临同样的问题,只是无法正常工作。我正在尝试更新SnowTracksShaderGraph sample by Tim Neville,您的代码使我想起了它。

© www.soinside.com 2019 - 2024. All rights reserved.