Skip to content

Instantly share code, notes, and snippets.

@cnlohr
Last active May 22, 2021 22:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cnlohr/e78fc4979c0091d54a93aee8e687f0e7 to your computer and use it in GitHub Desktop.
Save cnlohr/e78fc4979c0091d54a93aee8e687f0e7 to your computer and use it in GitHub Desktop.
perfeater - to keep your GPU busy in unity so you can do timing measurements in renderdoc or nsight.
Shader "Unlit/PerfEat"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 100
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;
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;
}
fixed4 frag (v2f i) : SV_Target
{
// sample the texture
fixed4 col = tex2D(_MainTex, i.uv);
// apply fog
float2 c = i.uv*2-1;
float2 z = 0;
int j;
for( j = 0; j < 20000; j++ )
{
z = c + float2( z.x*z.x-z.y*z.y, 2.*z.x*z.y );
}
col = float4( z, 0, 1 );
UNITY_APPLY_FOG(i.fogCoord, col);
return col;
}
ENDCG
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment