Damian Martyniuk
Damian Martyniuk

Reputation: 388

Converting shadertoy to Metal (cube mapping ?)

I'am trying to rewrite this shader and i'am stuck with line:

float backColor = dot (texture (iChannel0, direction).rgb, channel);

how would i do it ? Following this tutorial i should be able to pass my cubetexture here, but i cant wrap my head around this task. Right now without this line i get some random colors over time so i assume thats part i'am missing. I'am using SceneKit with SCNProgram.

Upvotes: 0

Views: 463

Answers (1)

warrenm
warrenm

Reputation: 31782

Assuming you've ported the relevant parts of the shader, loaded a cube map, and bound it as a shader argument, the equivalent line of Metal Shading Language code is simply:

float backColor = dot(texCube.sample(cubeSampler, direction).rgb, channel);

where texCube is of type texturecube<float, access::sample> and cubeSampler is something like

constexpr sampler cubeSampler(coord::normalized, filter::linear, mip_filter::linear)

Upvotes: 1

Related Questions