Skip to content

Latest commit

 

History

History
24 lines (18 loc) · 489 Bytes

File metadata and controls

24 lines (18 loc) · 489 Bytes

UnityReadbackFromShader

Basic way to read single integer -for now- from CG shaders.

Works by computing in fragment shader and applying that value to framebuffer, then unity can readback from this buffer

Shader

fixed4 frag (v2f i) : SV_Target
{
  return int2Fixed4( Fibonacci(30) );
}

C#

// get result texture see:FramebufferReadback.cs
var tex = GetResultTexture();

// get single pixel
Color c = tex.GetPixel(0, 0);

int fib30 = ReadbackValue(c);