Converting shadertoy shader with texture to jxs
Hello,
I always have problems when I try to convert shaders from shadertoy that use textures into a jxs file for max to use.
Here is the original shader: https://www.shadertoy.com/view/Ms2SWW
// Created by inigo quilez - iq/2013
// License Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
// normalized coordinates (-1 to 1 vertically)
vec2 p = (-iResolution.xy + 2.0*fragCoord.xy)/iResolution.y;
// angle of each pixel to the center of the screen
float a = atan(p.y,p.x);
// modified distance metric. Usually distance = (x² + y²)^(1/2). By replacing all the "2" numbers
// by 32 in that formula we can create distance metrics other than the euclidean. The higher the
// exponent, then more square the metric becomes. More information here:
float r = pow( pow(p.x*p.x,16.0) + pow(p.y*p.y,16.0), 1.0/32.0 );
// index texture by angle and radious, and animate along radius
vec2 uv = vec2( 0.5/r + 0.5*iGlobalTime,
a/3.1416 );
// fecth color and darken in the center
vec3 col = texture2D( iChannel0, uv ).xyz * r;
fragColor = vec4( col, 1.0 );
}
Here is my converted code:
I'm supplying the texture as a 512 x 512 jpeg. The shader definitely sees the texture because it turns brown but it doesn't map it correctly. There's something going on behind the scenes at shadertoy that I don't understand. Why don't they have to use the texcoords?
Attached is what the shader looks like on my end. Thank you!
Okay I figured it out. If I load in the texture like this in the jxs:
The wrap mode fixes it.
Hi Luke,
I have done a fair bit of work using shadertoy shaders in jitter, mainly through using Fabrizio Poce's v-module suite in max4live.
I am interested that you seem to be loading your texture files directly into the .jxs.
Can you provide more information on this?
Do the texture images need to be in a certain location, or will they get recognised from anywhere in the max path?
Once the have referenced them as above, how do you then bind them to your texture samplers (i.e uniform sampler2D tex0)
hi artoo.
the same basic rules apply to the texture tag as to texture objects in the patch. either provide the full path to the file, or include it in the search path.
i think by default, textures are referenced in the order they're declared, and referenced after textures bound to the object. but you can also specify which unit they are bound to like so (taken from the mrt.ssao.render.jxs file)
in this case the texture bound to the gl object (tex_normals) is bound to unit 0, and the random texture loaded in the shader file is bound to unit 1.