• February 25, 2021, 05:00:37 PM

Login with username, password and session length

Author Topic:  Add texture to any 3D fractal  (Read 152 times)

0 Members and 1 Guest are viewing this topic.

Offline kosalos

  • Fractal Friar
  • *
  • Posts: 131
Add texture to any 3D fractal
« on: June 30, 2020, 08:34:33 PM »
I'm sure there are better mapping algorithms, but this works well

1. supply an image to the compute shader
(Apple Metal shader, but you get the idea)

bool   c.txtOnOff                       // use texture?
float2 c.txtSize                        // size of texture image in pixels
float   c.tCenterX,c.tCenterY     // scroll amount    0.01 ... 1
float   c.tScale                        // texture scaling   0.01 ... 1

in your ray marching shader, after the DE() call,  where you have the DE() distance for the current pixel:

kernel void rayMarchShader
(
 texture2d<float, access::write> outTexture     [[texture(0)]],
 texture2d<float, access::read> coloringTexture [[texture(1)]],
 device Control &c      [[ buffer(0) ]],
 uint2 p [[thread_position_in_grid]]   )
{
...    float distance = DE() for current pixel


        float3 position = camera + distance * direction;
        float3 normal = calcNormal(position,0.057,c);

        // use texture
        if(c.txtOnOff) {
            float scale = c.tScale;
            float len = length(position) / distance;
            float x = normal.x / len;
            float y = normal.z / len;
            float w = c.txtSize.x;
            float h = c.txtSize.y;
            float xx = w + (c.tCenterX * 4 + x * scale) * (w + len);
            float yy = h + (c.tCenterY * 4 + y * scale) * (h + len);
           
            uint2 pt;
            pt.x = uint(fmod(xx,w));
            pt.y = uint(c.txtSize.y - fmod(yy,h));    // flip Y coord
            color = coloringTexture.read(pt).xyz;    //  extract pixel color from texture
        }


Linkback: https://fractalforums.org/programming/11/add-texture-to-any-3d-fractal/3634/


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

xx
Apophysis for color texture

Started by mclarekin on Fractal Image Gallery

0 Replies
196 Views
Last post October 26, 2018, 08:38:15 AM
by mclarekin
clip
fractal in nature (fractal stone and fractal concrete)

Started by hgjf2 on Chemistry

3 Replies
999 Views
Last post January 13, 2019, 08:07:15 AM
by hgjf2
xx
Cool 3D Fractal channel on YT: Cineastic Fractal Videos - CFV

Started by aliential on Fractal movie gallery

0 Replies
250 Views
Last post November 29, 2019, 08:09:46 AM
by aliential
xx
How to create a 3D fractal in real time. Fractal Alchemist.

Started by sanbase on Fractal Programs Discussion, Help, & Support

4 Replies
362 Views
Last post April 30, 2020, 09:27:59 AM
by mclarekin
smiley
Fractal Matrix V2 360° stereoscopic - Mandelbulb 3D fractal VR 4K

Started by schizo on Fractal movie gallery

2 Replies
441 Views
Last post September 27, 2020, 09:39:03 PM
by schizo