Cool demo with ZGE-conversion

All topics about ZGameEditor goes here.

Moderator: Moderators

User avatar
VilleK
Site Admin
Posts: 2382
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Cool demo with ZGE-conversion

Post 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 :)
Attachments
zge_ribbons.jpg
zge_ribbons.jpg (93.63 KiB) Viewed 13606 times
ToTheRoadOfRibbon_ZGE.zgeproj
(1.95 KiB) Downloaded 572 times
Last edited by VilleK on Tue Nov 03, 2009 5:01 pm, edited 1 time in total.
User avatar
Kjell
Posts: 1929
Joined: Sat Feb 23, 2008 11:15 pm

Post by Kjell »

:o

Pretty crazy, it's the old-skool raytracer days all over again 8)

K
User avatar
y offs et
Posts: 418
Joined: Wed Apr 22, 2009 4:26 pm
Location: BC, Canada

Post 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.
User avatar
VilleK
Site Admin
Posts: 2382
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Post 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>
User avatar
y offs et
Posts: 418
Joined: Wed Apr 22, 2009 4:26 pm
Location: BC, Canada

Post 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.
User avatar
jph_wacheski
Posts: 1005
Joined: Sat Feb 16, 2008 8:10 pm
Location: Canada
Contact:

Post 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.
iterationGAMES.com
User avatar
Kjell
Posts: 1929
Joined: Sat Feb 23, 2008 11:15 pm

Post 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
Attachments
Ribbon.zip
(27.29 KiB) Downloaded 543 times
User avatar
VilleK
Site Admin
Posts: 2382
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Post 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.
User avatar
y offs et
Posts: 418
Joined: Wed Apr 22, 2009 4:26 pm
Location: BC, Canada

Post by y offs et »

no change

#Fragment Shader compiled OK
#Error when linking shader program
#Error when linking shader program
#Shader variable error:w
User avatar
VilleK
Site Admin
Posts: 2382
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Post 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
User avatar
Kjell
Posts: 1929
Joined: Sat Feb 23, 2008 11:15 pm

Post by Kjell »

:idea:

OpenGL automatically constructs a ModelViewProjection Matrix, so you can just use ..

Code: Select all

gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
K
User avatar
y offs et
Posts: 418
Joined: Wed Apr 22, 2009 4:26 pm
Location: BC, Canada

Post 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
User avatar
Kjell
Posts: 1929
Joined: Sat Feb 23, 2008 11:15 pm

Post 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 ..

Code: Select all

for(int i=0; i<64; i++)
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
Last edited by Kjell on Wed Nov 04, 2009 2:11 pm, edited 1 time in total.
User avatar
jph_wacheski
Posts: 1005
Joined: Sat Feb 16, 2008 8:10 pm
Location: Canada
Contact:

Post 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??
iterationGAMES.com
User avatar
y offs et
Posts: 418
Joined: Wed Apr 22, 2009 4:26 pm
Location: BC, Canada

Post by y offs et »

for(int i=0; i<64; i++)
that just makes the wait getting to the error message shorter.
Post Reply