Friday, 7 November 2014

Tangents and Shades

Tangent Space (Texture Space)

-Tangent Space, Like World, Object and Camera space is a co-ordinate system. It is a very specific co-ordinate system that works specifically with textures. It is here that you declared where your textures on you model are laid out. It works in an xyz axis system where X = U, Y = V and Z = N(or W). We use this system specifically for lighting and most other shaders such as normal mapping. If we were to declare all our normals in our world space then we would have to translate or rotate every normal on an object when it moves. Instead using this method we can simply move the light into our tangent space.

If you look below you can see a shaded sphere, the U and V axis are forming a plane along the tangent line and our W is being used to calculate the shading on the specific point. This calculation is done on each individual polygon meaning that if we did not have to move hundreds of normals but instead one light, in a major scene which a lot of objects what would be easier? Moving thousands of normals for our scene or a dozen or so lights a few times.
^ Above Image from www.sedris.org



Bi-Tangents

A bi-tangent is a line that serves as a tangent for two different points, it is mainly used in normal mapping and bump mapping in order to calculate lighting to be smoother and more realistic


Bitangent
^ Above Image from http://mathworld.wolfram.com/Bitangent.html


Batches

A back is a large amount of information that we send to the render at once that is set to run to completion. This reduces our system overhead by running a program once for multiple processes instead of running the program once per set of instructions. This also allows for the process to shift with the usage of computer resources for smoother execution.



Deferred Shading

Defered shading is a screen space shading technique. It is called deferred because all of the lighting calculations are done last. For our first pass we collect all the necessary information needed for shading as well as doing our drawing pass for our geometry. After that we calculate our lighting. The lighting is specifically calculated for only the areas that it effects. This method however does not work with transparency and it is common when working with transparency to render the pransparent portions of your scene last.

Friday, 17 October 2014

Continuation




Error Handling 

Error handling is the anticipation, detection and resolution of errors. The best types of error handling systems are able to recover from errors and return information on how those errors happened. You can also use breakpoints to find errors. While this does not return the specific error it help you to find the approximate point in which the error occurs.


There are three kinds of errors. Syntax errors are caused by the improper use of a function or character. Logic errors are caused through being given undesired results. These take a lot of time and effort to fix. Run time errors are caused through invalid input data in a function such as giving it and object to operate on that does not exist or is of an incorrect type.


Exception throwing is when a function cannot do what it is designed to do. It is known as an execution failure. Exceptions do not return error code but instead report errors in your framework.


 ex: if (b==0) throw Ad::Exception(“Divide by Zero”); c = a/b;


If an exception is thrown than it cannot be ignored. The exception will unwind the program stack until it finds the portion of the program that knows what to do with it. If nothing is found then the program will terminate, otherwise the program will continue to run.


 Try not to throw an exception but instead use an assertion.



Iterators (Basic Reminder)

An iterator is an object that points to something in a range of element. This can be something like a vector, and array or any other kind of container. It gets its name because it iterates through the elements of that range.

Wrappers

Wrappers are needed for many reasons. Using them we can change our interface, make our program more user friendly, hide low level code, change the internals of a program without altering the software and guarantee function behavior across multiple platforms. Is something is wrapped it also allows for new functions to use it in their functions.

Singleton

A singleton is something that exists as itself that cannot be multiple things. It is bad for code because you cannot have more than one of them.



Global Variables are Bad

Global variables are bad as they pollute your code, especially in a header. Also everybody has access to it and therefore can alter it making it a higher chance to bugger up your code.

Camera

Cameras have three vectors: direction, up and left. These are all perpendicular unit vectors. When you rotate a camera there are two methods. Assuming the up vector is right and assuming its wrong. In the second method you take the world up as your up vector. This will not work if you are looking directly up

Affine Transforms

