User Tools

Site Tools


guides:gpu

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
guides:gpu [2024/05/31 22:38] osnrguides:gpu [2025/12/26 14:18] (current) osnr
Line 1: Line 1:
 +====== GPU FFI ======
 +
 The new 'GPU FFI' lets you write vertex and fragment shaders to draw things. The new 'GPU FFI' lets you write vertex and fragment shaders to draw things.
  
Line 32: Line 34:
 You can make ''%%sampler2D%%''-type arguments if you want to pass an image in; you can make ''%%fn%%'' arguments to a fragment shader as third argument. See the implementations of drawing primitives in virtual-programs/display/*.folk for more examples.  You can make ''%%sampler2D%%''-type arguments if you want to pass an image in; you can make ''%%fn%%'' arguments to a fragment shader as third argument. See the implementations of drawing primitives in virtual-programs/display/*.folk for more examples. 
  
-==== TODO: Document internal Gpu:: API ====+====== Adding functions ======
  
-These must be called on the display thread''Gpu::pipeline''''Gpu::draw''''Gpu::fn''+When you want to use functions, maybe to [[https://iquilezles.org/articles/palettes/|start using fun new color palettes in your shaders]], you can add them like this: 
 + 
 +<code> 
 +# sourcehttps://iquilezles.org/articles/palettes/ 
 +# cosine based palette, 4 vec3 params 
 +Wish the GPU compiles function "palette" {{float t vec3 a vec3 b vec3 c vec3 d} vec3 { 
 +    return a + b*cos( 6.28318*(c*t+d) ); 
 +}} 
 + 
 +Wish the GPU compiles pipeline "$this's triangle"
 +    {vec2 p0 vec2 p1 vec2 p2 float u_time} { 
 +        vec2 vertices[4] = vec2[4](p0p1p2, p0); 
 +        return vertices[gl_VertexIndex]; 
 +    } {fn palette} { 
 +        vec3 gradientColor = palette(gl_FragCoord.x, vec3(0.5,0.5,0.5),vec3(sin(u_time),0.5,0.5),vec3(1.0,1.0,1.0),vec3(0.0,sin(u_time),0.20)); 
 +        return vec4(gradientColor, 1.0); 
 +    } 
 +
 + 
 +Wish $this is outlined blue 
 +When $this has region /r/ & the clock time is /t/ { 
 +    set r' [region move $r down 100%] 
 +    Wish the GPU draws pipeline "$this's triangle" with arguments [list {*}[lrange [region vertices ${r'}] 0 2] [fmod $t 16384]] 
 +}</code>
  
 ---- ----
guides/gpu.1717195091.txt.gz · Last modified: by osnr

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki