Adding multiple lights to and OpenGL GLSL environment

Multiple lights in GLSL

So the students are wanting to know how I would find out how to add multiple moving lights in GLS. This is a narative of me searching and finding useful information.  It was done inline to try to show process, as the process for finding information is more important than the final information.

So we need multiple moving light sources. If you look at a standard shader it often has a single light source defined. Google “glsl light code” .  The first link Per fragment lighting GLSL, this has lots on lights and the full ambient, diffuse and specular content.  The main fragment shader code is

varying vec3 N;
varying vec3 v;

void main(void)
{
   vec3 L = normalize(gl_LightSource[0].position.xyz - v);   
   vec4 Idiff = gl_FrontLightProduct[0].diffuse * max(dot(N,L), 0.0);  
   Idiff = clamp(Idiff, 0.0, 1.0); 

   gl_FragColor = Idiff;
}

You will need to increase the shaders ability to calculate lights. There are two options for this, fixed numbers of lights (5 in the case we are looking at in class) or a array of light positions. We will look at the simplest fixed number of lights.

So the process I used was to google “how to create multiple light sources in gl shaders” This gives up a page “GLSL Programming/GLUT/Multiple Lights – Wikibooks, open …” which looks like it might help us. That page gives us the idea that I could use a for loop to process the light sources, but that the for loop needs to be limited as GPUs are not great at dealing with unwrapping for loops with variable length. The code on that page show how the lights can be set in the shader. That does not match what we need. We need to pass the values of the lights into the shader. This is the fragment shader so uniforms would be visible,  if it was processing through the vertex shader we would need to create the outs and ins. Lights are going to be uniforms that update per frame.

So how do we pass light values to the fragment shader as uniforms? Lets google that. “passing updated light position to glsl shader” the first is a stack overflow. No accepted answer, next link “Introduction to Shaders: Multiple Lights” look promising.

This gives us the information that passing a struct as a uniform can be done just by defining the struct. This allows us to pass enough information for the light source. It also suggests that we could use an array of n*4 vec4 per light. The 4 elements being position, ambient, diffuse, specular. So we are going to have 4 ghosts with lights, and one ambient light so we will have 5 lights in total. One will be positioned above the board. The other will be located where the ghosts are. The ambient per ghost can be {0.05 , 0.0 , 0.0} so that there is not much ambient light about but some. Also the different lights can have different ambient colors so we can tell they are there. The diffuse would be a bit larger say 0.5 0.0 0.0 to make the diffuse more important a component.

The main thing to set is the part of the array that is the position of each light.

In the shader intro tutorial it uses a for loop. So we need to find the location in our shader that calculates the light value and add a loop to calculate light values based on the location we set.

