Sign in to follow this  
Stellar Developer

Creating a Shader Class

Recommended Posts

I'd like to ask from someone who's already done this so I have less trouble creating mine. But im mostly confused about whether I should create a Shader class for each Type of shader I have, Or should I have a single Generic Shader class that can handle any type of shader. Good Advice is greatly appreciated! -Velik

Share this post


Link to post
Share on other sites
KEXIK    160
In my opinion it is best to do some basic wrapper to basic shader interface like ID3DXEffect (load shader, get technique handle, get parameters, set parameters, textures and so on) and then create something like MaterialManager which take care of shader loading, getting all semantics and setting common parameters like TIME, VIEW, PROJECTION, VIEWPROJECTION matrices (in DX you can use Pool to share it between several shaders). You can then create your own material format where you define which shader to use and which hard-entered parameters to set.

You can then use semantics like TextureLayer0, TextureLayer1, ... which will be set depending on rendered mesh textures.

That is how it works in our current engine...

Share this post


Link to post
Share on other sites
KEXIK    160
Or you can extend it and try to do something I want right now... inspired by UnrealEngine 3.

Split your shader to "template" and processing while processing will be lighting, shadowing, fog, ... based on material input (properties).

Shader template can looks like:
float3 GetDiffuse(SharedInput inp)
{
// here can be placed code generated from graphs based on level designer's needs,
// for example simple:
tex2D(sampler0, inp.coords0).xyz;
}

float GetOpacity(SharedInput inp)
{
return 1;
}

....

Then use these functions to get input for your processing maths.

Advantage of this is shared "processing part" and possibility to fill in template based on graphs, but main disadvantages are hard to implement, problems with interpolators (which coords to copy, which vert. data we need at template part).

With every material (filled in template) you must specify/know which parameters to set (which texture samplers are used, setting of samplers, which float params, ...) and there can be some processing code branches.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this