Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save yumayanagisawa/ef068ed3f4ad33e76f4ad1ab74a2a1b9 to your computer and use it in GitHub Desktop.
Save yumayanagisawa/ef068ed3f4ad33e76f4ad1ab74a2a1b9 to your computer and use it in GitHub Desktop.
Experiment with "_WorldSpaceCameraPos"
// Upgrade NOTE: replaced '_Object2World' with 'unity_ObjectToWorld'
Shader "Unlit/Architecture_Base_Unlit"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_Color("Color", Color) = (1,1,1,1)
_Luminosity("Luminosity", Float) = 10
_ArchitectureScale("Arch Scale", Float) = 30
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 200
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
// make fog work
#pragma multi_compile_fog
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float3 worldPos : TEXCOORD1;
UNITY_FOG_COORDS(1)
float4 vertex : SV_POSITION;
};
sampler2D _MainTex;
float4 _MainTex_ST;
fixed4 _Color;
// luminous power
float _Luminosity;
float _ArchitectureScale;
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.worldPos = mul(unity_ObjectToWorld, v.vertex).xyz;
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
UNITY_TRANSFER_FOG(o,o.vertex);
return o;
}
fixed4 frag (v2f i) : SV_Target
{
// sample the texture
fixed4 col = tex2D(_MainTex, i.uv) * _Color;
// apply fog
//UNITY_APPLY_FOG(i.fogCoord, col);
float distance = length(i.worldPos.xyz - _WorldSpaceCameraPos.xyz) / _ArchitectureScale;
col.rgb = (_ArchitectureScale - distance) * col.rgb * _Luminosity;
return col;
}
ENDCG
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment