Xor Shaders
  • Tutorials
  • About

#7 Introduction to 3D part 2

6/12/2015

18 Comments

 
In the last tutorial we made a basic flood shader. Today we'll make a basic 3D lighting shader.
Lighting shader usually use normals. As you may remember from the last tutorial, normals are the vectors which are perpendicular to each triangle. I will explain them in better detail.

Normals

Normal vector information can be received using the "in_Normal" attribute. This is only processed for each vertex (because it's in the vertex shader). So we'll create a varying vector called "v_vNormal" and we'll add it to both shaders (fragment and vertex). This way the normal can processed per pixel rather than per vertex. To test this shader we'll set the color to the normals so we can see what the normals look like. This is the code I used:

gl_FragColor = vec4(v_vNormal*0.5+0.5,1.0);

Because normals are in the range of -1 and 1 we'll multiply it be 0.5 and add 0.5 to put it in the range of 0 to 1 (since we can't see negative colors). 

Here is what it looks like (downloads at the bottom):

Read More
18 Comments

#7 Introduction to 3D Part 1

6/8/2015

2 Comments

 
It's been I while. I've finally made time to continue the tutorial series, and I would like to make an introduction to explain how shaders handle 3D in GameMaker. This is not a 3D tutorial for the GameMaker Language, but only for the shader aspect of it. To do this it is important that you read the Vertex Shader Tutorial.

getting 3D information

In order to make a shader for 3D you will most likely need to no 3d information such as position and normals. In the Vertex Shader Tutorial I explained in briefly how to get the position with the "in_Position" vector (only in the vertex shader). In order to add this to the fragment shader you'll need a varying vec3 for position. Create one and call it "v_vPosition". Make sure it's in the fragment shader also.

To get the position in 3D we will simply use the Z component along with the X and Y components. You can also get the normals (which is essentially a vector perpendicular to the currently processed triangle) of the triangles as they are set (d3d_draw functions have the normals already). When you apply the shader to a 3D object then you can retrieve the normal which is useful for lighting.

Read More
2 Comments

    Tutorials

    New tutorial at GMshaders.com!

    Categories

    All
    3D
    Beginner
    Intermediate

    Archives

    October 2021
    November 2019
    January 2019
    May 2016
    August 2015
    June 2015
    March 2015
    February 2015
    January 2015
    December 2014

    RSS Feed

Powered by Create your own unique website with customizable templates.