Help converting shader

Hi - I’m trying to convert this lovely shader → Shader - Shadertoy BETA
for use in Playcanvas - and I’m following Leonidas’s guide here - Shadertoy to PlayCanvas: Sirenian Dawn | Playing in Canvas

But I’m stuck - mainly because I’m new to non-unity shader stuff. The important stuff is in the diamond shader file - at the getAlbedo() function. The rest copies across with no errors.
https://playcanvas.com/editor/scene/1644525

the original shader, frag is this…
//vec2 frag = (2.0 * fragCoord.xy - iResolution.xy) / iResolution.y;

and in the tutorial example It’s changed to this. So I’ve stuck with that.
vec2 frag = (2.0 * $UV.x - iResolution.xy) / iResolution.y;

my problem is the dist calculation further down. It’s always >= 0.0 which makes me think the calculations are probably wrong.

also I’m having to change

texture (iChannel0, direction).rgb;
to
texture(iChannel0, vec2(direction.x,direction.y)).rgb;

which feels wrong. but It won’t let me use direction on it’s own it only accepts a vec2 into the texture function.

Can anyone point me in the right direction ? thanks :slight_smile:

Hi @jerryComo,

Yes it can be tricky in some cases to transfer a shadertoy shader, sometimes the scale of the texels/viewport needs some careful tweaking to get the same visual result.

The Sirenian Dawn tutorial is a bit old so some things may have changed in the PlayCanvas chunks system. About your distance question sorry, I’m not sure about it. Try debugging each line visually if possible, by commenting out the rest.

About your last texture() question, try this:

texture (iChannel0, direction.xy).rgb;
2 Likes