Question by
Hahah0 · Mar 02, 2021 at 03:55 AM ·
lightingrenderingvertex shader
Adding lighting to vertex shader
What's the simplest way to add shadow functionality based on the modified vertices, nothing I've found online seems to work
Shader "Unlit/HyperUnlit"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_Color("Color", Color) = (1,1,1,1)
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 100
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
#include "Complex.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
UNITY_FOG_COORDS(1)
float4 vertex : SV_POSITION;
};
sampler2D _MainTex;
float4 _MainTex_ST;
fixed4 _Color;
//Params
float Tscale;
float3 Tpos;
float klein;
float Rscale;
//Mobius Transformation (a,b,c,d)
float2 a;
float2 b;
float2 c;
float2 d;
v2f vert (appdata v)
{
v2f o;
//Reduce to float3
float3 worldPos = mul(unity_ObjectToWorld, float4(v.vertex.xyz, 1)).xyz;
//2. Apply linear transformations
worldPos *= Tscale;
worldPos += Tpos;
//3. Apply mobius transformation
worldPos = MobiusXZ(a,b,c,d, worldPos);
//4. Klein?
if (klein==1)
{
worldPos = PoincareToKlein(worldPos);
}
//5. Scale to disk radius
worldPos *= Rscale;
//Convert back to ? space
o.vertex = mul(UNITY_MATRIX_VP, float4(worldPos, 1));
//transform position to clip space
//o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
return o;
}
fixed4 frag (v2f i) : SV_Target
{
// sample the texture
fixed4 col = tex2D(_MainTex, i.uv) * _Color;
return col;
}
ENDCG
}
UsePass "Legacy Shaders/VertexLit/SHADOWCASTER"
}
}
Comment