Let's say that I have a cube that has an unlit shader applied to it. The shader does basic ray-marching.
Shader "sdf shader"{
Properties{
}
SubShader{
Pass{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
float sphere(float3 posi, float r){
return distance(posi, unity_ObjectToWorld._m03_m13_m23) - r;
}
float4 raymarch(float3 ori, float3 dire, float4 uv, float r){
float d;
for(int i; i < 64; i++){
if (d > 40){
break;
}
float3 post = ori + (dire * d);
if (sphere(post, r) < 0.001){
return float4(0,0,0,0);
}
d += sphere(post, r);
}
return uv;
}
struct appdata{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f{
float4 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
v2f vert (appdata v){
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.vertex;
return o;
}
fixed4 frag (v2f i) : SV_Target{
float3 pos = mul(unity_ObjectToWorld, i.uv);
float3 dir = normalize(pos - _WorldSpaceCameraPos);
float4 output = (1,1,1,1);
float4 col = raymarch(pos, dir, output, 1);
return col;
}
ENDCG
}
}
}
Does the shader do calculations for every pixel in the viewport or only the ones covered by the cube? By "covered by the cube", I mean the pixels that are currently displaying the cube and not the area around it.