Jump to content

- - - - -

New Shading Model and Material System!


cuboid engine exams shading model material system
4: Adsense

PS: No screenshots this time, just me talking! Posted Image

I haven't really been active lately because of the glorious exams that are nearing me, but it's still nice to know that it's close to over ( At least this round ).

So as the title says, I've been working on a new shading model that tries to support all of the modern techniques. Now two features that I'm really excited about is anisotropic surfaces and subsurface scattering with direct light sources. However I still have to improve my implementation of the clearcoat shading, as I'm still missing some important ideas about it.

On the other hand I decided to rewrite my material system, which is the one that the user will write for his own custom surface shaders ( For meshes ). Now previously I did a ton of string parsing but honestly it's just unnecessary and it didn't give me the freedom I needed. So, I went full on BERSERK MODE with macros. Now it may not seem like there's much macro work, but there is Posted Image!. So I simply have a file full of macros, and when the user requests to load a material file, it simply pastes his code into the file ( Well after a bit of parsing the material file ) and compiles it as a shader.

Example material:
Input
{
        Texture2D g_tNormalMap,
	float3 g_f3Color = (0.7, 0.7, 0.7),
	float g_fSubsurfaceIntensity = 0,
	float g_fAnisotropicIntensity = 0,
	float g_fClearcoatIntensity = 0,
	float g_fMetallicIntensity = 0,
	float g_fSpecularIntensity = 0,
	float g_fRoughness = 0,
};

Shader 
{
	#set vert CG_VSHADER
	#set pix CG_PSHADER // I have a deep dark fear of "frag"
	
	// Basic VS -> PS Structure
	struct Vertex
	{
                // This is a must! In the future I'll allow him to create his entire own structure
                // as not much work is needed for it, but it still simplifies a lot of his work
		CG_VERTEXBASE

                // The user could pass any other variable he wanted here
	};
	
	Vertex vert(CG_ILAYOUT IN)
	{
		// Zero set vertex
		Vertex o = (Vertex)0;
		
		// Just let the engine process it, the user may do this on his own
                // but in usual cases he really doesnt want to
		CG_VSPROCESS(o, IN);
		
		// Return encoded version
		CG_VSRETURN(o);
	}
	
	CG_GBUFFER pix(Vertex v)
	{
                float3 Normal = CG_NORMALMAP(
                                      v.CG_NORMAL, 
                                      CG_SAMPLE(g_tNormalMap, v.CG_TEXCOORD)
                                );

                // the same can be done for parallax mapping or whatever the user desires

		// Set up the surface properties
		Surface surf;
		surf.diffuse = g_f3Color;
		surf.normal = Normal;
		surf.subsurface = g_fSubsurfaceIntensity;
		surf.specular = g_fSpecularIntensity;
		surf.roughness = g_fRoughness;
		surf.metallic = g_fMetallicIntensity;
		surf.anisotropic = g_fAnisotropicIntensity;
		surf.clearcoat = g_fClearcoatIntensity; // Doesnt work yet!
		
		// Return encoded version
		CG_PSRETURN(v, 	surf);
	}
};
And that's about it!
As always, until next time!

Apr 05 2015 08:25 PM

Very nice method.

Note: GameDev.net moderates comments.