So as I've mentioned a few times already in previous blogs, my goal was to hit 65 in the homework questions. I finally hit that mark yesterday, and I believe I'm the second person to reach the cap after Gordon. It actually feels fantastic since now I don't have to worry about them anymore. I can just focus on getting things done for my other classes and working on GDW. Obviously my shadering adventures are far from over, but at the very least I don't have to stress over getting the homework questions done.
Anyways, this blog post is dedicated to my last week of shader homework questions, featuring particles. I finished last week at 53/65, so I needed 12 more points. I figured that since the easy particle question was at 4, and the medium one was still at 10, so getting those done would be ideal, especially since I want particles in our GDW game anyways, so might as well get it done.
I told Gordon that I wanted a photon particle system in our game. (Wikipedia)
So back in last semester, which totally feels like a trillion years ago by the way, I created a really simple particle system in SHFT. The most obvious particle effects that could be seen were the snow effects, but I also had particle effects for magic attacks when they dealt damage such as fireballs exploding and I also had particle effects for when enemies died. Overall it was pretty simple, every system was essentially the exact same, however the spawning position and velocity was slightly different.
The best looking one was the snow effect though. I was really proud of it because it was incredibly simple to make, and it looks pretty sick. In essence what I did was that I created a quad (alsanfoanf) above the world and told my program to randomly generate a position in that quad, and then randomly generate a velocity. With these two pieces of information I would just initialize a particle and then have it fall. The only two forces I had actually acting on it was a gravity and a wind force, and that was it. Simple. But it looked nice.
Our game looked pretty good back then.
In fact I was tutoring some people in Linear Algebra the other day (I'm a tutor working at the Academic Success Center and offer free tutoring in subjects such as Discrete Math, Linear Algebra and Programming through drop in hours on Tuesdays from 10 - 1 and by appointment 5 slots a week; you can book an appointment online at https://studentexperience.uoit.ca/home.htm.) and I asked them how I did my snow particles and they could pretty much figure it out too.
So now the problem was to figure out how to port it into shaders. Back in SHFT all the particles were done on the CPU which is lame, so I needed to figure out how to put it into the GPU. It turned out it wasn't even really that hard, you just had the same values, a velocity, position and acceleration and then you fed it a time value and using the awesome "P2 = P1 + V1t + 0.5At^2" formula the shader could automatically figure out where it would be. This only pretty much works with constant accelerations though, otherwise the particles jump around a bit. Same with changing velocity and position, since the formula assumes position, velocity and acceleration are constant and only time is changing
Random accelerations do weirdish things sometimes.
So that was essentially one question done. The next question would be the particle lighting question. At first I thought the question was having your particles be a light source so that they would light things up, so I did that. But apparently the question asked for the actual particles to be lit up. So I hacked up a really bad, really crappy, really ugly demo by the time class was over.
It was actually really bad. Like I feel bad for showing it to my prof, that's how bad it was. I was totally ready to just scrap it and do another question too but he ended up accepting it, which was great, but I still felt kind of bad. Honestly, most of the questions I've showed him did what it was supposed to do, but none of it looked very pretty. Most of it was pretty crappy looking, I'll try to fix that for next year, since I'm pretty sure we're going to be having these homework questions again for Game Engine.
This is a game engine right? How do I even program that. (Wikipedia)
Regardless, I'm done my homework questions for the semester. Moving on I'm probably just going to focus my programming efforts on stuff for my GDW game. I'll obviously be programming more shaders as well, but I don't know how much of it I'll be blogging about. Apparently people actually read my blog, what kind of programming related things do you want me to write about? Cause I could totally talk about anything. Even vaguely related stuff like the music I listen to when I program, random programming habits I have, etc etc.
Meh, back to particles. One of the requirements were to billboard particles, so I did some research on that and apparently it requires matrix or quaternion multiplication to rotate the particles so it always faced the camera. I have matrix and quaternion classes set up, but I figured it would be insanely expensive to do that for every particle, so I talked to the particle master Mirza and he said to use point sprites. So I did and my particles were billboarded. Simple.
But it also makes it not really look like snow.
Point sprites are pretty cool actually. Essentially you define a point and tell the program that the point is now a texture, and it textures it. Now instead of drawing four vertices for a quad, I send in one point. More efficient and it auto billboards, which is awesome, but it looks like the further back particles don't decrease in size relative to the scene. Gotta fix that. Also my frame rate. My code is so inefficient right now. Ugh.
My goal for particles is to have a better weather system though. We only had snow in SHFT last semester even though I made rain too (It looked terrible). The goal is to get more weather effects in this semester's game and to have random floaty particles in random places too, just because I can.
I took this picture randomly one day and wanted to use in a blog. Hope it's not too out of place here.
But yea, I need ideas for future blog posts. I can only blog so much about the stuff we talk about in class.