- Home /
Question by
Andreas_Lokko · Jan 12, 2017 at 12:09 PM ·
renderingshadersgraphics
How to use Graphics.DrawProcedural to render a quad over a scene?
I want to learn this so I could do some screen space particles in Unity. This is meant as a sort of "hello world" shader.
my current script is:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Runtime.InteropServices;
public class ParticleFX : MonoBehaviour
{
public int particlecount = 4;
private Material material;
void Start()
{
material = new Material(Shader.Find("Hidden/CustomParticle"));
}
void OnRenderImage(RenderTexture source, RenderTexture destination)
{
material.SetPass(0);
Graphics.DrawProcedural(MeshTopology.Quads, particlecount, 1);
}
void OnDestroy()
{
}
}
And my shader looks like this:
Shader "Hidden/CustomParticle"
{
SubShader
{
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
#pragma target 3.5
struct v2f {
fixed4 color : TEXCOORD0;
float4 pos : SV_POSITION;
};
v2f vert(
uint vid : SV_VertexID // vertex ID, needs to be uint
)
{
v2f o;
o.pos = UnityObjectToClipPos(float3(vid>>1,vid&1,1));
o.color = float4(1,0,0,1);
return o;
}
fixed4 frag(v2f i) : SV_Target
{
return i.color;
}
ENDCG
}
}
}
I expect to see a red quad cover my scene, but I don't. The core part is learning to use Graphics.DrawProcedural().
Comment