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wki8olPqKkph1ITdq9G.kE3xXX9f96AXOvwpGELi6Em+OozTOudWjIbcT3wb9mbtcg.t3BA+970B+9Ed7N6X4u3wksjIVdMnRGdWrNJtj42Uq00jTG86QFVBl661eBiCp7rPnXdGXrs56cURi923F+x8xoWVAMC3w2C.GpPZOwN+3uz+AzWgp0V82mV5yN7q26PxnHA7vDuJUdWX.HMeLvf8wPus56qnPmAu.APUXt+LI+12r0cyAH3R39cymHkwrW988Jl8xY9+FeLB6EK9VOyHDU81kzTf8Vt9iz2.suZsSuICcPc6z0ZD77ju0yS0E7wPY6z0Y0YPmaLC5byYPmaMC5b6YPm0lActyYpi5kgqmJEiL2PBDFrs9aoYaavdpuBv5OAXuOS7.
you need to paste this into the
bunny.glsl
shader file:// Variation of https://www.shadertoy.com/view/wtVyWK uniform float amp; vec3 erot(vec3 p, vec3 ax, float ro) { return mix(dot(p,ax)*ax,p,cos(ro))+sin(ro)*cross(ax,p); } float sdSphere( vec3 p, float s ) { return length(p)-s; } float wobble(vec3 p, float scale) { float x = (sin(scale*p.x)*sin(scale*p.y)*sin(scale*p.z)); return -1.0 * x * x; } float scene(vec3 p) { float x = sin(4.0 * 2.0 * 3.14159 * fract(iTime));; p *= vec3(sin(3.14159 * fract(iTime)) * 0.1 + 1.0); float d1 = sdSphere(p, 0.5); float gain = min(0.12, 0.12 * amp); p *= vec3(sin(5.0 * 3.14159 * fract(iTime)) * 0.1 + 1.0); float d2 = 1.5 * gain * wobble(p, 5.0); p *= vec3(sin(3.14159 * fract(iTime)) * 0.0 + 1.0); d2 += gain * 0.5 * wobble(p, 10.0); return d1 + d2; } vec3 norm(vec3 p) { mat3 k = mat3(p,p,p)-mat3(0.001); return normalize(scene(p) - vec3(scene(k[0]),scene(k[1]),scene(k[2]))); } void main() { vec2 uv = (fragCoord-0.5*iResolution.xy)/iResolution.y; vec2 mouse = (iMouse.xy-0.5*iResolution.xy)/iResolution.y; vec3 cam = normalize(vec3(1.5,uv)); vec3 init = vec3(-3.,0,0); float yrot = 0.5; float zrot = iTime*.2; cam = erot(cam, vec3(0,1,0), yrot); init = erot(init, vec3(0,1,0), yrot); cam = erot(cam, vec3(0,0,1), zrot); init = erot(init, vec3(0,0,1), zrot); vec3 p = init; bool hit = false; for (int i = 0; i < 150 && !hit; i++) { float dist = scene(p); hit = dist*dist < 1e-6; p+=dist*cam; if (distance(p,init)>5.) break; } vec3 n = norm(p); vec3 r = reflect(cam,n); //don't ask how I stumbled on this texture vec3 nz = p - erot(p, vec3(1), 2.) + erot(p, vec3(1), 4.); float spec = length(sin(r*3.5+sin(nz*120.)*.15)*.4+.6)/sqrt(3.); spec *= smoothstep(-.3,.2,scene(p+r*.2)); vec3 col = vec3(.1,.1,.12)*spec + pow(spec,8.); float bgdot = length(sin(cam*8.)*.4+.6)/2.; vec3 bg = vec3(.1,.1,.11); fragColor.xyz = hit ? col : bg; fragColor = smoothstep(-.02,1.05,sqrt(fragColor)) * (1.- dot(uv,uv)*.5); }
-
@Christoph-Hart Nice one!
-
@Christoph-Hart Why this means?
Interface:! WARNING: 0:86: Unary operation folding into constant is supported in newer GLSL versions{GLSL::Interface::bunny.glsl} Interface:! ERROR: 0:94: '' : illegal character (`) (0x60){GLSL::Interface::bunny.glsl} Interface:! ERROR: 0:94: '' : illegal character (`) (0x60){GLSL::Interface::bunny.glsl}
-
@Natan Ah, it was just an error in how I pasted the code, try again now (or remove the backticks on the last line yourself).
-
@Christoph-Hart :exploding_head:
Thank you so much.
This opens up so many possibilities.
It flys way above my coding skills. What parts of the script should I focus on In order to customize it?
-
@RastaChess just start by changing random numbers in the GLSL script and recompile. If you want to dive into that subject, you might want to read up on the entire distance function theory here:
Inigo Quilez
Tutorials and articles of Inigo Quilez on computer graphics, fractals, demoscene, shaders and more.
(iquilezles.org)
That's maybe the most valuable resource when it comes to Shader development.
-
@Christoph-Hart Thank You
-
@Christoph-Hart I have not been able to compile my shaders for ages until I got to the point where decided not to use them anymore...
...until I read that warning in the doc today:
// Enable Shader Line Numbers Old graphic cards (eg. the integrated Intel HD ones) do not support this, so if you get a weird GLSL compile error, untick this line.
:zany_face: :zany_face: :zany_face: :zany_face:
Complicated things are sometimes so simple...
-
@ustk yes the entire GLSL thing is a bit finicky (Also for production code you might want to add a minimal GLSL version requirement).
-
@ustk I was able to run @Christoph-Hart's exercise. But I have to say it's hard to wrap my head around how it works. It's appears so complicated. I tried with other shapes and things just disappear from the UI.
Can someone share a simple of example of how to have a primitive shape like a sphere show up on the UI?
thanks.
-
@Christoph-Hart Trying to test the GLSL version to decide to use it or not in production,
but theopenGLStats
isn't populated before trying to apply the shader at least once:void paint(Graphics& g) override { //... if (obj->dirty) { auto r = obj->shader->checkCompilation(g.getInternalContext()); obj->setCompileResult(r); obj->makeStatistics(); // So it's not called before the first painting attempt obj->dirty = false; }
Unless this is not a problem in a scenario where the version isn't compatible, and I can just hide the panel,
not worrying if the paint routine has been called but didn't succeeded... -
It's appears so complicated. I tried with other shapes and things just disappear from the UI.
Can someone share a simple of example of how to have a primitive shape like a sphere show up on the UI?
So if you really want to learn this, you need to learn shader programming. There's plenty of resources online for that, just remember that in HISE you only work with FRAGMENT SHADERS, so whenever they start talking about vertex shaders or textures, you need to skip these parts.
The most complicated thing to wrap your head around at the beginning is that you need to forget how usual 2D graphics programming work. Stuff like
drawCircle()
orfillRect()
will not be available, because the GPU is highly parallelized and needs to be able to calculate every single pixel independently. So in order to draw a circle, you need to check whether the given coordinate (that pixel you're about to render) has a smaller distance to the circle center than the radius, and in that case, you can assume it's inside the circle and draw it with the circle colour.I suggest you head over to shadertoy.com, search for simple examples and start modifying the code to get a feeling for how it works.