Category: Graphics

Natalled

Earlier this year both Microsoft and Sony presented what they called the “Future of gaming” class of controllers, but whats really going on here.
To answer that we have to look at their technologies and then derive intent from that.
It’s two seemingly very different control schemes, but are they, one uses a time-of-flight (TOF) camera to sense it’s surroundings and most notably the depth of it, the other one uses a high res camera to sense it’s surroundings that while it can’t measure depth it can track certain objects on the z axis reasonably well, however it is augmented by a glowing ping pong ball on a stick for “sub pixel 3d tracking”, it also has buttons which are useful at times.
Both systems also have an array of microphones which makes it easier to track and filter out voices. Read more »

Running OpenGL3.0 – part3

In our third installment we are looking into replacing all the matrix math previously built into openGL, what I am going to show you replaces most of it almost exactly like openGL used to work, naturally if your doing something a bit more advanced like a game or so, I would suggest that you use your scene graph to generate new matrices.

It’s really quite simple though, and as with the previous part we have to do some changes a bit here and there, so I am going to start with the most generalized bit and work my way down, and finally end up with the classic rotating cube.
But first the prerequisites, I am assuming that you started where part 2 left off, we will also need the following functions made to work
glGetUniformLocation
glUniformMatrix4fv

Step 1 – the shader
it’s really not that much but after

in vec3 Normal;

add

uniform mat4 projMat;

this will be where we send our new matrix to.
Then later in the code you need to do something like this to use our matrix

gl_Position=projMat*pos;

You could use and I almost recommend that you use two matrices one for the camera and one for the model transformation, but I leave that task to you.
Please note that the order of the multiplication is important. Read more »

Running OpenGL3.0 – part2

In this part I will show you what you must do to render even the smallest speck of graphical garbage on the screen in the openGL 3.0 API, it’s somewhat simple once you have all the tools.
First you need a good GLSL shader implementation because nothing will render without it, you can use mine if you want but just remember that we are gonna modify it a bit so it can’t be to abstracted.
Next you need to take a look at the VAO tutorial since well be using that too, naturally since we are using VAO well also be using VBO and in this example I have 3 buffers with the vertex, texture and normal coordinates for a cube, you could use anything, but I am using a cube.
We are also going to use 4 new functions so go ahead am make them work as well.
glVertexAttribPointer
glBindAttribLocation
glDisableVertexAttribArray
glEnableVertexAttribArray
Finally remove anything that has to do with matrices, well discuss those in part 3, in fact remove or comment out any deprecated function (you can find them in part 1).

Now then, there are about four steps to this, that is there are 4 things you need to change in your already existing code for things to work, so I will explain them in order. Read more »

Running OpenGL3.0 – part1

