Still new to unity but been writing shaders for hlsl/glsl for awhile. I need to pass a few parameters worth of data each frame. Did a google / doc search but think I might just be using the wrong wording or something. Any help would be much appreciated.
Also I’m getting the following run-time errors for the below shader when I try to set the parameters from the inspector.
For all my uniforms I get this error
Shader "Custom/QuadStretch" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
_GrabPosition("GrabPosition",Vector) = (0,0,0,0)
_GrabbedVertex("GrabbedVertex",Vector) = (0,0,0,0)
_Displacement("Displacement",Vector) = (0,0,0,0)
_MaxDistanceSquared("MaxDistanceSquared",Float) = 1.0
_MaxDistance("MaxDistanceSquared",Float) = 1.0
_RelaxationFactor("RelaxationFactor",Float) = 1.0
}
SubShader {
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
sampler2D _MainTex;
float4 _GrabPosition;
float4 _GrabbedVertex;
float4 _Displacement;
float _MaxDistanceSquared;
float _MaxDistance;
float _MinDistanceSquared;
float _RelaxationFactor;
struct vin
{
float4 pos : POSITION;
float4 color : COLOR0;
float2 uv : TEXCOORD0;
};
struct vout {
float4 pos : SV_POSITION;
float4 color : COLOR0;
float2 uv : TEXCOORD0;
};
//TODO: Make Sure There Is Max Distance Protection.
//PreDraw on CPU side Find GrabPosition And Set It To the equivalent
//Vector with MaxGrabDistanceMagnitude.
//Ex. If Max Distance is 1 and GrabPosition is <2,0,0> from the grabbed vertex
//Change GrabPosition To <1,0,0> Before It's Switched Over.
vout vert(vin v)
{
vout o;
float4 StaticDifference = _GrabbedVertex - v.pos; //Static Distance Between Vertices
StaticDifference.z = 0.0; //Scale only according to x,y Dimensions
float InvStaticDistSquared = dot(StaticDifference,StaticDifference); //Get Squared Distance Between The Two
if(InvStaticDistSquared < _MinDistanceSquared) //Really Only Here To Protect The Grabbed Vertex
InvStaticDistSquared = _MinDistanceSquared; //As The Distance When It's Grabbed Is Equal To Zero
InvStaticDistSquared = 1.0/InvStaticDistSquared; //Invert Distance Squared To Scale Position Based On Inverse of Distance
o.pos = v.pos + _Displacement; //Difference Between Static World Position and GrabPosition
o.pos = lerp(o.pos,_GrabPosition,InvStaticDistSquared*_RelaxationFactor); //Lerp Position Based on Inverse of Distance
o.pos = mul(UNITY_MATRIX_MVP,o.pos); //Model Space To World Space
o.color = v.color;
o.uv = v.uv;
return o;
}
float4 frag(vout v) : COLOR
{
float4 c;
c = tex2D(_MainTex,v.uv);
return c*v.color;
}
ENDCG
}
}
FallBack "Diffuse"
}