• April 20, 2021, 09:31:05 AM

0 Members and 1 Guest are viewing this topic.

kosalos

• Fractal Friar
• Posts: 142
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:

(
texture2d<float, access::write> outTexture     [[texture(0)]],
device Control &c      [[ buffer(0) ]],
{
...    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
}

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

Similar Topics

Apophysis for color texture

Started by mclarekin on Fractal Image Gallery

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

Started by hgjf2 on Chemistry

3 Replies
1273 Views
January 13, 2019, 08:07:15 AM
by hgjf2
How to create a 3D fractal in real time. Fractal Alchemist.
4 Replies
430 Views
April 30, 2020, 09:27:59 AM
by mclarekin
Cool 3D Fractal channel on YT: Cineastic Fractal Videos - CFV

Started by aliential on Fractal movie gallery

0 Replies
287 Views
November 29, 2019, 08:09:46 AM
by aliential
360° Fractal Canyon - Mandelbulb 3D fractal VR animation in 4K

Started by schizo on Fractal movie gallery

0 Replies
345 Views
May 18, 2019, 06:36:52 PM
by schizo