Okay, i reworked the whole shader system. Was a bunch of work but it's great now. Much easier as to use as long as you don't write custom renderning. Then you have to write 3 lines instead of one tongue

The engine now has only one default shader that will expand with the rest of the engine. It will be compiled on demand with the correct subshaders so it works for forward rendering as well as deferred rendering.

Here an example:

Click to reveal.. (Shader Source)

Code:
shader:add
{
	type = "global",
	source = 
[[
	// Transformation matrices
	uniform mat4 matWorld;
	uniform mat4 matView;
	uniform mat4 matProjection;

	// Mesh textures
	uniform sampler2D meshDiffuseTexture;
	uniform sampler2D meshSpecularTexture;
	uniform sampler2D meshEmissiveTexture;

	// Deferred renderer uniforms
	uniform sampler2D renderDiffuseLightBuffer;
	uniform sampler2D renderSpecularLightBuffer;

	// Material Values
	uniform vec4 mtlDiffuse;
	uniform vec4 mtlSpecular;
	uniform vec4 mtlEmissive;
	uniform float mtlEmissiveScale;
]]
}

shader:add
{
	type = "vertex",
	input = "mesh",
	source = 
[[
	out vec3 position;
	out vec3 normal;
	out vec3 tangent;
	out vec3 bitangent;
	out vec2 uv;
	out vec4 screenSpaceUV;

	void main()
	{
		vec4 pos = vec4(vertexPosition, 1);
		gl_Position = matProjection * matView * matWorld * pos;

		position = (matWorld * pos).xyz;

		mat3 mv3x3 = mat3(matWorld);
		normal = normalize(mv3x3 * vertexNormal);
		tangent = normalize(mv3x3 * vertexTangent);
		bitangent = normalize(mv3x3 * vertexBiTangent);

		uv = vertexUV;
		screenSpaceUV = gl_Position;
	}
]]
}

shader:add
{
	type = "fragment",
	source = 
[[
	layout(location = 0) out vec4 color;
	in vec2 uv;
	void main()
	{
		color = texture(meshDiffuseTexture, uv);
		if(color.a < 0.5f) discard;
	}
]]
}

shader:add
{
	type = "fragment",
	class = "DeferredRenderer",
	source = 
[[
	in vec2 uv;
	in vec4 screenSpaceUV;

	layout(location = 0) out vec4 color;

	void main()
	{
		vec4 diffuseColor = texture(meshDiffuseTexture, uv);
		vec3 specularColor = texture(meshSpecularTexture, uv).rgb;
		vec3 emissiveColor = texture(meshEmissiveTexture, uv).rgb;

		vec2 ss = 0.5f + 0.5f * screenSpaceUV.xy / screenSpaceUV.w;

		color.rgb = mtlDiffuse.rgb * diffuseColor.rgb * textureLod(renderDiffuseLightBuffer, ss, 0.0f).rgb;
		color.rgb += mtlSpecular.rgb * specularColor * textureLod(renderSpecularLightBuffer, ss, 0.0f).rgb;
	
		color.rgb += emissiveColor * mtlEmissiveScale * mtlEmissive.rgb;

		color.a = diffuseColor.a;
		if(color.a < 0.5f) discard;
	}
]]
}




As you can see, the shader defines two fragment shaders. One without a class. That's the default fragment shader that will be used.
To bind a shader, we use the Shader.Select method:
Code:
// Select the default shader:
CompiledShader cs = shader.Select();

// Bind it!
cs.Bind();



To bind the shader with the class, we use:
Code:
// Select the shader with class modifier:
CompiledShader cs = shader.Select("DeferredRenderer");
// Bind it (again)
cs.Bind();



But that's not all!
We can also override some subshaders if we want/need to.
Code:
// Create a custom fragment shader
var geometryPixelShader = new ShaderFragment(ShaderType.FragmentShader, geomPixSource);

// Select the shader with class and override the pixel shader.
CompiledShader cs = shader.Select("DeferredRenderer", geometryPixelShader);

// Should be known already
cs.Bind();


I'm using this functionality in the deferred renderer. Just provide any custom shader and my renderer can use it (if the output variables of the vertex/geometry/tesselation shader are right wink )

Oh, how do you load a shader?
Several possibilities: Using the AssetManager, create it in the engine with Shader.Load or even built it with CompiledShader and ShaderFragment.

I hope I could give some insight on how the new shader system works.

Don't hesitate to ask me some questions!

Regards
Felix


Visit my site: www.masterq32.de