Page 1 of 2
Cool demo with ZGE-conversion
Posted: Mon Nov 02, 2009 5:59 pm
by VilleK
I found an article about an impressive 1kb-demo:
http://sizecoding.blogspot.com/2009/11/ ... iboon.html
It features the source code and it's completely implemented as a fragment-shader that draws upon a single quad. This seems to be the trend among the latest 1 and 4kb demos to do everything in shaders.
So it was easy to just draw a RenderSprite and copy-paste the shader into ZGE. It's fun to study the fragment source to learn how to make cool shader tricks. Even if the zge-version becomes 28 times larger than the original

Posted: Mon Nov 02, 2009 6:16 pm
by Kjell
Pretty crazy, it's the old-skool raytracer days all over again
K
Posted: Mon Nov 02, 2009 7:44 pm
by y offs et
I suppose this is another ATI-related error. Log reads -
-Loading etc.
#Fragment Shader compiled OK
+GL ERROR 1282
#Error when linking shader program
#Error when linking shader program
#Shader variable error:Time
and I get a slow, big white square in preview and .exe
This may be another clue : When I re-open with the program pre-loaded, the GL error line doesn't appear but the result is the same. Then I open the program and it does.
Posted: Mon Nov 02, 2009 7:55 pm
by VilleK
It could be because how the time-variable is used in the shader. Try this instead (copy paste into zge project tree):
Code: Select all
ZZDC<?xml version="1.0" encoding="iso-8859-1" ?>
<Shader Name="Shader1">
<FragmentShaderSource>
<![CDATA[//http://sizecoding.blogspot.com/2009/11/frequencies-to-road-of-riboon.html
uniform float w;
float d;
float o(vec3 p){return min(
cos(p.x)+cos(p.y*1.5)+cos(p.z)+cos(p.y*20)*.0256,
length(max(abs(p-vec3(cos(p.z*1.5)*.256,cos(p.z)*.256-.5,0))-vec3(.12,.0256,w+3.),vec3(0)))
);}
vec3 n(vec3 p){vec3 f=vec3(.0256,0,0);return normalize(vec3(o(p+f.xyy),o(p+f.yxy),o(p+f.yyx)));}
void main(){
vec3 s=vec3(cos(w)*.5,-cos(w*.5)*.5+.256,w);
vec3 p=s;
vec3 e=normalize(vec3((gl_FragCoord.xy)*.00256-1.,1.));
for(int i=0;i<64;i++){d=o(p);p+=d*e;}
vec3 pp=p;
p+=e=reflect(e,n(p));
for(int i=0;i<64;i++){d=o(p);p+=d*e;}
gl_FragColor=abs(dot(n(p),vec3(.1)))+vec4(.3,cos(w*.5)*.5+.5,-cos(w*.5)*.5+.5,1)*length(p-s)*.0256
+length(p-s)*.0256+(1-min(pp.y+1.8,1.))*vec4(1,.8,.7,1);
}]]>
</FragmentShaderSource>
<UniformVariables>
<ShaderVariable VariableName="w" ValuePropRef="App Time"/>
</UniformVariables>
</Shader>
Posted: Mon Nov 02, 2009 9:28 pm
by y offs et
Log message changes
#Loading etc.
#Error in Fragment Shader compilation
#Shader variable error:Time
---------------------------------
forget that - I don't copy/paste because my text editor gets upset about some coding.
Anyway, I changed the shader variable to "w" and it compiles OK but I get the linking error message.
Posted: Tue Nov 03, 2009 2:39 pm
by jph_wacheski
Wow I'll say that is cool! Does anyone have any explinations of how this is working,. is it actualy tracing rays for each pixel? Also, I know he was specificly working it to be a fullscreen render,. however how would we modify this to keep it on the sprite at any size on the screen,. currently if you resize the window or sprite the area of vision is limited/moved,. sotra like cutting a hologram eh,. . neet.
Posted: Tue Nov 03, 2009 4:11 pm
by Kjell
Easy,
Just pass the projection data from the vertex shader .. attached is a build that comes pretty close. By the way, I'm sure the creator made every decision purely with filesize in mind, but it's not very convenient to normalize the complete orientation matrix when it is dependent on fragment coordinates ( which means that when you use a different screen ratio then intended the camera actually is oriented differently ).
The way it works at its core is that for each pixel the distance to both the procedural cave and ribbon object is calculated ( the o function ) of which the closest is used ( and uses some fancy / simple raytracing to get the final color ).
K
Posted: Tue Nov 03, 2009 5:04 pm
by VilleK
I've updated the zgeproj-file in the first post to include a version of the shader that's easier to read with comment from the original source. Also I changed the w-variable so maybe this new version works for you yoffset.
Posted: Wed Nov 04, 2009 12:48 am
by y offs et
no change
#Fragment Shader compiled OK
#Error when linking shader program
#Error when linking shader program
#Shader variable error:w
Posted: Wed Nov 04, 2009 7:50 am
by VilleK
Hmmm... maybe ATI requires a vertex shader? Try setting this to the VertexShaderSource-property:
Code: Select all
void main()
{
gl_Position = gl_ProjectionMatrix * gl_ModelViewMatrix * gl_Vertex;
}
You can also try if the original demo works on your computer:
http://www.frequency.fr/upload/producti ... _Win32.zip
Posted: Wed Nov 04, 2009 8:00 am
by Kjell
OpenGL automatically constructs a ModelViewProjection Matrix, so you can just use ..
Code: Select all
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
K
Posted: Wed Nov 04, 2009 1:59 pm
by y offs et
The original demos just give me white screens.
the extra code just expands the log message.
#Vertex Shader compiled OK
+GL ERROR 1282
#Fragment Shader compiled OK
#Error when linking shader program
#Error when linking shader program
#Shader variable error:w
Posted: Wed Nov 04, 2009 2:10 pm
by Kjell
Hmm,
Might get tricky finding out the culprit .. could you try to decrease the number of ray-trace passes? Perhaps your driver unrolls loops and exceeds a limitation of the card somehow. Lower 64 to for instance 8 in the two instances of ..
Ideally you'd try to recreate the shader step by step .. then you'll probably be able to pinpoint what is causing the problem.
K
Posted: Wed Nov 04, 2009 2:11 pm
by jph_wacheski
Thanks Ville the coments will help,. Just want to see what I can learn from this as it is very cool,. there is a lot of shader code on the blog as well,. some may be usefull to me, so a good find indeed. Although the focus is on geometry shaders and my card does only 2.0 not 3.0 level stuff. Humm, I got a bit of cash from an honorarium from doing that arcade machine project,. perhaps I should invest some in another graphics card? Does anyone know what is cool, does ps3.0 and is resonable cost??
Posted: Wed Nov 04, 2009 4:39 pm
by y offs et
for(int i=0; i<64; i++)
that just makes the wait getting to the error message shorter.