Feed on
Posts
Comments

Category 'Programming'

Click the post title to be able to read and write comments.

I recently got the idea to try to create a procedural shader system for DirectX 11. This basically entails that one simply throws a mesh at the shader generator and it generates a customized shader for this mesh that suits it perfectly.
I knew it is being done in high-end game engines but I had no idea how one actually does it. I spent quite a lot of time on google trying to find this, but it basically looks like some universal secret even though it actually is quite simple. So I played around with it a bit and I managed to get it to work in the end. So the follow code snippet is the procedure I used for getting it to work, probably a whole load of other ones out there.
Just hope this saves other people the same frustrations I had for a while.

void GenerateShader()
{
        ostringstream shader;

        // Basic Vertex Shader
	shader << "float4 BasicVS( float4 Pos : POSITION ) : SV_POSITION" << endl;
	shader << "{" << endl;
	shader << "	return Pos;" << endl;
	shader << "}" << endl;

        // Basic Pixel Shader
	shader << "float4 BasicPS( float4 Pos : SV_POSITION ) : SV_Target" << endl;
	shader <<"{" << endl;
	shader <<"	return float4( 1.0f, 1.0f, 1.0f, 1.0f );" << endl;
	shader <<"}" << endl;

        // A standard DirectX 10 technique
	shader << "technique10 DefaultTechnique" << endl;
	shader << "{" << endl;
	shader << "	pass p0" << endl;
	shader << "	{" << endl;
	shader << "		SetGeometryShader(NULL);" << endl;
	shader << "		SetVertexShader(CompileShader(vs_4_0, BasicVS()));" << endl;
	shader << "		SetPixelShader(CompileShader(ps_4_0, BasicPS()));" << endl;
	shader << "	}" << endl;
	shader << "}" << endl;         

        // This is where the "magic" is at. Grab the char* from your stringstream
        // and feed it into D3DCompile() along with whatever other parameters you usually send it.
        ID3DBlob* errorBlob;
        unsigned int shaderSize = shader.str().size() * sizeof(char);
        HRESULT hr = D3DCompile(shader.str().c_str(), shaderSize, "none", 0, 0, "DefaultTechnique",
                                          "fx_4_0", D3D10_SHADER_ENABLE_STRICTNESS, 0, &blob_, &errorBlob);
	if( FAILED(hr) )
        {
                OutputDebugStringA( (char*)errorBlob->GetBufferPointer() );
	}
	SAFE_RELEASE( errorBlob );
}

So now all that is left is 99.9% of the work to actually switch case together a shader that supports all the things your different meshes might need.
Maybe I will post something on that later when I manage to make a dent in that daunting task :p

I implemented this during a weekend, mostly because relief mapping has always interested me. Decided to toss in parallax mapping as well when I was “in the neighborhood”, and a little normal mapping for good measure as well. This is the basic implementation of both techniques with no optimizations or artifact corrections.

Here is a small code snippet. Nothing special, just don’t like to not show code.

float ray_intersect_relief(in float2 orig, in float2 dir)
{
    const float max_num_linear_steps = 20;
    const float max_num_binary_steps = 5;
    float depth = 0.0f;
    float size = 1.0f / max_num_linear_steps;
// Attempt to find the first intersection against the relief map with a linear search.
    // This is because binary search can easily miss topography.
    for(int i = 0; i < max_num_linear_steps - 1; i++)
    {
        float4 t = gTexRelief.Sample(textureSampler, orig + dir * depth);
        if(depth < t.r)
            depth += size;
    }
     // A binary search to try and find the "edge" of the closest intersection point
    for(int j = 0; j < max_num_binary_steps; j++)
    {
        size *= 0.5f;
        float4 t = gTexRelief.Sample(textureSampler, orig + dir * depth);
        if(depth < t.r)
            depth += 2*size;
        depth -= size;
    }
    return depth;
}

So… It’s been a while.

Life is good, excluding the torment of a dying molar, and not a whole lot has happened in this time of silence. Work has been good, but has not really been related to what I wanted to write about in this blog so I opted to stay quiet for a while.

Lately I started looking at available positions in various game companies and it was somewhat upsetting to notice that you are not really suited for filling any position other than as a junior. So I basically decided that I really needed to do something about my portfolio. It was a while back that I decided this, but there was Christmas and stuff in the way so I haven’t really started doing stuff until now. Now it has begun though.

The general idea is that I will simply implement all the various things I have always wanted to try and then post the results in the portfolio section (hopefully with some binaries as well). The types of thing I will be implementing will mostly be 3D graphics related, since this is the area I always seem to find myself drooling over. But there will also be some other stuff like resource management and so on.

I have already implemented the first thing I will be putting on the portfolio (relief mapping) and it will be going up there shortly (probably not today though). Other things to be expected, in the very near future, are things like, just to name a few: Parallax mapping, Screen Space Ambient Occlusion, Deferred rendering.

