Reputation: 11
I have imported an underwater effect shader from the following youtube video: https://www.youtube.com/watch?v=GweaV8ZO7oA
However, the following errors show up at the console. I assume this is because of the version difference of the unity editor. I have tried to get an understanding of the errors for the past days but couldn't find anything.
here is the shader script:
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
public class Underwater : ScriptableRendererFeature
{
[System.Serializable]
public class Settings
{
//future settings
public Material material;
public RenderPassEvent renderPassEvent = RenderPassEvent.AfterRenderingSkybox;
public Color color;
public float distance = 10;
[Range(0, 1)]
public float alpha;
public float refraction = 0.1f;
public Texture normalmap;
public Vector4 UV = new Vector4(1,1,0.2f,0.1f);
}
public Settings settings = new Settings();
class Pass : ScriptableRenderPass
{
public Settings settings;
private RenderTargetIdentifier source;
RenderTargetHandle tempTexture;
private string profilerTag;
public void Setup(RenderTargetIdentifier source)
{
this.source = source;
}
public Pass(string profilerTag)
{
this.profilerTag = profilerTag;
}
public override void Configure(CommandBuffer cmd, RenderTextureDescriptor cameraTextureDescriptor)
{
cmd.GetTemporaryRT(tempTexture.id, cameraTextureDescriptor);
ConfigureTarget(tempTexture.Identifier());
ConfigureClear(ClearFlag.All, Color.black);
}
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
{
CommandBuffer cmd = CommandBufferPool.Get(profilerTag);
cmd.Clear();
//it is very important that if something fails our code still calls
//CommandBufferPool.Release(cmd) or we will have a HUGE memory leak
try
{
//here we set out material properties
//...
settings.material.SetFloat("_dis", settings.distance);
settings.material.SetFloat("_alpha", settings.alpha);
settings.material.SetColor("_color", settings.color);
settings.material.SetTexture("_NormalMap", settings.normalmap);
settings.material.SetFloat("_refraction", settings.refraction);
settings.material.SetVector("_normalUV", settings.UV);
//never use a Blit from source to source, as it only works with MSAA
// enabled and the scene view doesnt have MSAA,
// so the scene view will be pure black
cmd.Blit(source, tempTexture.Identifier());
cmd.Blit(tempTexture.Identifier(), source, settings.material, 0);
context.ExecuteCommandBuffer(cmd);
}
catch
{
Debug.LogError("Error");
}
cmd.Clear();
CommandBufferPool.Release(cmd);
}
}
Pass pass;
RenderTargetHandle renderTextureHandle;
public override void Create()
{
pass = new Pass("Underwater Effects");
name = "Underwater Effects";
pass.settings = settings;
pass.renderPassEvent = settings.renderPassEvent;
}
public override void SetupRenderPasses(ScriptableRenderer renderer, in RenderingData renderingData)
{
var cameraColorTargetIdent = renderer.cameraColorTarget;
pass.Setup(cameraColorTargetIdent);
}
public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData)
{
renderer.EnqueuePass(pass);
}
}
How may I fix these errors?
Upvotes: 0
Views: 22