Showing posts from January, 2016

Project 3: Grass Sim

Overview One of the main problems with rendering lots of primitives, is each one requires its own draw call/position definition.
A solution to this is instanced rendering, where you give opengl a set of vertices and tell it to render it X amount of times. Since it computes everything internally from then on the cost of it is near 0.

Instanced rendering does this (pseudo code):
for 0, X do Set Instance ID DrawArrays/DrawElements.etc
In the form of this:
GL.DrawArraysInstanced(PrimitiveType.Triangles, 0, 3, X);
So now the fun part involves the shaders because each instance cannot be given a unique uniform value (which is what I do normally).
Each instance has an ID from 0->X, utilising this in interesting ways allows you to produce cool effects for practically free.

Here's what I came up with after playing around with it:

Video after adding a time uniform:

Vertex Shader Details To distribute the triangles uniformly given a number from 0 -> 10,000.
int x = int( mod( gl_Instan…

Cloth Simulation Update

Some of the issues I found with the system since my last post:
I assumed that all constraints had the same rest length, now it takes into account shear and linear constraint lengths.I only accounted for X,Y properties of each point which caused points to act strangely when close to each other, I have changed it to work in 3D. Although the view only looks 2D.  Here's the result:

Project 2: Cloth Simulation

Cloth simulation using opengl and c#.

My previous project was about learning the graphics api opengl (lighting/models/projections/shaders) and I feel like if I wanted to carry it on I would have to start again from scratch using things I learned the first time around.
Instead I am focusing on some other concepts which have been on my bucket list for a while now, cloth simulations.
My first task was how to effectively render a "cloth" matrix (?) so that I could visually see the system, this is actually quite a challenge when opengl is focused on 3d not 2d.

I set up the model-view-projection matrix using an Orthographic Projection.
Then since the original coordinate system goes (0, +Y, 0) up the screen, (+X, 0, 0) along the screen it was not intuitive to debug so I applied a scale of (0, -1, 0) and a translation, because (0, 0, 0) is the center of the screen in opengl, to transform it into Cartesian coordinates.

Ok... so now I can draw some dots and lines in the right place.


Sketchy physics simulations.

Today I attempted to wrap my head around portals...

In my simulation, when the spheres reach the bottom of the tube, they are teleported to the right hand surface of the cylinder. Maintaining speed but changing the sphere's direction.

Initially I ran into a problem of them gaining energy over time, since the force which pushed them from the portal is proportional to the velocity it hits the bottom and the position of the ball along the horizontal axis.

Then after some thinking with my trusty whiteboard...

I realised that it was because I wasn't forcing the spheres out with the same amount of energy the spheres had at the bottom of the tube! Momentum!

Another issue I had was that spheres would converge, I figured it was something to do with the way I was applying drag to the velocity of the spheres. After all portals can't exist in a real physical model without hacks can they? In my opinion I think this one looks the most... real. Since everything loses energy it makes sen…

OpenGL clipping technique.

Part of the physics simulation I am working on at the moment involves cutting a cylinder in half, so that spheres have a defined space to interact but we can also view them.

First I created a cylinder in 3ds max, with normals included. I didn't create the half cylinder because I want to have multiple cylinder objects for the spheres to collide with (also I was interested in the process).

So I implemented an extra expression in my GLSL fragment shader, to say:
 If the X value (the camera looks down the X axis) of a fragment (in worldspace) is < 0 then discard that fragment.
Initially, using the `discard` in-built function I got really strange results, with some fragments being removed and some staying. It looked like static on a TV.

This problem was solved by implementing alpha blending, and setting the alpha value of fragments I want to discard to 0.0.

This was great! however I wanted more control over the clipping (hardcoded at the time), so I decided to define a "clippin…

First programming book arrived!

Very pleased with the purchase! Hopefully I can now finish some 3D code I have been tearing my hair out over. It even has sections on Compute Shaders (which I am very interested in, OpenCL is too cryptic for me.).

Ten Golden Usability Rules

Taken from Jakob Nielsen in his book `Usability Engineering`.
Use simple and natural dialog/language. Since every additional feature or item of information on a screen is one more thing to learn, one more thing to misunderstand and one more thing to search the user interface should be simplified as much as possible. Less is more.Use language that fits the user group. The language should be based on user's language and not the system-oriented terms. Translation from one language to another is more than just words. Time, current, phrases, metaphors, measurements all must fit the culture of the user group.Minimize the load on short-term memory. Users should not have to remember information from one part of the interface to another. Instructions of usage should be visible or easily retrievable whenever appropriate.Make the graphical user interface coherent and consistent. The same action should always have the same effect.Give the ability to use shortcuts. Accelerators (unseen by nov…