Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Simple Texture Light
#1
I will post soon
Brian Beuken
Lecturer in Game Programming at Breda University of Applied Sciences.
Author of The Fundamentals of C/C++ Game Programming: Using Target-based Development on SBC's 



Reply
#2
And here I am at last, sorry been busy, lets talk about light and what a difference it can make to your games
The 2 models below are simple examples of a model drawn with a light shader and without, the difference is quite marked.

There are rather a lot of lighting concepts out there and some need a bit more work and effort than others, we'll start with a simple one which can be found in the Model Light demos

[Image: snapshot.png]
Brian Beuken
Lecturer in Game Programming at Breda University of Applied Sciences.
Author of The Fundamentals of C/C++ Game Programming: Using Target-based Development on SBC's 



Reply
#3
On thing I have noticed and am a bit annoyed with myself, I didn't convert any of my camera positions in to view space before sending them to the shaders....that a doh!
Brian Beuken
Lecturer in Game Programming at Breda University of Applied Sciences.
Author of The Fundamentals of C/C++ Game Programming: Using Target-based Development on SBC's 



Reply
#4
This is cool.

I recently watched a talk from John Romero (id Software: Commander Keen, Wolfenstein 3D, Doom and so on) where he discuses the creation of Doom and part of the talk he mentions how they used light and shading to enhance the scary nature of the game.
https://www.youtube.com/watch?v=eBU34NZhW7I&t=1478s

This does seem like a cool way to change the look and feel of items in a game.
Reply
#5
yes light totally creates a sense of immersion in a game. A shape or model will always look artificial until light is applied and it smooths and adds subtly to the model as the pic above shows.

Get a flickering torchlight in front of you with a distance limit and you get a real sense being in a cave with a flame torch.

Light in all is different forms is one of the main challenges to a graphics programmer trying to achieve realism.
Brian Beuken
Lecturer in Game Programming at Breda University of Applied Sciences.
Author of The Fundamentals of C/C++ Game Programming: Using Target-based Development on SBC's 



Reply
#6
Here's a simple vertex light shader for you
Code:
  #version 100

  uniform mat4 MVP; // A constant representing the combined model/view/projection matrix.
  uniform mat4 MV;    // A constant representing the combined model/view matrix.
   
  uniform vec4    Ambient; // we will discard this for now, feel free to re add it.
 
  attribute vec2 a_texCoord;
  attribute vec4 a_Position; // Per-vertex position information we will pass in.
  attribute vec3 a_Normal;   // Per-vertex normal information we will pass in.
 
// These will be passed into the fragment shader.
  varying vec2 v_texCoord;    
  varying float v_Colour;    
 

 
  void main()
  {        

      vec4 u_LightPos = vec4(2.0, 5.0, -10.0, 1.0); // The position of a light in world space. should really be a uniform passed but for test, make it a fixed point in space.

     vec4 modelViewVertex = vec4(MV * a_Position);   // Transform the vertex into camera space.
     vec4 modelViewNormal = vec4(MV * vec4( a_Normal,0.0));     // Transform the normal's orientation into camera space.
       u_LightPos =   MV * u_LightPos; // put light in camera space (this could be done on the CPU but leaving it here in case you want to do other things)

    // Get a lighting direction vector from the light to the vertex.
      vec4 lightVector = normalize(u_LightPos - modelViewVertex);

    // pass the output values to the fragment
     v_Colour = max(dot(modelViewNormal, lightVector), 0.05);  // dont allow totally black ie 0.0
      v_texCoord = a_texCoord;                                        

     gl_Position = MVP * a_Position; // usual positon calc
  }

and the frag for it

Code:
    #version 100

uniform sampler2D s_texture;
varying vec2 v_texCoord;
varying float v_Colour;

void main()
{
    gl_FragColor = texture2D( s_texture, v_texCoord )*v_Colour;
    gl_FragColor.a = 1.0;
}
Brian Beuken
Lecturer in Game Programming at Breda University of Applied Sciences.
Author of The Fundamentals of C/C++ Game Programming: Using Target-based Development on SBC's 



Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)