Shadertoy Porting Texture problem

Hello,
It’s my first attempt trying to port a shadertoy shader into vvvv and I found an error that no search through google or forums seems to help me resolving it. The error is:

Offset texture instructions must take an offset, which can resolve to integer literal in the range -8 to 7.

This is the original script:

> void mainImage( out float4 fragColor, in float2 fragCoord )
> {
> float2 uv = (fragCoord.xy-.5*iResolution.xy) / iResolution.y;
>     float2 UV = fragCoord.xy/iResolution.xy;
>     float3 M = iMouse.xyz/iResolution.xyz;
>     float T = iTime+M.x*2.;
>     float t = T*.2;
>     float rainAmount = iMouse.z>0. ? M.y : sin(T*.05)*.3+.7;
>     float maxBlur = lerp(3., 6., rainAmount);
>     float minBlur = 2.;
>     float story = 0.;
>     float heart = 0.;
>     //float zoom = -cos(T*.2);
>     //uv *= .7+zoom*.3;
>     //UV = (UV-.5)*(.9+zoom*.1)+.5;   
>     float staticDrops = S(-.5, 1., rainAmount)*2.;
>     float layer1 = S(.25, .75, rainAmount);
>     float layer2 = S(.0, .5, rainAmount);
>     float2 c = Drops(uv, t, staticDrops, layer1, layer2);
>     #ifdef CHEAP_NORMALS
>     	float2 n = float2(dFdx(c.x), dFdy(c.x));// cheap normals 
>     #else
>     	float2 e = float2(.001, 0.);
>     	float cx = Drops(uv+e, t, staticDrops, layer1, layer2).x;
>     	float cy = Drops(uv+e.yx, t, staticDrops, layer1, layer2).x;
>     	float2 n = float2(cx-c.x, cy-c.x);		// expensive normals
>     #endif
>     float focus = lerp(maxBlur-c.y, minBlur, S(.1, .2, c.x));
>     float3 col = textureLod(iChannel0, UV+n, focus).rgb;
>     fragColor = float4(col, 1.);
> }

This is what I came up with with the converting tool and looking at other similar porting examples:

float4 PS(float4 fragCoord : SV_POSITION): SV_Target
{

float2 uv = (fragCoord.xy-.5R.xy) / R.y;
float2 UV = fragCoord.xy/R.xy;
//float3 M = iMouse.xyz/R.xyz;
float T = Time;//+M.x
2.;
float t = T*.2;
float rainAmount = Size>0. ? Size : sin(T*.05).3+.7;
float maxBlur = lerp(3., 6., rainAmount);
float minBlur = 2.;
float story = 0.;
float heart = 0.;
//float zoom = -cos(T
.2);
//uv = .7+zoom.3;
//UV = (UV-.5)(.9+zoom.1)+.5;
float staticDrops = S(-.5, 1., rainAmount)*2.;
float layer1 = S(.25, .75, rainAmount);
float layer2 = S(.0, .5, rainAmount);
float2 c = Drops(uv, t, staticDrops, layer1, layer2);
#ifdef CHEAP_NORMALS
float2 n = float2(dFdx(c.x), dFdy(c.x));// cheap normals
#else
float2 e = float2(.001, 0.);
float cx = Drops(uv+e, t, staticDrops, layer1, layer2).x;
float cy = Drops(uv+e.yx, t, staticDrops, layer1, layer2).x;
float2 n = float2(cx-c.x, cy-c.x); // expensive normals
#endif
float focus = lerp(maxBlur-c.y, minBlur, S(.1, .2, c.x));
float3 col = tex0.Sample(s0, UV+n, focus).rgb;
return float4(col, 1.);

The error itself is on this line

float3 col = tex0.Sample(s0, UV+n, focus).rgb;

What does it mean and how should I resolve this?

Maybe try to cahnge dFdx to ddx and dFdy to ddy?

I think in hlsl it is called that way.

You can also debug by asigning the normals to the output color, so you see if they are correctly calculated

Also make sure to make the mipmap level (focus) an integer value, by for example useing floor() or round() and initialize with int instead of float

By using just Sample() you don’t address the mipmap level, so simply use SampleLevel().
@tekcor: it can of course be a floating point value to interpolate between two mipmap levels.

Thank you @tekcor and @flux,
SamplerLevel() works! Shader successfully ported.

Now I need some help to further modify this shader, better to start another thread or we can continue in this one?

Hi, @flux you are right, i was looking at Sample() reference quickly and there was written use only integer for the third paramter. Intuitively I was thinkings they mean MIP Level, but in fact the third parameter in Sample() is texture coordinate offset.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.