Welcome to a series I have planned on OpenGL 3.0 regarding the forward compatible mode, or in layman’s terms, using OpenGLwithout all the stuff that got cut.
It’s quite a different beast to work with, even I have problems getting my head around it since so much things that you used for every other line has to be done differently, I find myself adding the line glTranslatef(…. only to suddenly stop thinking “o, right, doesn’t work anymore”.

It’s a bit harder also as you have to use shaders or it won’t be drawn, you cant just use a VBO like before but instead you have to bind it to a input variable.
In short everything is different, but I will try to guide you trough the basic stuff, but look at it from the bright side, now you have no more excuse not to code the way it should be done.

So what got cut well quite a bit, take a look at http://www.opengl.org/documentation/specs/ and download the 3.0 specification and then check under the section called “The Deprecation Model”, but here are some highlights Read more »

Vertex array objects

With openGL 3 came a few cool features most of these are pretty small and quick to learn, VAOs are among these, I really didn’t want to write a full fledged tutorial about it before, but seeing as I’m changing the format to promote shorter and more article like posts, it seemed like as good as place as any to start.

There hasn’t been that much written about the vertex_array_object extension, also there is some confusion on where to use it and how.
Simply put it couldn’t be simpler, it’s used to make the daily life of using VBOs easier and the code prettier, earlier you had to call these three functions for each buffer to set up rendering, normally that would be at least 3.

glEnableClientState
glBindBuffer
glTexCoordPointer Read more »

Recent updates

Ok, a lot has happened recently, so let me update you on things and thoughts I had.
First, I finally got a real job, I am now a professional web programmer, not exactly my first choice but hey you can’t get it all, well at least it allows me to develop some ideas I have while I’m getting paid for doing things, and the upside is that it’s a pretty flexible job, being deadline based and all, I can take an extra long lunch if I need to as long as I get things done on time.
Fortunately I do a lot of back end work so deadlines and jobs are reasonably evenly spaced and phased, most of the time.

Anyway moving on to anime, my current anime viewing list is

Slayers revolution
Zero no tsukaima 3
Sekirei
Nogizaka Haruka no Himitsu
Mission-E
ToLoveRu – Trouble

See at least some of them or forfeit you license to be of the ruling class when I take over the world. Read more »

Diablo time

Another day another blizzard teaser update.
This is the third day of the teasers and yet another new rune has appeared on that ice field image.
Now I would have written this like on Monday when I first was sure about what would happen, but I wanted to be extra double sure by having at least one or two predicted data points, and that came today.

The reveal this weekend is going to be Diablo3, and here is why.
1. we have 5-6 days to the reveal this weekend, but only 5 days of possible runes (Monday-Friday).
2. these five runes form a pentagram, they could also form a circle but now that the third rune appeared in the predicted place I am pretty sure it’s a pentagram, and for the record the next rune will be at the to and the fifth at the bottom right.
3. there is no other ip they could release right about now, that and Diablo3 is long overdue. Read more »

Out with the old

Today I say farewell to a great thing, a thing I have looked upon for hours at end for the last 5 years.
It served me well when I needed it to and it allowed me to shoot further away, it made antialiasing obsolete and not to mention how it heated up the room those cold winter nights.


the one

I hadn’t planed replacing it for some time but a month or so ago I think it sprung a leak in one or two capacitors, and ever since then it got blurrier and blurrier and not to mention that I had to degauss it 3 times a day, in the end (read yesterday) it decided it where going to pack it in and leave basically all text below 14pt totally unreadable. Read more »

Say cheese

I got myself a late Christmas present today, I bought a cheap (relatively speaking) DSLR camera, a Nikon D200.

It’s one of the top ten best DSLRs out there and I like it, seriously, it can do so much, for example, it works perfectly with older Nikon lenses so I has a blast running around with my mothers old micro nikkor taking macro pictures of everything, another thing is the shear rate it can take pictures at, 5 per second it takes pictures with 12Bit of dynamic range(yours have 8), and it can be tricked into taking HDR images. Read more »

PCF

In the last previous tutorial we explored the depth shadow maps in all it’s aliasing glory.
I showed you ho to fix the steep angle artifacts by using the diffuse term, and the shadow poping by adding a bias to the shadows.
In this lesson we are going to implement something called Percentage Closer Filtering or PCF as it is more commonly called, the name doesn’t exactly reveal what it does.
It is in fact a way to multi sample the shadows and this is pretty simple, so simple that i am not going to supply you with anything other than the new shader file, the rest is exactly the same as tutorial 03a.

1. transform the texture coordinates first two values by a really small amount.
2.make a shadow test against those coordinates.
3. repeat 1 and 2 as many times as needed..
4. take the collective result from the shadow tests and divide it with the number if samples you just did.

Lets demonstrate this with some code.
First we set up some variables + load the other textures besides the shadows.
Since we are also going to do 25 samples we want to eliminate as much as possible from the loop, that is why i added the inverted bias to gl_TexCoord[2].z instead of the shadow value.


float blur_spread[5];
blur_spread[0] = -0.003;
blur_spread[1] = -0.001;
blur_spread[2] = 0.000;
blur_spread[3] = 0.001;
blur_spread[4] = 0.003;

float samples=1.0/25.0;

gl_TexCoord[2] = gl_TexCoord[2]/gl_TexCoord[2].w;
gl_TexCoord[2]=(gl_TexCoord[2]+ 1.0) * 0.5;

gl_TexCoord[2].z -=0.005;
vec4 base = texture2D(texunit0, gl_TexCoord[0].xy);
vec3 norm = texture2D(texunit1, gl_TexCoord[0].xy).xyz*2.0-1.0;

float shade=0.0;
float shadow=0.0;

int x=0;
int y=0;

next do the sampling, note that because a division is more problematic than a add, we pre divided the samples so instead of adding one for each sample we are adding 0.04, this saves us the trouble of having to divide at runtime.


for(x=0;x<5;x++)
{
for(y=0;y<5;y++)
{
shadow = texture2D(texunit2,gl_TexCoord[2].xy+vec2(blur_spread[x],blur_spread[y]));
if(shadow > gl_TexCoord[2].z)
shade+=samples;
}
}

Great now all we have to do is include the rest and we are done


norm = normalize(gl_NormalMatrix * norm);
float fresnel =max((norm.z-0.6)*-1.0,0.0);
float diffuse = max(dot(lightVec, norm),0.0);
float specular = max(dot(reflect(lightVec,norm), viewVec), 0.0)*1.7;
specular=pow(specular,8.0);
shade*=diffuse;
gl_FragColor = (base* shade)+(vec4(0.0,0.1,0.3,0.0)*fresnel)+
(vec4(0.5,0.5,0.4,0.0)*specular*shade);

You can now begin to play around with the numbers, increasing the values in blur_spread will make it a bit more blurry, but then other artifacts show up, these can be fixed by fiddling with the bias parameters, but ultimately PCF is just a hack and won’t work every time.
I originally planned to include a version that changed the blurriness according to the distance from the shadow casting surface, it looked pretty good, unfortunately not good enough in all situations, it was done by getting the distance between the fragment and the shadow map depth value and with this manipulating the values in blur_spread.
It would have worked if it whereat for those meddling kids(read:artifacts).
Test and see if you can do it.

Download the new shader file for this tutorial, to get the rest download the previous tutorial

WordPress Themes