I am trying to blit material made in ShaderGraph onto RenderTexture. And it doesn't work
The code of my script:
using UnityEngine.UI;
#if UNITY_EDITOR
using UnityEditor;
#endif
[ExecuteInEditMode]
public class TerrainGenerator : MonoBehaviour
{
[SerializeField] private Terrain terrain;
[SerializeField] private Material material;
public RenderTexture renderTexture;
[ContextMenu("Generate Terrain texture")]
public void GenerateTerrainTexture()
{
if (terrain == null || material == null || renderTexture == null)
{
Debug.Log("Terrain generation failed");
return;
}
Graphics.Blit(Texture2D.whiteTexture, renderTexture, material);
}
private void OnValidate()
{
if(renderTexture == null)
{
renderTexture = RenderTexture.GetTemporary(1024, 1024, 0, RenderTextureFormat.RFloat);
}
}
}
[CustomEditor(typeof(TerrainGenerator))]
public class TerrainGeneratorEditor : Editor
{
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
TerrainGenerator terrainGenerator = (TerrainGenerator)target;
if (GUILayout.Button("Generate Terrain texture"))
{
terrainGenerator.GenerateTerrainTexture();
}
RenderTexture texture = terrainGenerator.renderTexture;
if(texture){
GUILayout.Label("Preview", EditorStyles.boldLabel);
Rect rect = GUILayoutUtility.GetAspectRect(texture.width / (float)texture.height);
EditorGUI.DrawPreviewTexture(rect, texture);
}
}
}```
My shader (screenshot)
Please help me fix this