think maybe I should try asking something more pointed.
I'm really struggling with glsl and I know I'm making a huge problem for myself since I'm also using metal in runtime for rendering but it doesn't matter if I set the renderer to opengl either I get the same result.
So to simplify life I found a shader on a site called "shadertoy" It creates a cartoony water effect and I'd like to use it. But I get errors when I do. This is the shader:
#define TAU 6.28318530718
#define MAX_ITER 5
void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
float time = iGlobalTime * .5+23.0;
// uv should be the 0-1 uv of texture...
vec2 uv = fragCoord.xy / iResolution.xy;
#ifdef SHOW_TILING
vec2 p = mod(uv*TAU*2.0, TAU)-250.0;
#else
vec2 p = mod(uv*TAU, TAU)-250.0;
#endif
vec2 i = vec2(p);
float c = 1.0;
float inten = .005;
for (int n = 0; n < MAX_ITER; n++)
{
float t = time * (1.0 - (3.5 / float(n+1)));
i = p + vec2(cos(t - i.x) + sin(t + i.y), sin(t - i.y) + cos(t + i.x));
c += 1.0/length(vec2(p.x / (sin(i.x+t)/inten),p.y / (cos(i.y+t)/inten)));
}
c /= float(MAX_ITER);
c = 1.17-pow(c, 1.4);
vec3 colour = vec3(pow(abs(c), 8.0));
colour = clamp(colour + vec3(0.0, 0.35, 0.5), 0.0, 1.0);
#ifdef SHOW_TILING
// Flash tile borders...
vec2 pixel = 2.0 / iResolution.xy;
uv *= 2.0;
float f = floor(mod(iGlobalTime*.5, 2.0)); // Flash value.
vec2 first = step(pixel, uv) * f; // Rule out first screen pixels and flash.
uv = step(fract(uv), pixel); // Add one line of pixels per tile.
colour = mix(colour, vec3(1.0, 1.0, 0.0), (uv.x + uv.y) * first.x * first.y); // Yellow line
#endif
fragColor = vec4(colour, 1.0);
}I save it in a file called water.shader (but I have tried water.glsl too.)
In my container object for scnnodes I have a method I call :
-(void)initModifiers
{
SCNNode * node = self.nodeObject;
_surfModifier = [NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"sm_surf" ofType:@"shader"] encoding:NSUTF8StringEncoding error:nil];
_lightModifier= [NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"sm_light" ofType:@"shader"] encoding:NSUTF8StringEncoding error:nil];
_geomModifier = [NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"sm_geom" ofType:@"shader"] encoding:NSUTF8StringEncoding error:nil];
_fragModifier = [NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"sm_frag" ofType:@"shader"] encoding:NSUTF8StringEncoding error:nil];
_waterModifier = [NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"water" ofType:@"shader"] encoding:NSUTF8StringEncoding error:nil];
[node.geometry setValue:@0.0 forKey:@"Amplitude"];
[node.geometry setValue:@0.0 forKey:@"lightIntensity"];
[node.geometry setValue:@0.0 forKey:@"surfIntensity"];
[node.geometry setValue:@0.0 forKey:@"fragIntensity"];
}This is nearly a direct c&p from an apple example
Then for other modifiers, specifically one that uses surfmodifier and lightmodifier I can call it with:
-(void)addWaterToNode:(SCNNode*)node
{
[SCNTransaction begin];
[SCNTransaction setAnimationDuration:3];
[node.geometry setValue:@0.25 forKey:@"Amplitude"];
[SCNTransaction setCompletionBlock:^{
[SCNTransaction begin];
[SCNTransaction setAnimationDuration:3];
node.geometry.shaderModifiers = @{SCNShaderModifierEntryPointSurface : _surfModifier,
SCNShaderModifierEntryPointLightingModel : _lightModifier};
[node.geometry setValue:@0.25 forKey:@"surfIntensity"];
[SCNTransaction commit];
}];
[SCNTransaction commit];
}The combination _surfModifier and _lightModifier has a water-ish look but it's not very good.
But the problem is the water modifier that I listed above, I don't know how to call it or add it to the geometry so that I can use it instead. Or honestly any shader at all even if I write it myself I guess I don't understand how to use them.