Skip to content

Instantly share code, notes, and snippets.

@julhe
Last active December 28, 2018 18:57
Show Gist options
  • Save julhe/8c43597b2995c4b0fcbc63aa39882cac to your computer and use it in GitHub Desktop.
Save julhe/8c43597b2995c4b0fcbc63aa39882cac to your computer and use it in GitHub Desktop.
dot vs. add
Shader "Unlit/MadVsDot"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_TestVector("_TestVector", Vector) = (0,1,2,3)
[Toggle(DOT_VARIANT)] _DOT_VARIANT("DOT_VARIANT", Int) = 0
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 100
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
// make fog work
#pragma multi_compile_fog
#pragma enable_d3d11_debug_symbols
#pragma multi_compile _ DOT_VARIANT
#include "UnityCG.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;
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
UNITY_TRANSFER_FOG(o,o.vertex);
return o;
}
half4 _TestVector;
fixed4 frag (v2f i) : SV_Target
{
half val = 0;
half4 smp = tex2D(_MainTex, i.uv);
for(int i = 0; i < 1000; i++){
smp += i;
#ifdef DOT_VARIANT
val += dot(smp, 0.33);
#else
val += (smp.x + smp.y + smp.z) * 0.33;
#endif
}
return val;
}
ENDCG
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment