Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Topics - PixelPiledriver
Pages: 1 2 [3]

General Discussion / Pixel Shaders
« on: May 21, 2012, 10:15:16 pm »
The purpose of a Pixel Shader is to control the color of a rendered pixel.
Read this if you are unfamiliar with the topic.

I've taken interest in writing a 2D lighting Shader.

Lighting depends on many variables.
But as a massive simplification it depends on 2.
Surface direction (normal) and light source position:

In 3D art getting a normal is easy.
The data is already there as it is essential to how it is rendered.
But 2D art is different.
Altho we can find the normal of certain pixels, like the outer edges, there is no "physical" axis.
Surface normals are created by the artist and kept consistent only by choice.
It's exactly this sort of constructed fakeness that keeps me interested in art.
My purpose is not to replace per pixel artistic decisions of color.
It is to add another layer of control to a sprite that is interactive in a game engine.

We can represent direction as a color.
This is commonly thought of as Normal Mapping.
We can use an extra map to light a 2D image.

So first I had to figure out what kind of axis to pull data from.
I started with a 2-axis format:

This had some appealing results (which are lost, forgot to take screenshots), but I felt the control was a little off.

Then I tried using a quadrant method using the Blue channel to determine quadrant.

The idea was to make it easier to find direction.
But I found the setup annoying to work with and abandoned it pretty quickly.

Having a third access could remove the need for quadrants.
My first thought was to use this 3-axis setup:

It reminds me of Barycentric Coordinates and therefore has some interesting properties.
It could have worked but I tried to look for other answers.

Then I came to this 3-axis setup:

It has direction and matches how we traditionally think of a 3D axis making it easier to think about and use.
This is what I'm using now, and it works well.

So here's the progression of getting the base code to work.
I'm writing this from scratch and tweaking it to my needs.
The light source was from the mouse position so I could move it around and see changes quickly.
Old stuff and mistakes towards the top, new stuff and properly working towards the bottom.

The idea is to draw a normal map by hand.
Reducing the number of colors makes surface direction more apparent.
It's easier to grab from and stay consistent.

Manually drawing the normal map, such as the "brick" pattern on the sphere, in theory seems crazy.
But it ends up having really interesting and appealing results despite the fact that its a normal map defined with solid color lines.

Here's some more test results using a sprite and 3 different types of normal map:

Using multiple spheres for normals creates a crapload of distortion, but it's quick and easy to setup.
The last row is starting to actually look decent, even though it uses the multi-sphere normal map.
It's a bit too subtle but its also much more noticeable and cool when it happens in realtime and changes based on position.

Manually painting the normals has much more potential (and is my original goal of coding this) but I have not yet taken the time to make a really nice map.
That'll be my next test, probably on something static.
Obviously it's less expensive to use on static assets but is still doable for animations.

There's still a lot of work to do.
Even if you're not a programmer feel free to comment.
It could lead to a much better shader or other features.

Challenges & Activities / The Photopalette Activity Thread!
« on: May 06, 2012, 04:18:05 am »
In an effort to break away from how I usually start an image I came up with an exercise.

Go to Google.
Find a photo or image:

Drop it into GraphicsGale.
Reduce to 16 colors:

Whatever colors you are dealt, use them.
Even if they are not the best colors that's what you get to work with.

The idea is that if the image you found is still legible after being reduced, and almost always is, then infinite legible images could be created from the same colors.

So I started out with something really plain:

And then just continued to work with it.

I've even cheated a bit.
I added 3 or 4 colors and kicked some out.
Here the current color pal is at 15 colors:

A trick to it is that the image is not actually "random".
You yourself get to choose the image, so you can effectively choose your color range.
Choose an image with people and you're bound to get some skin tones.
Choose an image with more reds and yellows if that's what you want to work with.
Choose an image with high or low contrast.

The element of surprise comes when you reduce to 16 colors.
The balance is not always what you expect.
Of course if the colors are really unappealing to you just go find a different image.

I'm kind of back and forth about the strictness of the exercise right now.
Obviously these colors aren't the brightest, but then again the idea was to use what I was given.
But I've added some, so why not just change them all?
Or just add another 16 on top so that the current dim colors will make the new ones shine even brighter.
But what about a 16 color limit?
Well... hmmm...
I'll have to create a series of rule sets in the future, ranging from extremely strict to extremely flexible.

Basically it boils down to this.
The more rules you follow, the more it's like a game.
But the less rules you follow, the more its like a process tool.
The choice is yours.
Both degrees are beneficial exercises.

The original palette can also be seen as a base.
Since I've already cheated some, here I've added colors and changed the contrast/brightness.
At this point I'm up to 24 colors:

This is about 6 hours work (yes I'm super slow).
There's plenty of messy areas and things that could be changed.
I plan on dropping in some more to finish it off.
Crits and edits are welcome of course.

Ideally you should post:
1. The photo
2. Reduced photo with original palette
3. Current palette
4. Your art!

If you get some time try it yourself!
It's an interesting exercise.

Kind of a silly character:

The grayscale reveals that she is VERY mid key.
I was tricked into thinking she had wider range by leaving in the black outlines for so long.
Once I swapped them for colored line all of the lows disappeared.

Also on my laptop monitor her colors are terribly blown out in blue.
But my 2nd monitor she is completely readable.
I'll have to find some compromise.

After some more passes if I get the time I'll do some animations.
Of what?
Piledriving robots into the ground of course.

Pages: 1 2 [3]