I moved to a new URL! Check it out!

Dev Log: Shader Experiments

Dev Log: Shader Experiments
Since my break to work on the remaining bits of Otter I haven't really fallen back into the groove on working on my big game project yet. Yesterday I dedicated the day to playing around with shaders since I'm really interested in using them for all kinds of cool visual effects.

Image


This is what I ended up coming up with at the end of the day. First I was playing around with gradient maps for recoloring an image, and then I started to mess with displacement to make cool waves in the image. Finally I wanted to experiment with having a render texture that could be passed to the shader for dynamic effects.

Basically how this little program works is that there is the static image with a shader loaded. Then there's a Surface object that can be painted on with the mouse. The shader uses the texture from that Surface to affect the image in different ways.

Here's the full C# source:
using Otter;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ShaderTesting {
class Program {
static void Main(string[] args) {
var image = new Image("pic.jpg");
var game = new Game("ShaderZ", image.Width, image.Height);

game.FirstScene = new TestScene();

game.Start();
}
}

class TestScene : Scene {

Image image = new Image("pic.jpg");
Image circle = new Image("circle.png");
Surface distortion;

public TestScene() {
AddGraphic(image);
distortion = new Surface(image.Width, image.Height);
circle.CenterOrigin();
circle.Blend = BlendMode.Add;
AddGraphic(distortion);
circle.Alpha = 0.1f;
distortion.Visible = false;
distortion.AutoClear = false;
}

public override void Update() {
base.Update();

if (Timer % 30 == 0) {
try {
image.Shader = new Shader("../../shader.frag");
}
catch(Exception e) {
Console.WriteLine("Shader error:");
Console.WriteLine(e.Message);
}
image.Shader.SetParameter("gradient", new Texture("gradient.png"));
}
if (Input.MouseButtonPressed(MouseButton.Right)) {
distortion.Clear();
}
image.Shader.SetParameter("time", Timer);
image.Shader.SetParameter("distortion", distortion.Texture);
image.Shader.SetParameter("offset", Util.SinScale(Timer, 0, 1));

if (Input.MouseButtonDown(MouseButton.Left)) {
Draw.SetTarget(distortion);
Draw.Graphic(circle, MouseX, image.Height - MouseY);
Draw.ResetTarget();
}
}

public override void Render() {
base.Render();

Draw.Circle(MouseX - 15, MouseY - 15, 30, Color.None, Color.Red, 2);
}
}
}

And the GLSL shader source:
sampler2D texture;
sampler2D gradient;
sampler2D distortion;
uniform float offset;
uniform float time;
uniform float mixfactor;

void main() {
vec2 pos = gl_TexCoord[0];
vec2 distortColor = texture2D(distortion, pos);
pos.x += distortColor.r * (sin(time * 0.1 + pos.x * 10) * 0.05);
pos.y -= distortColor.g * (cos(time * 0.1 + pos.y * 10) * 0.05);
vec4 color = texture2D(texture, pos);

float gray = (color.r + color.g + color.b) / 3;

vec4 gradientColor = texture2D(gradient, vec2(gray, offset));

gl_FragColor = mix(color, gradientColor, distortColor.r + distortColor.g);
}

You can download everything here. Note that you'll have to give it a reference to Otter to compile and run it yourself.

Doodle Post

Image

More Otter Updates

More Otter Updates
I've gotten myself into the bad habit of procrastinating on my game project by working on Otter some more!

I just pushed another wave of updates on the journey to the big 1.0.0.

* Text and RichText's rendering positions have been changed. The default origin will now be the top left most position of any text, instead of allowing for "bleed." This should make it simpler to deal with.

* The Tilemap class got a few updates including a performance boost for clearing tiles, and a final pass on tile layers. Everything in the Tilemap class should now be usable as intended.

* Documentation fixes and updates across the board.

* Debugger has been updated to adjust for the Text updates.

So at this point I think the only thing that's left is fixing whatever bugs come up. So if you hit any bugs in any point in Otter then please let me know on the forums!

Otter Updates

Otter Updates
Things are moving along for Otter, my SFML.Net based game making framework!

I pushed a lot of changes this week that is bringing it closer to the big version 1.0. I overhauled a lot of the code in the Graphics classes, fixed some bugs, and updated all of the documentation for mostly everything. I also went through and cleaned up a lot of the code and organized it into nifty regions.

Right now my plan is to just keep testing things for awhile yet to make sure there's no crazy show-stopping bugs before I publicly announce to the world that it's officially version 1.0. Some of my recent changes have not been tested that thoroughly yet, and there have been a few bug reports popping up that I've been fixing up, so I can only imagine there are more bugs lurking in the shadows.

As far as sprite batching goes, I decided that I'm holding off on official sprite batching support until after version 1.0. There is some stuff set up in the back end of things to turn on sprite batching, but there are a handful of bugs that need to be resolved first and I don't think I'm going to be able to get them squished quickly enough. Aside from that, my performance tests seem to indicate that sprite batching isn't really that helpful anyway.

If you're using Otter and encounter any bugs, you can let me know on the forums or directly on the BitBucket issue tracker.

Doodle Post

Image

Doodle Post

Image