Original Post
Hi, I am currently working on a shader/material system (based on OpenGL) similar to the Effects Files (.fx) of DirectX. My shader files are based on XML and look like this: This is a shader with one pass and one texture stage. $T1 and $M2 are variables, that can be set from within the application. For example: So the previous shader would be executed as (some pseudo code): First at all: What do you think? Is this system flexible enough? Especially I don't really know if it's a problem, that every parameter can have only one value. That's why I have to split the glBlendFunc parameters into to parts. Would something like this be better? But here I've got special cases for all the OpenGL functions that have more than one parameter... Future support for pixel/vertex programs is planned, and should look like this: One more question: should a shader "unload" itself on exit? So should it change the states to some predefined values? Pro: outside a shader I do always have the same environment, so I could draw something outside a shader without checking every state, whether it has the correct value or not. Contra: This results in heavy state changing, especially when using the same shader twice, because at first the shader is unloaded and then loaded again. I think it would be better to provide some "standard shader", that you can load, for rendering "without a shader" (or avoid this at all). Opinions? Ideas? Suggestions for improvement? thx, fallen
<shaderfile version="0.1">
<shader name="test">
<pass>
<stage>
<texture name="$T1" />
<state name="BLEND" value="true" />
<parameter name="BLENDFUNC_SRC" value="SRC_ALPHA" />
<parameter name="BLENDFUNC_DEST" value="ONE" />
</stage>
</pass>
<world matrix="$M1" />
</shader>
</shaderfile>
shader.setTexture("T1", myTexture);
shader.setMatrix("M1", worldMatrix);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, loadTex(M1));
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
drawMe();
<parameter name="BLENDFUNC" src="SRC_ALPHA" dest="ONE" />
<shader name="test2">
<pass>
...
<program type="vertex">
// some vertex program here
</program>
</pass>
</shader>