Sunday, 21 March 2010

Compile GLSL shaders from Visual Studio

While I was programming some shaders I found it useful to compile shaders from Visual Studio. Of course it is a much nicer way to do it with programs like Render Monkey, but for some shaders (my particle shader) it can be useful to compile directly.

So, to do that, I needed to have installed Cg (and to have an Nvidia graphics board!).

Here are the steps:

Compile glsl shaders before runtime using cgc:

1. Download and install cg (http://developer.nvidia.com/object/cg_download.html)

2. Open VS. Project->Properties->C++->
add at Additional Include Directories $(CG_INC_PATH)
(CG_INC_PATH should be an environment var after installing cg)

3. (Add the shader as files for the project.)
Right click on the shader -> Configuration Properties ->
Custom build step;

- write at Command line: cgc $(InputPath) -oglsl -profile gp4vp
for vertex shader and
cgc $(InputPath) -oglsl -profile gp4fp
(gp4vp/gp4fp are openGL profiles for Nvidia 8 series;
Here is a list of other profiles (from cg doc):

DirectX profiles
dx8ps, dx8vs, dx9ps2, dxvs2, hlslf, hlslv, ps_1_1, ps_1_2, ps_1_3, ps_2_0, ps_2_x, ps_3_0, vs_1_1, vs_2_0, vs_2_x, vs_3_0

OpenGL profiles
arbfp1, arbvp1, fp20, fp30, fp30unlimited, fp40, fp40unlimited, glslf, glslv, gp4fp, gp4gp, gp4vp, gpu_fp, gpu_gp, gpu_vp, vp20, vp30, vp40

Fragment profiles
arbfp1, dx8ps, dx9ps2, hlslf, fp20, fp30, fp30unlimited, fp40, fp40unlimited, glslf, gp4fp, gpu_fp, ps_1_1, ps_1_2, ps_1_3, ps_2_0, ps_2_x, ps_3_0

Geometry profiles
gp4gp, gpu_gp

Vertex profiles
arbvp1, dx8vs, dxvs2, glslv, gp4vp, gpu_vp, hlslv, vp20, vp30, vp40, vs_1_1, vs_2_0, vs_2_x, vs_3_0

Geforce 3/4 profiles
fp20, vp20

Geforce 5 profiles
fp30, vp30

Geforce 6/7 profiles
fp40, vp40

Geforce 8 profiles
gp4fp, gp4gp, gp4vp, gpu_fp, gpu_gp, gpu_vp
)

-write at outputs (in the same window) $(InputName).vp for vertex program
and $(InputName).fp for fragment program



//--------------------------------------------------------------------------


If you wish to have the shader code highlighted, here is a solution:


1. Copy usertype.dat (included on the Cg CD) to the Visual Studio bin directory
(Microsoft Visual Studio 8\Common7\IDE)
2. Start regedit (Start -> Run -> regedit) and go to
HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\9.0\Languages\Language services\C\C++
(older ver: HKEY_CURRENT_USER\Software\Microsoft\DevStudio\6.0\Text Editor\Tabs/Language Settings\C/C++)

3. Add .vert;.frag; (.cg;) to the end of the FileExtensions key
(each extension in the list should be separated with a semicolon)
4. Open Visual Studio, tools->text editor->file extension->
add .vert and .frag (.cg), selecting C++ editor
5. Restart Visual Studio

Your shaders should now have syntax highlighting.

Rip Off

[SEE VIDEO]

2 weeks to alpha:


older version:

[SEE VIDEO]

This is a group project, that is still under development
(we are Team "Water", and there are 8 people in the group).

The goal is to implement the "Rip Off" game
on several platforms.The version we actually reproduced was this one:
http://www.brothersoft.com/games/rip-off.html

It has to have a vector engine based version, as well as an
evolved one. Then we have to port it on PSP, and one ofGame Cube or iPhone (to be decided). We will also
have a version that will use 3D glasses, for an experiment
in treating the lazy eye illness.
At the moment we have just releasedthe alpha version for the vector graphics version.
The 3D (evolved) version is not yet finished, but is close
to alpha as well, and it is playable.


I've been working at the 3D version for this game, at the
graphics interface, 3D graphics interface and PC_3D implementation.
The graphics interface is the abstraction layer ofVector Graphics and 3D graphics. If we switch the preprocessor
directives from _VECTOR to _3D or vice versa, the program
will compile using the corresponding classes. The same thing
is valid for _PC, _PSP (_SPSP, as it seems _PSP is already
taken) and _GC.
The initial class diagram for the graphics layer looked like this:The internal class structure for the graphics layer has been changed (i've added some new classes/functionalities), but i kept this diagram for simplicity. The point I want to emphasise here is the fact that the pllication structure is portable. For example, classes like ParticleSystem or TextureManager are using classes like VBOObject or Texture. Those are determined at compile time, according to the preprocessor variables defined:
#pragma once

#ifdef _3D

#ifdef _PC
#include "../pc/3dgraphics/PCVBOObject.h"
typedef PCVBOObject VBOObject;
#elif _SPSP
#include "../psp/3dgraphics/PSPVBOObject.h"
typedef PSPVBOObject VBOObject;
#elif _GC
#include "../psp/3dgraphics/GCVBOObject.h"
typedef GCVBOObject VBOObject;
#endif

#endif


The interfaces from the 3d graphics layer are used for keeping a common structure for all the platforms. Those "IF" classes have to be implemented on each platform. The advantage of the class structure is that platform specific calls do not interfere with the graphics specific functionalities (like managing textures, or loading models ). Furthermore, all openGL calls are separated from the core classes. As an improvement we could implement the classes in DirectX as well. However, the interfaces are "OpenGL-like", and they might need slight changes while switching to DX. For now, we will concentrate on the current tasks, as there is not much time left to the final release.
I'll post the final class diagram as well, but it is a bit difficult to read, as it is quite large:


All the models are from turbo squid
and 3d studio, they are all free models :)

Teapot War

This project is a Render Monkey assignment.

[SEE VIDEO]

[SEE VIDEO1]

[READ DETAILS]

Some screenshots I like:

Real Time Graphics assignment

[SEE DETAILS]

[SEE VIDEO]

[SEE VIDEO1]


Some screenshots that I like:


Shaders 24h assignment

We had a 24 hours assignment to implement some shader effects in ASM vs 1.1 and ps 1.1.
We started from a DX9 app, that loaded the skull model, and the effects to implement were:



[WATCH VIDEO]

Screenshot from the marble effect. 2 textures are applied, one for the background marble, and one for the shining spot, that moves with the viewer.


Basic Techniques
  1. Implementation of Diffuse Lighting
  2. Blending of multiple point lights
  3. Vertex position Manipulation

Advanced Techniques
  1. Implement two specular lights, one fixed and one controlled by the mouse.
  2. Apply a marble effect texture to the skull.
  3. Implement a two tone paint effect.
  4. Implement a glowing halo effect.
  5. cubic environment mapping.
  6. optimisation of the program as a portfolio piece, ie
  • loading shaders on a key press
  • removing the rotation and replacing with mouse rotation
  • adding text information to the scene


Unfortunatelly, not all the effects work properly, because of the 24 hours limit. The main bug is at the halo effect. It was supposed to be an interpolation between the halo colour and the background colour. The app draws a scaled skull using a yellowy colour, than it draws the original skull in the next pass.

The method i wanted to use for glowing was a gaussian blur, and have a ps for that, but i doubt ps1.1 can support many texture samples. I had troubles with sampling a texture with other texCoords than the input ones, so I had to give up to this because of the time limits. It is still an open pb of how to solve this using shader model 1.1.

What the app currently does is to approximate the pixel position and yield an interpolate color, but the position is obviously wrong, as the yellow hallo appears on the top of the skull, and it gets whiter at the bottom part.

Edutainment

Crayon Physics Deluxe is a 2D physics game, where all the drawings are rigid bodies that interact according to the physics laws. The assignment we had to do was to design a game level for Crayon Physics that could be used at the end of a physics lesson (for general school pupils or high school).

So, I chose Newton's Laws, and here is my level:
[WATCH VIDEO]


More information about the physics game (including the level editor) can be found here:
http://www.crayonphysics.com/

I have written a game concept and design document for it, i will paste bits of it here:

1. Introduction

Title: Dragons’ lair
Genre: Edutainment //Educational Game
Player type: children aged 11-17
Theme: fantasy
Content: physics (Newton’s motion laws; Conservation of momentum)
Game graphics: 2D, cartoonish style
Game time: 3-7 min
Technical details: the game is a level build on “Crayon Physics Deluxe” 2D physics engine,
and thus it inherits all its requirements for functioning.

“Dragons’ lair” is an educational game that desires to help children reflect on their studies related to physics. Children must take a ball from the starting position to the exit of the dragons’ dungeon, and on its way out it must collect two stars. In order to do this, they have to apply their knowledge about motion. If the ball takes the wrong way, it will be eaten by a dragon. It is a drawing game, and the player can mainly interact with the scene by drawing objects on the screen.


The rest of the document contains the following chapter:

2. Game Analysis
2.1. Game atmosphere
2.2. Game elements
2.3. Game controls
2.4. Game play
2.5. Game action diagram

3.Physics content analysis

The theme the game is built upon Newton’s laws of motion. The game wants to be a helping tool,
which can be used at the end of the physics lesson. It also includes notions from plastic collisions
and circular motion.
There are the three wheels that are spinning, and the ball will step on them, moving from one side to the other. The point of the game is balancing the wheels, first in an isolated system, then in a more complex one. Details of physical equations and experiments involved in the game are given in the enclosed handouts.

[...]

















[...]

4. Learning content analysis

The objective of the game is to help children learn the laws of motion in a pleasant and joyful
manner. However, the game assumes that notions like vector and forces are known. Notions of
friction forces will give a better understanding of the physics contained. The handouts for older
children contain notions about rotational motion as well.

The main learning outcomes of the game should be

- Learning Newton’s laws and how to apply them
- Learning to compute the re
- Being able to predict a trajectory, if an object is projected along a given direction
- Learning and applying the momentum conservation law
- Understand how momentum conservation is used in collisions. Predict the results o
collisions between objects of different masses.
- Learn to use action and reaction forces to achieve their goal
- Observe the circular motion, and the accelerated spinning of the wheels
- Learning to solve the fixed pulley experiment, and to make analogies to

There are some additional learning outcomes as well, when the player is rewarded. The player will be tired after balancing the wheels, and will be anxious to see his progress - so it will be attentive of what is going on. He will notice the accelerated motion along the curved trajectory and the jumping of the plane, and will see the pendulum and the collisions at the end. The pendulum experiment could well be a revision from previous lessons, or a hint to the next ones.
The learning elements are intrinsically linked within the game play. A flow chard diagram is
represented [...]

5. Key features

6. Conclusions

7. References

Micah Hrehovcsik, Game Concept & Design Document Template, available at
student-kmt.hku.nl/%7Egiel/blog/Concept/Documenten/Representatie/DesignDocTemplate_1.5.doc

*******
The link above does not work if opened directly from my blog :(
You can either paste the link in a new tab, or go to
http://student-kmt.hku.nl/~giel/blog/Concept/Documenten/Representatie/
and download DesignDocTemplate_1.5.doc
*******


SAT Physics, Spark notes, last modified: 11th September 2009
http://www.sparknotes.com/testprep/books/sat2/physics/chapter10section4.rhtml
The Physics Classroom, last modified: 13th November 2009,
http://www.physicsclassroom.com/Class/newtlaws/

Friday, 19 March 2010

Real Time GPU Graphics Engine Modules

This piece of work is my bsc final project. Basically it is a collection of rendering methods implemented using shaders.

[SEE DETAILS]

I have uploaded some videos on youtube:

[WATCH VIDEO]

[WATCH VIDEO1]

[WATCH VIDEO2]

[WATCH VIDEO3]



Some screenshots that I like:



Year 4 projects

I will describe in this post my graphics projects that I develloped during year 4, at university. These are my oldest graphics projects, but I think they worth mentioning.

Loader and Modeller 3D

This was a group project for 2 persons. It is an app that allows model loading (3ds but limmited, and ms3d) and mesh manipulation. The user can displace vertices, can change texture coordinates, and apply affine transformations on the model. Animation from ms3d models can also be displayed.The app looks like this:



Using this loader (porting him into a new application) I've made an app for the AI module, implemetning a genetic algorithm for finding the way out of a labyrinth. The one who had to get out of the labyrinth was the animated dwarf:

A video from this app can be found here.

Another assignment that used the dwarf model:This is an older application, which is based on Nehe Lesson 31. It loades an ms3d model and has reflections on the ground. The skydome that surrounds the scene is spinning to suggest clouds movement.


And I have to mension my first shader assignment (Cg):


The next picture is from an application that implements volume shadows. It casts shadows from rotational objects.


This application is a small game, it has cubes that fall from the upper side of the screen. If the user presses a cube with a certain colour, the adjacent cubes with the same colour fade out, and the cubes that lay on top start falling.