Skip to content

Instantly share code, notes, and snippets.

@g0ody
Last active May 10, 2024 02:50
Show Gist options
  • Save g0ody/5550039 to your computer and use it in GitHub Desktop.
Save g0ody/5550039 to your computer and use it in GitHub Desktop.
A Shader to make everything cruved in Unity3D
Shader "Platogo/Curved" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
_QOffset ("Offset", Vector) = (0,0,0,0)
_Dist ("Distance", Float) = 100.0
}
SubShader {
Tags { "RenderType"="Opaque" }
Pass
{
Lighting Off
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
sampler2D _MainTex;
float4 _QOffset;
float _Dist;
uniform float4 _MainTex_ST;
struct v2f {
float4 pos : SV_POSITION;
float2 uv : TEXCOORD0;
};
v2f vert (appdata_base v)
{
v2f o;
float4 vPos = mul (UNITY_MATRIX_MV, v.vertex);
float zOff = vPos.z/_Dist;
vPos += _QOffset*zOff*zOff;
o.pos = mul (UNITY_MATRIX_P, vPos);
o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
return o;
}
half4 frag (v2f i) : COLOR
{
return tex2D(_MainTex, i.uv);
}
ENDCG
}
}
FallBack "Mobil/Unlit"
}
Shader "Platogo/CurvedAlpha" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
_QOffset ("Offset", Vector) = (0,0,0,0)
_Dist ("Distance", Float) = 100.0
_Alpha ("Alpha", Range(0.0,1.0)) = 1.0
}
SubShader {
Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
LOD 100
ZWrite On
Blend SrcAlpha OneMinusSrcAlpha
Pass
{
Lighting Off
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
sampler2D _MainTex;
float4 _QOffset;
float _Dist;
float _Alpha;
uniform float4 _MainTex_ST;
struct v2f {
float4 pos : SV_POSITION;
float2 uv : TEXCOORD0;
};
v2f vert (appdata_base v)
{
v2f o;
float4 vPos = mul (UNITY_MATRIX_MV, v.vertex);
float zOff = vPos.z/_Dist;
vPos += _QOffset*zOff*zOff;
o.pos = mul (UNITY_MATRIX_P, vPos);
o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
return o;
}
half4 frag (v2f i) : COLOR
{
return tex2D(_MainTex, i.uv) * float4(1,1,1,_Alpha);
}
ENDCG
}
}
FallBack "Platogo/Unlit Texture Alpha"
}
Shader "Platogo/Curved 2 Texture Blend" {
Properties {
_Blend ("Blend", Range (0, 1)) = 0.5
_MainTex ("Base (RGB)", 2D) = "white"
_BlendTex ("Blend (RGB)", 2D) = "black"
_QOffset ("Offset", Vector) = (0,0,0,0)
_Dist ("Distance", Float) = 100.0
}
SubShader {
Tags { "RenderType"="Opaque" }
Pass
{
Lighting Off
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
sampler2D _MainTex;
sampler2D _BlendTex;
float4 _QOffset;
float _Dist;
float _Blend;
uniform float4 _MainTex_ST;
struct v2f {
float4 pos : SV_POSITION;
float2 uv : TEXCOORD0;
};
v2f vert (appdata_base v)
{
v2f o;
float4 vPos = mul (UNITY_MATRIX_MV, v.vertex);
float zOff = vPos.z/_Dist;
vPos += _QOffset*zOff*zOff;
o.pos = mul (UNITY_MATRIX_P, vPos);
o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
return o;
}
half4 frag (v2f i) : COLOR
{
return lerp( tex2D(_MainTex, i.uv), tex2D(_BlendTex, i.uv), _Blend);
}
ENDCG
}
}
FallBack "Mobil/Unlit"
}
Copy link

ghost commented Jan 29, 2021

Do you have a preview of what it looks like? 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment