It has been quite a long time since last posted a proper development update article. Of course we did not intend to leave you in the dark. Gathering information about all our progress takes time, and it is easier to write things on the spot than looking at it in retrospect.
Instead of focusing on multiple new features like we have in previous development update, we will be focusing on one new feature instead.
This article is a rather technical one and the subject may not interest everyone of you. We hope you will have a fun read!
Ripping out the Shader Editor
Source Shader Editor is something we distributed with the last Estranged Alpha - on a simple level it lets us create shaders (programs that take data from the game and tell the graphics card how to show it on screen) in an editor.It was a third party tool created by a mod developer named Biohazard.
Now why would we rip out the Shader Editor? The answer is pretty simple. We are now able to write our own shaders directly for Source. Which allows us to interact with the Source Engine on a deeper level.
Why would we not just keep both the editor and our own code, it shouldn't affect the project that much at all. In fact we still have the Shader Editor materials sitting in our mod acting like nothing has ever happened.
We ripped it out because we are trying to keep things clean. The Shader Editor is a pretty bulky buddy, adding a bunch of extra files to the codebase and also its own shader data files, the so called ‘canvas' files.
One of our new friends, Drew Watts, has also been helping integrating some of his custom shaders into our mod. We don't want these files to just be out there in some canvas files because they are not our work, they're Drew's.
Now what does programming shaders from scratch without the Shader Editor allow us to do that we can't do when using the editor. Well, as it turns out. Quite a lot!
The Phong Reflection Model
A bunch of modders out there may be familiar with the ‘VertexLitGeneric' (model shader) VMT parameters named ‘$phong' and all of its children: ‘$phongfresnelranges', ‘$rimlight', etc... An good example of a model that uses the Phong reflection model is the character model of Alyx.You can find more information about the Phong for these materials on the Valve Developer Community wiki.
Now what is this Phong? Or more specifically in this case; what is the Phong reflection model?
It is a mathematical model that allows you to calculate the local illumination of points on a surface. A.k.a. it allows you to calculate light reflection of the lights in the area.
World geometry in Source usually uses the ‘LightmappedGeneric' shader and does not support the ‘$phong' parameter and its children.
Specular Phong support for World Geometry
This is where it gets interesting. Estranged's ‘LightmappedGeneric' isn't using the default shader code anymore. It has been customized and made to support up to 10 lights. This means that we can input a maximum of ten lights for Phong reflection calculations.
The system isn't completely stable yet but most of it is working properly now. It wasn't easy to get it all to work but it was worth the effort.
A few things had to be done to get it to work properly. Initially we used the same function that the Phong shading for ‘VertexLitGeneric' uses to get its light information. This function supplied us with four lights that turned on and off rather rapidly fading into existence based on ‘ambient cube' information.
After asking around we found out that we can make our own interface to allow the client to interact with the shader DLL files. So a function was written to get us 10 lights instead and BAM! The shader could now process up to ten lights! The best part of it all is that we are able to control how they are handled instead of having to rely on an inaccessible function.