Categories
Uncategorized

Shader with light support

Finished rewriting the normal map shader. Supports ambient, diffuse, specular, and emmisive. It’s pretty optimized. I feel good about learning but also upset that this should have been done 8 months ago by the original graphics programmer I hired. As I look around at samples, I realize he didn’t really write anything at all, but […]

Finished rewriting the normal map shader. Supports ambient, diffuse, specular, and emmisive.

3 lights

It’s pretty optimized.

I feel good about learning but also upset that this should have been done 8 months ago by the original graphics programmer I hired. As I look around at samples, I realize he didn’t really write anything at all, but copied from those samples and made some minor changes. The result didn’t support the features I asked for and was slow.

Last week I sent the shader to another company to optimize it. What I got for my $400 was something twice as fast but was buggy.

So I went over it myself today, fixed all the bugs, and made it twice as fast again.

Funny how I, with 2 months of training and no experience doing this, can beat a supposed lead programmer and an outsourcing game company in one day. Or maybe this isn’t a reflection of how good I am but how bad I am at picking competent people to work for me.

5 replies on “Shader with light support”

Which BRDF are you using? The top and bottom of the sphere appears much(!) too dark to look anything near realistic. Any chance to see the complete lighting shader?

Forgot half of the post…

> Finished rewriting the normal map shader. Supports ambient, diffuse,
> specular, and emmisive.
Is the specular term and normal mapping deactivated for the screenshot? I can see neither the first nor the second.

Without a BRDF there would be no lighting at all 😉 Even diffuse Lambert is a very simple BRDF (however, an ugly and crude approximation). So I guess you are using Lambert’s normal.lightDir for the diffuse component?

When you have a few minutes, try with Half Lambert:
float NdotL = dot(normal, lightDir);

float halfLambert = NdotL * 0.5 + 0.5;
float diffuse = halfLambert * halfLambert;
instead of:
float diffuse = NdotL;

Or you might want to try Wrap Lighting:
float diffuse = max(0.0, (NdotL + wrap) / (1.0 + wrap));

where “wrap” is an object-specfic parameter (for testing I would suggest comparing 0.2 to 0.8) and defines the amount of simulated subsurface scattering.

For more on this, drop me a line via mail 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *