Skip to content

Instantly share code, notes, and snippets.

@leegoonz
Created January 8, 2020 19:47
Show Gist options
  • Save leegoonz/8366ef8768f30eacf6c4dda13eec0857 to your computer and use it in GitHub Desktop.
Save leegoonz/8366ef8768f30eacf6c4dda13eec0857 to your computer and use it in GitHub Desktop.
Shader /*ase_name*/ "Leegoonz/ASETemplateShaders/ParabolicMatcap" /*end*/
{
Properties
{
_FrontParaboloid ("_FrontParaboloid", 2D) = "white" { }
_RearParaboloid ("_RearParaboloid", 2D) = "white" { }
/*ase_props*/
}
SubShader
{
Tags { "RenderType"="Opaque" "LightMode" = "ForwardBase" /*ase_tags*/}
LOD 100
Cull Off
/*ase_pass*/
Pass
{
CGPROGRAM
#pragma target 3.0
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
/*ase_pragma*/
struct appdata
{
float4 vertex : POSITION;
float3 normal : NORMAL;
float4 texcoord : TEXCOORD0;
float4 texcoord1 : TEXCOORD1;
UNITY_VERTEX_INPUT_INSTANCE_ID
/*ase_vdata:p=p;uv0=tc0.xy;uv1=tc1.xy*/
};
struct v2f
{
float4 vertex : SV_POSITION;
float4 texcoord : TEXCOORD0;
float3 worldNormal : TEXCOORD1;
UNITY_VERTEX_OUTPUT_STEREO
/*ase_interp(1,7):sp=sp.xyzw;uv0=tc0.xy;uv1=tc0.zw*/
};
uniform fixed4 _Color;
uniform sampler2D _FrontParaboloid;
uniform sampler2D _RearParaboloid;
/*ase_globals*/
v2f vert ( appdata v /*ase_vert_input*/)
{
v2f o;
UNITY_SETUP_INSTANCE_ID(v);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
o.texcoord.xy = v.texcoord.xy;
o.texcoord.zw = v.texcoord1.xy;
// ase common template code
/*ase_vert_code:v=appdata;o=v2f*/
v.vertex.xyz += /*ase_vert_out:Local Vertex;Float3*/ float3(0,0,0) /*end*/;
o.vertex = UnityObjectToClipPos(v.vertex);
o.worldNormal = normalize(mul((float3x3)unity_ObjectToWorld, v.normal));
return o;
}
inline fixed4 texParaboloidXFliped(sampler2D front, sampler2D back, float3 refl)
{
if (refl.x > 0)
{
float2 frontUv;
frontUv.x = refl.z / (refl.x + 1);
frontUv.y = refl.y / (refl.x + 1);
frontUv = (frontUv * .5f) + 0.5f;
frontUv.x = 1 - frontUv.x;
return tex2D(front, frontUv);
}
else
{
float2 backUv;
backUv.x = refl.z / (1 - refl.x);
backUv.x *= -1;
backUv.y = refl.y / (1 - refl.x);
backUv = (backUv * .5f) + 0.5f;
backUv.x = backUv.x;
return tex2D(back, backUv);
}
}
fixed4 frag (v2f i /*ase_frag_input*/) : SV_Target
{
fixed4 parabolicOut;
// ase common template code
/*ase_frag_code:i=v2f*/
parabolicOut = /*ase_frag_out:Albedo Color;Float4*/float4(1,1,1,1)/*end*/;
//return myColorVar;
return parabolicOut * texParaboloidXFliped(_FrontParaboloid, _RearParaboloid, i.worldNormal);;
}
ENDCG
}
}
CustomEditor "ASEMaterialInspector"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment