   Fixed function materials vs Shaders for a game engine.
  OK right now my engine uses shaders but it makes the script for the engine kinda sloppy and the rules for this one engine class have to be different from every other class, for instance:GameMaterial = material( "Data/Shaders/Default.fx" )GameMaterial:set_texture( "txDiffuse", "Data/Textures/Female.dds" )GameMaterial:set_texture( "txEnvironment", "Data/Textures/rnl_cross_mip.dds" )GameMaterial:set_variable( "Environment_map_intensity", 1, {0.005} )GameMaterial:set_variable( "lightPos", 4, {-5.0, 0.0, 0.0, 0.0} )GameMaterial:set_variable( "Diffuse", 4, {3.0, 3.0, 3.0, 1.0} )Object:set_material_slot( 0, GameMaterial )This type of scripting is not the same as the clean easy to use classes that have default values which I have for other things, such as this:GameWindow = window()GameWindow.title = "Ether"GameWindow.icon = "Ether.ico"GameWindow.width = 1024GameWindow.height = 768GameWindow.maximize = falseGameWindow.size = falseI have to set the light position for each object and I have to set the variables for the shader but if I used fixed function materials I could just add lights to the scene and make a clean simple to use class which could be just as advanced as any shader but at the cost of versatility. For instance to use a fixed function material would look something like this:GameMaterial = material()GameMaterial.diffuse = {3.0, 3.0, 3.0, 1.0}GameMaterial.texture = "Data/Textures/Female.dds"GameMaterial.environment_map = "Data/Textures/rnl_cross_mip.dds"GameMaterial.reflection_intensity = 0.005Object:set_material_slot( 0, Material )If you were using a game engine which method would you prefer, versatility vs ease of use?   
  using FFP, actually uses shaders behind the scenes (on shader capable cards). ;)may as well just bite the bullet and provide the flexibility people expect   ;Quote:Original post by Matt_Dusing FFP, actually uses shaders behind the scenes (on shader capable cards). ;)may as well just bite the bullet and provide the flexibility people expectWhat is FFP and how does it handle lighting?I have one idea that would work, I could use semantics for some of the variables which the engine needs direct control of like lighting. That is how I remember 3DS Max interfaced with the shaders so I believe that would provide the most flexibility and ease of use over my other options.What do you think?   ;  FFP = fixed function pipeline.I wouldn't suggest going with the FFP because API's are starting to veer away from it. DX3D10+ no longer supports FFP (maybe emulated? Not sure).   ;Quote:Original post by CodaKillerWhat is FFP and how does it handle lighting?Fixed Function Pipeline. And it's pretty much dead as far as games are concerned, so going with shaders seem to be really the only choice unless you are making something exceedingly simple.You can't make a fixed-function path as advanced as any shader. If you can, then your shaders aren't doing anything interesting. Just encapsulate everything shader-related, then it won't look sloppy on the outside.   ;Quote:Original post by JroggyFFP = fixed function pipeline.I wouldn't suggest going with the FFP because API's are starting to veer away from it. DX3D10+ no longer supports FFP (maybe emulated? Not sure).I am using DirectX 10 and I was not talking about using the FFP I was talking about using a shader and only exposing key features to the engine.   ;  Lemme understand it: you're asking if you should use a single shader for all materials (and use the shader variables for parameters) or a separate shader for each material, right?   ;Quote:Original post by Sik_the_hedgehogLemme understand it: you're asking if you should use a single shader for all materials (and use the shader variables for parameters) or a separate shader for each material, right?Yeah exactly.   ;  Wouldn't different materials potentially require very different data streams? It could be difficult to write a one size fits all shader. The best approach to shaders & materials I've seen so far came from Yann L in this thread. Even though the thread is old, there are some cool ideas in there.   ;  Seems like you are using Lua, in this case you can use the __newindex meta method to add some syntactic sugar.Example:function Material()mat = {}-- init mat-- ...-- create a metatablemat.mt = {}mat.mt.__newindex = function (t,key,value)-- use the prefix to find out what function to callif (string.sub(key,1,2)=="tx") thenprint("set_texture(",key,",",value,")")-- set_texture(key,value)end-- and so on-- ...endsetmetatable(mat, mat.mt)return mat;endnow you can write something like:material = Material()material.txDiffuse =  "Data/Textures/Female.dds"the second line will call the __newindex meta method, you can use prefixes or type checks to figure out what method should be called then.   