If one refuses to work for any other industry one can only blame themselves for not doing everything in their power to be worthy of working there.

Lots of changes

Yeah so I went to the job meeting. 15 minutes into the meeting I got the job! So I am now a full time employee ( for 6 months at least ) at the xDelia project as a game programmer.

I start tomorrow already, so it is going a million miles an hour at the moment. I am headed over to Germany, Tuesday – Thursday, next week for some work related workshop as well. So lots of things happening indeed.

So now there’s lots to do. I need to fill out some papers for the educational part of school and report that I am taking a leave of absence. Then of course there is also contract signing and all matter of other stuff I need to fix with the job (have to hunt down a computer for my room, and then of course have someone tell me where my room is). Not to mention having to report to CSN my leave of absence as well so they’ll stop sending me money, but for some reason you need to know how much you will earn, which I don’t know yet, before you are allowed to report a leave of absence. Seems kind of silly to me.

Now this is the story all about how
My life got flipped, turned upside down

Kinda how it feels. This will pretty much change everything I was doing. No more school for a while of course and iPhone coding will be put on the back-burner again. It is, however, all good. I get what I value most. Experience. With the economy as it is there is no way in Helsinki that any game company would hire someone that has no prior work experience. So this job will be worth a lot for my CV. Hopefully it will be for at least a year. Generally looks better in the resumé than 6 months, I say anyway.

So who’s turn is it next now then from Quantum Studios?

Networking Done

The UDP networking is now done for my Freevo remote app, tested it with my Freevo server earlier and it works perfectly. Just have to finish up the Settings tab, which will most likely be done today, so that one can specify what host and port it should connect to and stuff like that. Then it’s just the final icons and intensive bug testing and tweaking left to do. Making this app has been a great help in putting the stuff I have learned in the book into practice.

So school starts again tomorrow. Or well not really. I’m just going to talk to someone about what courses I decided on for my master’s education (since you get to pick 90% of the curriculum yourself). The courses don’t actually start until Tuesday. Will be nice to start meeting other people again, rather than sitting here cooped up in Karlskrona with nobody we know.

The Results of The Day

Two posts in one day? What the hamburger?!

Who knows? It sure is strange.

However! I just wanted to show the progress I have made today. Worked most of the day on this thing, or well not just the app. The thing is that I needed a Tab Bar for the app, so of course I had to actually learn how to make Tab Bars. So that’s where half the time went.

Anywho, I have the general layout pegged down now. So now I just have to get the actual networking part working again, since I had to refactor the code quite a bit which resulted in nothing working anymore, but that is tomorrow’s project.

Before I end this I just want to show some screenshots of the app. It doesn’t look like much, because it isn’t much. At least it is something though, progress.

IMG_0085 IMG_0086 IMG_0087 IMG_0088 .

The “Settings” tab doesn’t show much you might say. I, however, claim that it says “POTENTIAL”!

Art update

So I found some artists to help me out with my apps. Andreas Nilsson is making some icons for the Freevo remote app. Rasmus Welin is learning how to make sprite characters for the usage in the JRPG I mentioned previously. So now I just have to get out of procrastination mode and continue work on the apps.
Starting the Masters education on Monday at BTH, so I don’t know how much time there will be for programming on these things during the week, but there’s always the weekends.

The Battle Plan

So I have decided what my big iPhone game down the road will be. It will be a jrpg styled game, like all the “Tales of” games.

This decision came after buying a game, which is similar in concept, from the app store. People were raving about how perfect and wonderful this game was etc etc.

It didn’t take long to realize that people have really low standards to when it comes to games on the iPhone. Sure it isn’t a super powerful platform for games in the first place, but the products should still be held at a high standard. It lacked lots of sound effects, dialogs made no sense, made lots of contemporary comments which ruined the atmosphere (gangster rap in a medieval fantasy setting doesn’t make sense now does it?), worthless controls, annoying background music. The list just goes on and on and still almost all of those which have commented on this game gave the score 5/5.

So that was when I decided that a jrpg is what I would, to show people how a proper game should be like on the iPhone. This will probably be years in the making, but I have time.

iPhone progress

So I’ve started getting more proficient with the workings of Objective-C and have made a prototype of my first app, iFreeMote. It is just a simple remote control app for the multimedia application Freevo (play, fast forward, pause, etc). I decided on this as my first app partially because it is so easy, but mainly because using the already available web interface for freevo remote works very poorly in safari on the iPhone. So even if there would be no public interest in the app I would still use it everyday. If anyone of you feel proficient with making snazzy icons, send me a message. Really need some proper icons for the final layout of this app.
What ya think?

iPhone ahoy!

Yeah. So I finally started reading the iPhone book the other day. So far I have learned a whole bunch of cool stuff when it comes to making graphical interfaces and I must say that it was easier and more streamlined than I thought it would be.

So soon maybe I am qualified to make my first in-game menu for a game ;)

Check back soon for more about my progress, if it pleases you!

Older Posts »