An affine transformation is a function that keeps the ration between points, lines and planes. When an object goes through an affine transformation it is  identical to the original in its ratios between all the distances of each point. An affine transformation can be a translation, scale, reflection or rotation in any combination, order or sequence. This means that, for example, ever linear transformation would be an affine transformation, but not ever affine transformation would be a linear transformation. 


Affine Transformation (as reflection)




Homogeneous Co-ordinates


Homogeneous coordinates allow us to project 3D geometry in an euclidean space into our projective space

See:
http://deltaorange.com/2012/03/08/the-truth-behind-homogenous-coordinates/

Friday, 26 September 2014

For Starters


This year, much like the last I will be recording what I learned in the process of this course.
For those of you who are here for graphics go here: www.bishopsgraphics.blogspot.ca

What is Game Engines


To start with we should ask what is game engines. A game engine is the basic software or a video game. It is what we start with and work from to get a game instead of working from scratch. There are a large variety of engines out there, two examples of these would be the Creation Engine which Bethesda made and used for Skyrim and Unity. The Creation Engine would be an in house engine, meaning that is is made by and used by the same company internally and they do not share it. The Unity engine on the other hand I developed specifically for others to use, coming with its own built in tools that allow people to pick up and use it with less experience than required for other engines. With game engines you can do special effects with the tools you already have, but, to stand out, it is better to know the inner workings of your engines in order to help make you own unique effects.


What do we Need

You may be thinking, what do we need in order to learn engines. Really all you need is your computer and to get a hold of the source code for an engine. It also help to have strong knowledge of C++, linear algebra, and computer graphics.


Pointers 

The first topic we are going to be starting with are pointers, specifically smart pointers. What is a smart pointer? A smart pointer is a data type that simulates a pointer while also filling in with other useful functions. Unlike normal pointers, smart pointers keep track of the memory they point to. This means you can use them to free up memory when deleting an object and prevent memory leak. This is done through returning an unique pointer.The unique pointer takes a copy of your data for you to use, then deletes itself when you are done with it so that you do not forget to delete your objects. The major benefit of a unique pointer is that if I will not work then the program will complain instead of continuing to run, forcing you to find the error yourself.

A virtual pointer is a type of smart pointer. Take for instance the code

        {int *i = new int(0); delete i;} 
This is a shared pointer and the code will not push itself off the stack instead we must use:
        {sharedPtr i(new int(0));}
This code will delete itself but we want to avoid using new so we use
        {sharedPtr i = MakeShared<int> (0);}
While this works it is still a shared pointer. Shared pointers have a innate problem where they permeate through your code and make them unable to be deleted as they get tangled up in to much code that ends up using it. To stop this we would use the Virtual pointer I talked about before.
        {VirtualPtr<obj> obj = ToVirtualPtr(GetObject());}

If you look at the old method, lets say there is a function called ThisFunction() later in your code and ThisFunction() requires a shared pointer. By using you pointer ThisFunction() has now altered it so you have to go back and make sure it does not mess up your old code. If we instead use the virtual pointer then we would not screw up our system, this is because if it gets deleted then you will be alerted by the system and you will not have to go back and search through all your code for the errors, saving you time and making your code easier to read.

For pointer remember to not used shared and try to avoid unique pointers unless the code is solely yours. There are other pointers called weak pointers which break cyclical dependencies but since those are frowned on we also try to avoid them. Always try to use virtual pointers and virtual stack objects (covered later) instead.



Entity Component System



The Entity Component System (or ECS) is the inner working of our program that helps us process information. Every library has a Component system in it. While we may use a scene graph in order to see our game scenes and how the objects in them interact the ECS exists for our computer. It is how we use objects in functions.


Think of the entity as a key and the components are the teeth on a key. A function would be a lock, in this example character movement. To open the lock we require a few things, the current velocity of the character and its position. 


If you look above you can see that our key has two of these teeth. meaning that it can open the lock to the character movement function. This prevents objects lacking attributes needed for a function to be used for a function.