Simple Texture Light - Printable Version

+- Forums (
+-- Forum: Main Forums (
+--- Forum: OpenGLES2.0 Shaders (
+--- Thread: Simple Texture Light (/showthread.php?tid=30)

Simple Texture Light - Brian Beuken - 03-04-2018

I will post soon

RE: Simple Texture Light - Brian Beuken - 04-29-2018

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]

RE: Simple Texture Light - Brian Beuken - 02-23-2019

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!

RE: Simple Texture Light - jomoengineer - 02-27-2019

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.

This does seem like a cool way to change the look and feel of items in a game.

RE: Simple Texture Light - Brian Beuken - 02-27-2019

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.

RE: Simple Texture Light - Brian Beuken - 02-20-2020

Here's a simple vertex light shader for you
  #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

    #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;