Material System
Posted
by
Towelie
on Game Development
See other posts from Game Development
or by Towelie
Published on 2013-06-24T21:32:59Z
Indexed on
2013/06/24
22:32 UTC
Read the original article
Hit count: 229
I'm designing Material/Shader System (target API DX10+ and may be OpenGL3+, now only DX10). I know, there was a lot of topics about this, but i can't find what i need.
I don't want to do some kind of compilation/parsing scripts in real-time.
So there some artist-created material, written at some analog of CG.
After it compiled to hlsl code and after to final shader.
Also there are some hard-coded ConstantBuffers
, like
cbuffer EveryFrameChanging
{
float4x4 matView;
float time;
float delta;
}
And shader use shared constant buffers to get parameters. For each mesh in the scene, getting needs and what it can give (normals, binormals etc.) and finding corresponding permutation of shader or calculating missing parts.
Also, during build calculating render states and the permutations or hash for this shader which later will be used for sorting or even giving the ID from 0 to ShaderCount
w/o gaps to it for sorting.
FinalShader
have only 1 technique and one pass.
After it for each Mesh setting some shader and it's good to render.
some pseudo code
SetConstantBuffer(ConstantBuffer::PerFrame);
foreach (shader in FinalShaders)
SetConstantBuffer(ConstantBuffer::PerShader, shader);
SetRenderState(shader);
foreach (mesh in shader.GetAllMeshes)
SetConstantBuffer(ConstantBuffer::PerMesh, mesh);
SetBuffers(mesh);
Draw();
class FinalShader
{
public:
UUID m_ID;
RenderState m_RenderState;
CBufferBindings m_BufferBindings;
}
But i have no idea how to create this CG language and do i really need it?
© Game Development or respective owner