How would I fake lighting?

I’m making a orthographic isometric game, and I want to be able to edit lighting from the three directions of geometry you can see (top, left, and right). How could I do this, what type of shader would I need? I want to do this myself so could I just get instruction? Cheers! :slight_smile:

I’ve done some research and I’d like to rephrase my question. How could I give each face of my cube its own vertex so that I can hard color each face and it opposite face independently of the rest?

I would take a look at the free matcap shaders on the asset store. It’s very fast, view-direction-based fake lighting that is easy to customize. It comes with a few matcap textures, but it’s pretty straight-forward to make your own either with a matcap generator tool or simply by hand.

Not what I’m looking for. I would like a shader that will let me independently hard color each side of a cube so I fake lighting for my for a poly game easily. Pretty much make three surface lights, any ideas?

I don’t know how it’s done but it sounds like this shader asset fits the bill. It’s not free though

It sounds like a good situation to use vertex colours (which you can apply on your mesh procedurally) and a shader which will display those vertex colours.

pixpusher that is exactly what I was looking for, but I’m 16 and broke so buying something even as cheap as that isn’t a option. Is there a way I could make a dumbed down version that simulates three directional light shining on my geometry? With hard colors no blending.

Not sure this is what you’re looking for, but I did a simple shader in Shader Forge a while ago that takes a left, right, and top color and blends those based on a mesh’s normals. It’s only going to do “hard” colors on cubes, since those have normals that point 100% in each color’s direction, but if your geometry is cube-based, it could work.

I think it’s kosher to share the compiled output from Shader Forge, so I can post it if you’re interested.

This scene has no lights:

Here are the properties (I have an optional texture you can mix in, but I don’t remember why):

That is exactly what I’m looking for, may I have it?

Sure, here’s the .shader file:
https://dl.dropboxusercontent.com/u/28342849/Unity_misc/ShaderForge/DirectionalUnlitBlending.shader

You’ll probably get a warning, since you need the Shader Forge asset imported into your project to be able to edit it with Shader Forge, but I don’t think that should cause any issues. You can probably just remove the junk at the top to get rid of the Shader Forge data.

Once compiled, it’ll show up under “Shader Forge” in your shader list. You can change the source to make it something else.

Thanks man! How does it work?

@Dev-Undead are you asking what the logic is in the shader or how to use it?

The “meat” of it is really just this one line. It takes each color and multiplies it by one of the normal vector’s three coordinates, then multiplies all of those together. Super simple as shaders go and it’s probably overkill to use Shader Forge for it. The texture part of it I could probably just take out.

float3 emissive = (_Texture_var.rgb*((_LeftColor.rgbi.normalDir.r)+(_TopColor.rgbi.normalDir.g)+(_RightColor.rgb*i.normalDir.b)));

This value is set as the output pixel with an alpha of 1.0.

Is there a way I could color the opposite side as well? E.g. Top and bottom one color, left and right, front and back?

When I do (_Texture_var.rgb*((_LeftColor.rgbi.normalDir.r)+(_TopColor.rgbi.normalDir.g)+(_RightColor.rgb*i.normalDir.b))^2); it does both sides but messes up the color

Here’s one that works with all six sides. I used Shader Forge to create another input of the normal, inverted it, did the same sort of math with three new colors, then did a Blend with the Lighten option to combine everything. In the generated code, it used “saturate” for that. Seems to work!
https://dl.dropboxusercontent.com/u/28342849/Unity_misc/ShaderForge/SixColorlUnlitBlending.shader

You just need to do a lerp, and you’d want to do it in the vertex shader. There’s no point in doing per-pixel calculations on an interpolated normal.

Removed

Edit: Fixed normal scale and bias
Edit Again: Apparently, had a copy/paste malfunction that messed it all up. Should be right now.
Edit #3: Added scale by dot product for each axis. Should be working now, but no guarantees, exchanges, or refunds.
Edit #4: Still wrong, haha. I’m going to sit down and make sure it’s right before I post a new version.

1 Like

Since it’s the same normal value across the whole poly, yeah, that makes sense. :smile:

Yeah, you’d only want to do the math in the frag shader if you wanted to add a bump map to your object. Then, you’d have no choice but to do the interpolations after sampling the bump map texture.

@CaptainScience_1 your code works nicely but it messes up the colors. Ill look into finding a solution myself tho also this Screenshot - ee2006956656eadab3627a5a2014aa8d - Gyazo

Did you try my solution? The second shader? It’s not efficient, though I suspect optimizing such a simple shader isn’t necessary.