Jump to content
  • Advertisement
Sign in to follow this  
CodaKiller

Fixed function materials vs Shaders for a game engine.

This topic is 3461 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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 = 1024
	GameWindow.height = 768
	GameWindow.maximize = false
	GameWindow.size = false







I 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.005
	Object:set_material_slot( 0, Material )







If you were using a game engine which method would you prefer, versatility vs ease of use?

Share this post


Link to post
Share on other sites
Advertisement
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

Share this post


Link to post
Share on other sites
Quote:
Original post by Matt_D
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


What 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?

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
Quote:
Original post by CodaKiller
What 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.

Share this post


Link to post
Share on other sites
Quote:
Original post by Jroggy
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).


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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
Quote:
Original post by Sik_the_hedgehog
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?


Yeah exactly.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 metatable
mat.mt = {}
mat.mt.__newindex =
function (t,key,value)
-- use the prefix to find out what function to call
if (string.sub(key,1,2)=="tx") then
print("set_texture(",key,",",value,")")
-- set_texture(key,value)
end
-- and so on
-- ...
end

setmetatable(mat, mat.mt)
return mat;
end



now 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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!