• April 19, 2021, 02:52:46 AM

Login with username, password and session length

Author Topic:  Shadow Lines  (Read 154 times)

0 Members and 1 Guest are viewing this topic.

Offline kosalos

  • Fractal Friar
  • *
  • Posts: 142
Shadow Lines
« on: June 27, 2020, 06:42:31 AM »
Add shadow lines to your 2D fractals.
1. calculate your fractal as usual, storing to a texture.
2. call a second compute shader that creates an altered copy with shadow lines added.

Here's an Apple Metal shader, but you get the idea...
--------------------------------------------------------------

kernel void shadowShader
(
 texture2d<float, access::read> src [[texture(0)]],        // your 2D fractal
 texture2d<float, access::write> dst [[texture(1)]],       // copy with shadow lines added
 constant Control &control [[buffer(0)]],                       // merely holds the size of the texture
 uint2 p [[thread_position_in_grid]])
{
    if(p.x > uint(control.xSize)) return; // screen size not evenly divisible by threadGroups
    if(p.y > uint(control.ySize)) return;
   
    float4 v = src.read(p);
   
    if(p.x > 1 && p.y > 1) {
        bool shadow = false;
       
        {
            uint2 p2 = p;
            p2.x -= 1;
            float4 vx = src.read(p2);
            if(v.x < vx.x || v.y < vx.y) shadow = true;
        }
       
        if(!shadow)
        {
            uint2 p2 = p;
            p2.y -= 1;
            float4 vx = src.read(p2);
            if(v.x < vx.x || v.y < vx.y) shadow = true;
        }
       
        if(!shadow)
        {
            uint2 p2 = p;
            p2.x -= 1;
            p2.y -= 1;
            float4 vx = src.read(p2);
            if(v.x < vx.x || v.y < vx.y) shadow = true;
        }
       
        if(shadow) {
            v.x /= 4;
            v.y /= 4;
            v.z /= 4;
        }
    }
   
    dst.write(v,p);
}


Linkback: https://fractalforums.org/index.php?topic=3618.0


There are no comments for this topic. Do you want to be the first?

xx
Menger sponge with raytraced shadow

Started by Nintendokater on Fractal Image Gallery

2 Replies
406 Views
Last post August 18, 2019, 10:56:42 PM
by ThunderboltPagoda
xx
Silver lines

Started by Etymos on Fractal Image Gallery

0 Replies
132 Views
Last post August 31, 2018, 09:38:59 PM
by Etymos
smiley
Menger sponge out of frames in less than 20 lines + renders

Started by kronpano on StructureSynth & BrowserSynth

0 Replies
100 Views
Last post September 25, 2020, 11:36:41 AM
by kronpano
xx
Nazca lines - A Mandelbrot zoom to 2.7E359

Started by Fluoroantimonic_Acid on Fractal movie gallery

3 Replies
539 Views
Last post October 28, 2020, 05:27:10 AM
by 3DickUlus