New Shading Model and Material System!

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 MODEwith 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:

        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,

	#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

                // 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
		// Return encoded version
	CG_GBUFFER pix(Vertex v)
                float3 Normal = CG_NORMALMAP(
                                      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!

Screen Space Reflections ( SSR ) – CONTINUED ( Aka Improvements )

So I’ve been working on my screen space reflections (SSR) and have been trying to eliminate artifacts. The next step will be the somehow make it more physically, because currently I just base the strength of the reflection linearly on the roughness ( sorta ).

Sponza Scene ( Yes, again ) ( Oh, and I decreased the intensity, although its configurable by the user, as the previous intensity was WAY too high ):
PS: Notice the weird line artifact below the arches, I still have to figure out what that is, including a few other artifacts. :). And I forgot to disable fog, so the colors are a bit dimmed down.
Posted Image
Posted Image
Posted ImagePosted Image
Another testing scene, the direction of the sun is very low on purpose to enhance the reflections. This is the scene WITHOUT SSR:
Posted Image
Posted Image
Posted Image
Posted Image
And, as always, that’s it!

Screen Space Reflections ( SSR ) – We must all accept yoshi_lol as our lord and true saviour!

So I finally got a basic implementation of Screen Space Reflections ( SSR ), aside from the fact that its screen space and some artifacts it’s actually ok. Now, you may wonder why the title is as following:

“We must all accept yoshi_lol as our lord and true saviour!”

I based my implementation on the article from Casual Effects:

However I was in trouble as there were a few conversion problems from GLSL -> HLSL, not the syntax conversion. So there yoshi_lol ( User from ) came, gave me his implementation and from there I saw how he converted it to D3D-HLSL. Thanks yoshi_lol! So now we must accept him as our true lord and saviour. :)


Screenshots! ( There are many artifacts, it’s a very early implementation, so there are many areas that look really messed up! )
Posted Image
Posted Image
Posted Image
Posted Image
And that’s about it!

Until next time! :)


This isn’t really a new big update, just me talking a bit and showing some pictures. :)

Well, as the title suggests I wanted to play with trees, to see how my shading model handles vegetation together with GI. Now aside from the performance as I’ve disabled any frustum culling, the performance is not too bad. However there’s still LOTS of work in the shading model of surfaces where light is guaranteed to pass through, so the images might be a bit weird…

There’s also a few problems with my volumetric lighting. Currently I find the vector between the world space position and the world space position of the pixel, but, if the ray is TOO long, then what? I know there’s some really nice research published by Intel that describes large scale outdoor volumetric lighting, however I’m not going to dive into that right now as it’s a lot of work.

So, as people want to see pictures, I give you pictures!

Posted Image
Now, for the fun of it, why not render 6000 trees!

Posted Image

Color Grading

So something I never got a basic implementation of was color grading, so today I decided to get a rough implementation. There’s still lots to work on, its based on the NVIDIA’s post complement sample (

Color Grading DISABLED vs ENABLED:
Posted Image
And that’s all, until next time! And enough about the damn white/gold/purple/brown/etc… dress!

Volumetric Lighting!

So one topic that we all hear over and over is VOLUMETRIC LIGHTING ( caps intended ). Why? Because its so damn awesome. Why not? Because it can get expensive depending on the hardware. So after countless of tries I scrapped the code I’ve been wanting to shoot then resurrect then shoot again and just wrote what made sense, and it worked!

The implementation is actually really simple, in simple terms I did it like this: ( I havent optimized it yet, E.g. I should do it all in light view space )

// Number of raymarches
steps = 50

// Get world space position
positionWS = GetPosition();

// Get world space position of the pixel
rayWS = GetWorldSpacePixelPos();

// Get ray between world space position and pixel world space pos
v = positionWS - rayWS;
vStep = v / steps;

color = 0,0,0
for i = 0 to steps
    rayWS += vStep;

    // Calculate view and proj space rayWS
    rayWSVS = ...
    rayWSPS = ...

    // Does this position recieve light?
    occlusion = GetShadowOcclusion(..., rayWSPS);

    // Do some fancy math about energy
    energy = ... * occlusion * ...

    color +=;

return color * gLightColor;

Results: ( Its not done yet )

Posted Image

Posted Image

Thats all! Until next time!

The beginning of particle simulation

Last Entry:

So I got a basic backbones of the simulation system up and running. The simulation happens in a compute shader, and everything just works out, which is great! :) So to test it out I put two point masses with low intensity a bit from eachother, and this was the result.
Next step will to be stretch the particles based on velocity for a fake like motion blur, and then allowing the particles to collide with the objects around them.

GIF: ( Its a bit large )

Until next time!