Debug Draw with Cached Meshes & Vertex Shaders in Unity

This post is part of my Game Programming Series.

Complete source code for the debug draw utility and Unity scene for generating the demo animation above can be found on GitHub. Here is a shortcut to the debug draw utility class. And here is a shortcut to the shaders.

Motivation

I’ve recently started picking up Unity, and quickly found out that the only easily accessible debug draw function is Debug.DrawLine, unless I was mistaken (in which case please do let me know).

So I thought it was a good opportunity to familiarize myself with Unity’s environment and a great exercise to implement a debug draw utility that draws various primitives, including rectangles, boxes, spheres, cylinders, and capsules. This post is essentially a quick documentation of what I have done and problems I’ve encountered.

Continue reading

Posted in C#, Gamedev, Programming, Shader, Unity | Leave a comment

Timeslicing Batched Algorithms in Games

This post is part of my Game Programming Series.
The source files for generating the animations in this post are on GitHub.
本文之中文翻譯在此 (by Wayne Chen)

Timeslicing is a very useful technique to improve the performance of batched algorithms (multiple instances of the same algorithm): instead of running all instances of algorithms in a single frame, spread them across multiple frames.

For instance, if you have 100 NPCs in a game level, you typically don’t need to have every one of them make a decision in every single frame; having 50 NPCs make decisions in each frame would effectively reduce the decision performance overhead by 50%, 25 NPCs by 75%, and 20 NPCs by 80%.

Note that I said timeslicing the decisions, not the whole update logic of the NPCs. In every frame, we’d still want to animate every NPC, or at least the ones closer and more noticeable to the player, based on the latest decision. The extra animation layer can usually hide the slight latency in the timesliced decision layer.

Also bear in mind that I will not be discussing how to finish a single algorithm across multiple frames, which is another form of timeslicing that is not within the scope of this post. Rather, this post will focus on spreading multiple instances of the same algorithm across multiple frames, where each instance is small enough to fit in a single frame.

Such timeslicing technique applies to batched algorithms that are not hyper-sensitive to latency. If even a single frame of latency is critical to certain batched algorithms, it’s probably not a good idea to timeslice them.

In this post, I’d like to cover:

  • An example that involves running multiple instances of a simple algorithm in batch.
  • How to timeslice such batched algorithms.
  • A categorization for timeslicing based on the timing of input and output.
  • A sample implementation of a timeslicer utility class.
  • Finally, how threads can be brought into the mix.

Continue reading

Posted in C/C++, Gamedev, Programming | Leave a comment

Game Math: Curve Approximation via Curve “Projection”

This post is part of my Game Math Series.

Also, this post is part 2 of a series (part 1) leading up to a geometric interpretation of Fourier transform and spherical harmonics.

Drawing analogy from vector projection, we have seen what it means to “project” a curve onto another in the previous post. This time, we’ll see how to find a the closest vector on a plane via vector projection, and then we’ll see how it translates to finding the best approximation of a curve via curve “projection”. This handy analogy can help us take another step closer to a geometric interpretation of Fourier transform and spherical harmonics later.

Continue reading

Posted in Math | 3 Comments

Game Math: “Projecting” a Curve onto Another

This post is part of my Game Math Series.

Also, this post is part 1 of a series (part 2) leading up to a geometric interpretation of Fourier transform and spherical harmonics.

Fourier transform and spherical harmonics are mathematical tools that can be used to represent a function as a combination of periodic functions (functions that repeat themselves, like sine waves) of different frequencies. You can approximate a complex function by using a limited number of periodic functions at certain frequencies. Fourier transform is often used in audio processing to post-process signals as combination of sine waves of different frequencies, instead of single streams of sound waves. Spherical harmonics can be used to approximate baked ambient lights in game levels.

We’ll revisit these tools in later posts, so it’s okay if you’re still not clear how they can be of use at this point. First, let’s start somewhere more basic.

Continue reading

Posted in Math | 1 Comment

我的Uncharted 4開發雜記

Uncharted 4 logo

本文屬於My Career系列文

Here is the original English post.
本文之英文原文在此

註:為方便複製至PTT,本文排版採BBS格式,不習慣者請見諒

Uncharted 4已經發售,終於可以分享我負責開發的部分了
我主要是負責單人模式的夥伴AI、多人模式的戰友AI、還有一些遊戲邏輯
沒有收錄到最終遊戲的部分和一些瑣碎的細工我就略過不提

Continue reading

Posted in Gamedev | 19 Comments

A Brain Dump of What I Worked on for Uncharted 4

Uncharted 4 logo

This post is part of My Career Series.

本文之中文翻譯在此

Now that Uncharted 4 is released, I am able to talk about what I worked on for the project. I mostly worked on AI for single-player buddies and multiplayer sidekicks, as well as some gameplay logic. I’m leaving out things that never went in to the final game and some minor things that are too verbose to elaborate on. So here it goes:

Continue reading

Posted in Gamedev | 33 Comments

我的秘境之旅

本文屬於My Career系列文

Here is the original English post.
本文之英文原文在此

Continue reading

Posted in Gamedev | 6 Comments

My Uncharted Journey

This post is part of My Career Series.

本文之中文翻譯在此

Note: This post was written before Uncharted 4 went gold, so it might contain tones or implications that Uncharted 4 hasn’t gone gold yet. Sorry for the confusion.

I started working on Uncharted 4: A Thief’s End almost two years ago, and here we are, less than two months before release. This would be my first shipped title as a full-time game programmer (I shipped Planetary Annihilation during a summer internship). Looking back now, I realized that I’ve really come a long way since I first wanted to make games more than a decade ago. I would like to take this opportunity to write down this journey to share with you and as a note for myself.

Continue reading

Posted in Gamedev | Leave a comment

DigiPen: 我的遊戲學校

本文屬於My Career系列文

Here is the original English post.
本文之英文原文在此

Continue reading

Posted in Gamedev | 8 Comments

DigiPen: The Game School I Went To

This post is part of My Career Series.

本文之中文翻譯在此

Disclaimer: This post is all about my personal experience with DigiPen and is in no way intended to represent anyone else’s experience or opinions.

I went to DigiPen Institute of Technology to learn how to make games in 2011, and graduated last year (2014). I graduated one year earlier than my fellow classmates in the same year, because I transferred in some credits I had already earned at my previous college in Taiwan.

I have written one post about my life at DigiPen every year on a game design forum in Taiwan. Also, many of my DigiPen friends just graduated and have started their jobs in the game industry. So I thought, why not write a dedicated post about my experience at DigiPen in English on my blog?

Continue reading

Posted in Gamedev | 30 Comments