int i;
for (i=0;i<12;i=i+4) {...

We need more than just the directional lighting provided by the shader. Thus we need to define fall off (attenuation is the technical term). In the GLSL tutorial page it suggests using the w element in the vec4 for the light to define purely directional lighting from other forms.

Google “point light source in GLSL”. The first page, covers the idea of attenuation of light sources. GLSL point light. Thus we update the shader in the assignment to handle, multiple lights. Give the locations x, y and z. Then we change the fragment shader to have attenuation so the light gets dimmer as we get further from it. Then we send in the location of the lights into the shader to have them move with the ghost. There is also a suggestion to use a different shader for different numbers of lights.  So creating a 5 light shader is a perfectly reasonable solution.

So that is some of my process to find code.  Hopefully it helps with your searching

 

Simon

Coffee&Code

It is really nice when students take the initiative to set up activities.  One of our international students likes working with Linux.  Many of our students have focused on Windows rather than Linux, so he thought it would be nice to be able to share the joy of linux with the other students.

We suggested that perhaps the department could support the activity a little to encourage students to learn in a more informal setting.

So as of Thursday the 15th of October we will be having regualar Coffee and Code sessions where the student talk about using Linux, Latex, makefile, and anything else that they think is interesting about being a programmer.

Signup form

Hopefully other students find this a useful forum for learning

Simon

Setting up my computer

So I have reinstalled windows on the correct drive. Now the install process begins

There are a lot of applications that I use regularly

Document tools.

Working on Documents:

  1. Miktex 2.9 http://miktex.org/download
    1. Accept
    2. Anyone use
    3. A4 Install packages YES
  2. Texniccenter 2.02 all as standard
    1. Use Miktex
    2. All defaults, we will set it up later
  3. Jabref
  4. Inkscape  0.91 typical install https://inkscape.org/en/download/windows/

Coding

  1. Visual Studio Ultimate
  2. Putty 0.64 all installer except Puttytel
  3. SourceTree
  4. Git Bash 1.95 https://git-scm.com/download/win
  5. SDL 2.02
  6. Cuda SDK
  7. GLEW
  8. Audacity

Other

  1. Steam
  2. VLC

Unemployment in NZ

Recently I saw some discussion of unemployment in NZ, and how the government were claiming they were managing it well. 15 years ago the right wing ACT had a policy of 6-7% unemployment as a MINIMUM level to counter inflation. This follows from the idea that if you keep unemployment at 7% you keep wage levels down. Low wage increases keeps inflation low, low inflation is very good if you are already wealthy as it protects your current wealth. ACT dropped that as an official polity, but I prefer to assess politician on what they do rather than what they say.

The currently government has former ACT party memebers mergered with the rest of the right wing National party.

Unemployment NZ vs Aus
Unemployment rate NZ vs Australia OECD data

Since the National government came to power they have implemented policies to try to achieve the 6-7% unemployment rate. They claim that the 2007 crunch caused the increase. This cliam is not supported by comparison to our nearest neighbour Australia. Looking at the OECD data for 2000-2013 NZ had lower unemployment until 2008 were NZ jumped above Aus.

The problem seems to be that much of the media in NZ just publish what the government says rather than checking those claims against international data.

Summer Game Development camp

So this summer is going to be a lot of fun.

On the 14th to the 18th of July I will be running a summer camp for game development.  We hare hoping to have 30 kids from 14 to 20 years old come and learn about game development and try to make some simple games.

The official sign up sheet is through Hyperion.  They are the head group for all gaming in Norway, and they are the ones organising all of the logistics.  I am just providing content. There will be two tracks, one focused on programming and one on design.

 

Oculus Rift + Facebook = WTF?

At The Gathering 2014 this year I talked about the Oculus Rift and had some demonstrations to show the audience.  I also talked about the purchase of Oculus by Facebook.  A lot has been written about the pros and cons of the purchase, and many people are sceptical of Facebooks involvement.

As I see it there are several potential motivators for facebook to by Oculus, some of which will create fantastic VR and some might destroy the platform. As I see it the first possibility is the publically stated one, that VR is cool and the future, and Facebook wants to be involved.  There are other additional reasons:

Sharing on Consol – Consol makers moving into the social space with Sony including the share button on the controller.  This bypasses facebooks social network and is a threat to their core business.  The rift offers another route to gamers and a way of getting them to share using facebook through the VR controller.  This motivation would require FB to make the controller the best interface for gaming.  This would be positive for the gaming experience.

Broadening Market – Facebook gaming companies are seen as entirely casual,  to expand their market beyond just casual gamers they need to be involved in activities and game projects beyond their current portfolio.  This is somewhat risky as Facebook may push the commericalisation models they currently have on the content of the Rift.  This could destroy the emmersive experience extremely easily.

Social VR – The idea of having second life in VR is one that FB has suggested.  I believe the challenge for  Social Networking in VR will be the uncanny valley of social interaction. The idea that by getting interactions to close to actually being with the person, but the connection not actually being there, may make socialising in VR worse than using texting or video chat. There might not be an uncanny valley for VR, but if there is, then social VR is in trouble.  I also think that pushing the Oculus Rift’s development in this direction would be bad for gamers.

This area is going to be interesting to watch.  The experience created by immersive virtual reality (IVR) will be both amazing and challenging.  As a society we will need to work out how to deal with the engagement of IVR.  For some people, being surrounded by the virtual world will be so enthralling that they will never want to leave. If Facebook is able to add social interaction to IVR then the lure of this new technology will become even stronger. Should there be limits on the amount of time people spend in VR? Should game developers worry about their players health? Will too much of a good thing create a backlash? What effect will driving IVR have on peoples actually driving behaviour?

It is a brave new world, and given facebooks reckless disregard for users privacy, I am not sure they are the best people to be guiding the development of a peice of technology with such large ethical concerns attached.

 

 

Eve online

The CCP talk focused on moving from the default idea of custom fast tools to using standard software engineering techniques.

These included:

Capabilities. Decoupling the client from the server.

Standards over performance

REST- standardize interface to categories of resources in the game

Dev ops is very important. Reproducible deployments.

Internal conference. Getting developers to buy into the new system.

Tearing down the wall between Dev and publishing

Read/write Api to allow 3rd party development

Customer, player and character are different in persistent universe games.

The keys learning items for CCP was to look outside the game Dev community and find people who are solving similar problems, and keep a balance between low level solutions and general capabilities.

Innovation and Rapid prototyping

As part of the Universities need to increase the amount of innovation and entrepreneurship being taught at HiG I have created a new course on Rapid Prototyping and innovation.

I will blog about the development of the course and hopefully by the beginning of August we will have a website and lots of resources for people to sink their teeth into:

The course involves intense periods of development, bracketed by lectures and assessment.  The idea is to use events like the Global Game Jam, Games for Health Jam, and the Idea24 competition here in Gjovik, as opportunities to develop actual prototypes and learn about rapid innovation.

The course requires the students to participate in at least 2 prototyping session, and demonstrate that they have learnt both the tools and techniques for rapid development.

Some useful resources include: