So i have multiple disconnected quads that face up in a single mesh, can i somehow displace their vertices to look at the camera instead or another vector?
using ProceduralToolkit;
public class Pointfield : MonoBehaviour
{
private Transform myTF;
private MeshDraft meshDraft = new MeshDraft();
private MeshFilter meshFilter;
private MeshRenderer meshRenderer;
private MeshCollider meshCollider;
public int pointCount = 100;
public float pointRadius = 0.2f;
public float radius = 10;
private void Start()
{
myTF = GetComponent<Transform>();
meshFilter = myTF.GetComponent<MeshFilter>();
meshRenderer = myTF.GetComponent<MeshRenderer>();
meshCollider = myTF.GetComponent<MeshCollider>();
Create();
}
private void Create()
{
for(int i = 0; i < pointCount; i++)
{
Vector3 position = Random.insideUnitSphere * radius;
Vector3 c1 = position + (((Vector3.back + Vector3.left) / 2) * pointRadius);
Vector3 c2 = position + (((Vector3.forward + Vector3.left) / 2) * pointRadius);
Vector3 c3 = position + (((Vector3.forward + Vector3.right) / 2) * pointRadius);
Vector3 c4 = position + (((Vector3.back + Vector3.right) / 2) * pointRadius);
MeshDraft quad = MeshDraft.Quad(c1, c2, c3, c4);
meshDraft.Add(quad);
}
Render();
}
private void Render()
{
meshFilter.mesh = meshDraft.ToMesh();
}
}
Shader "Custom/GS Billboard"
{
Properties
{
_SpriteTex ("Base (RGB)", 2D) = "white" {}
_Size ("Size", Range(0, 3)) = 0.5
}
SubShader
{
Pass
{
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
#pragma target 5.0
#pragma vertex VS_Main
#pragma fragment FS_Main
#pragma geometry GS_Main
#include "UnityCG.cginc"
// **************************************************************
// Data structures *
// **************************************************************
struct GS_INPUT
{
float4 pos : POSITION;
float3 normal : NORMAL;
float2 tex0 : TEXCOORD0;
};
struct FS_INPUT
{
float4 pos : POSITION;
float2 tex0 : TEXCOORD0;
};
// **************************************************************
// Vars *
// **************************************************************
float _Size;
float4x4 _VP;
Texture2D _SpriteTex;
SamplerState sampler_SpriteTex;
// **************************************************************
// Shader Programs *
// **************************************************************
// Vertex Shader ------------------------------------------------
GS_INPUT VS_Main(appdata_base v)
{
GS_INPUT output = (GS_INPUT)0;
output.pos = mul(unity_ObjectToWorld, v.vertex);
output.normal = v.normal;
output.tex0 = float2(0, 0);
return output;
}
// Geometry Shader -----------------------------------------------------
[maxvertexcount(4)]
void GS_Main(point GS_INPUT p[1], inout TriangleStream<FS_INPUT> triStream)
{
float3 up = UNITY_MATRIX_IT_MV[0].xyz;
float3 look = _WorldSpaceCameraPos - p[0].pos;
look.y = 0;
look = normalize(look);
float3 right = UNITY_MATRIX_IT_MV[1].xyz;
float halfS = 0.5f * _Size;
float4 v[4];
v[0] = float4(p[0].pos + halfS * right - halfS * up, 1.0f);
v[1] = float4(p[0].pos + halfS * right + halfS * up, 1.0f);
v[2] = float4(p[0].pos - halfS * right - halfS * up, 1.0f);
v[3] = float4(p[0].pos - halfS * right + halfS * up, 1.0f);
FS_INPUT pIn;
pIn.pos = UnityObjectToClipPos(v[0]);
pIn.tex0 = float2(1.0f, 0.0f);
triStream.Append(pIn);
pIn.pos = UnityObjectToClipPos(v[1]);
pIn.tex0 = float2(1.0f, 1.0f);
triStream.Append(pIn);
pIn.pos = UnityObjectToClipPos(v[2]);
pIn.tex0 = float2(0.0f, 0.0f);
triStream.Append(pIn);
pIn.pos = UnityObjectToClipPos(v[3]);
pIn.tex0 = float2(0.0f, 1.0f);
triStream.Append(pIn);
}
// Fragment Shader -----------------------------------------------
float4 FS_Main(FS_INPUT input) : COLOR
{
return _SpriteTex.Sample(sampler_SpriteTex, input.tex0);
}
ENDCG
}
}
}
Return to Amplify Shader Editor
Users browsing this forum: No registered users and 90 guests