Friday, August 9, 2013

With 4 minutes to spare, I reached my goal of 20 project Euler problems in different languages in 24 hours. I learned a lot of languages, some real, some not so real - but overall this was very fun, and I may try to extend this challenge to more (esoteric) language over longer stretches of time.

Starlight2 can now properly construct a legal (but stupid) random ship from an image. Now it is time to interact with other ships, initially in combat. The time alotted for this is specifically 75 minutes, since the jam ends at 3pm today.

A Randomly-Constructed Ship

Build GUI infrastructure for popup ship windows (equivalent to the main view in a traditional RTS)

Window render

Window draw

Window resize

Window close

Zoom control

Ship View inside the popup windows

Draw ships (with zoom and pan)

Show modules as plain hexagons

Right-mouse pans view inside of a window

Render module icons

Find the module under a mouse

Draw main view that shows a "realistic" universe (equivalent to a minimap in a traditional RTS)

Integrate starfield prototype

Overlay GUI

Show ships

Show free modules

Draw paths

Main view interaction

Zoom control

Right mouse pans

Support selection of ships

Provide waypoint GUI

Warp-drive

Modules & interaction

Make hexification symmetric

Drag within ship

Drag outside ship

Drag inside ship

Click to activate module

Target modules in other ships

Simulation

Compute dynamic commodities, e.g., heat, power, etc.

Simulate attacks

Trading (needs more GUI)

Polish graphics

Starfield background pan and zoom

Per-user color

GUI stylization: bloom, noise, ripple on hit

Re-coloring of ships

Clip module view to the actual window bounds

Polish UI

Clip the mouse to the window when panning, or hide the mouse and allow it to go outside

After a sleep that did not last long enough, I quickly refactored my code to compute and store only the form factors for a single patch at a time (which requires O(n) space as opposed to the old O(n^2)). This slows down computation, since we have to recompute form factors every bounce, but makes large scenes able to not take over my entire hard drive.

I then spent some time fixing bugs and debugging scenes. Note to everyone: Dabrovic Sponza has pretty awful tesselation, don't use it at all possible. But anyway, I changed one of the doors in Dabrovic Sponza to emit lots of light and let my radiosity solver run on a course tesselation for a few dozen seconds (it did direct + some of the first bounce indirect in that time frame), giving me:

I'm going to try on Crytek Sponza; then profile and do the easiest optimizations possible before 3. But I ran radiosity on Sponza and had a soft lighting image in <1 minute; so I win!

7 left, with 4 languages I really know left.
One lesson I have learned in the recent problems: I used up J far too early.
Anyway, now I am more so in "learn cool/interesting/reasonable language" mode than the "do crazy things" mode, on account of time...but Shakespeare and INTERCAL are still in my mind for future use if I get my 20 done.

Problem 11: PHP

Find the largest product of 4 adjacent numbers in a 20x20 grid

This wasn't too bad, other than PHP being hard to debug and me forgetting to put $'s on array indices.

I've been working on the programmatic design for the elements of the ship. Modules consist of up to seven hexagonal Features, themselves arranged in a hexagonal shape. Features have no variable state beyond their identification (i.e., they are enumerated values). Modules are randomly instantiated into the universe and are indivisible once instantiated. They can be damaged and torn/ejected/blasted from ships (and repaired), but can't be fragmented.

A module generates a mask for itself that is used for rendering borders and other effects. Because modules are rendered in computer-display style, it is appropriate that damaged modules use the mask to render "television static" noise patterns over themselves, as if the signal were breaking down.

Features are represented by icons. There is a generic, useless Feature (let's call it CORRIDOR) that dilutes the value of a Module. Some compound Features, such as ARMORED_THRUSTER, disproportionally enhance the value of the Module containing them.

Weapons can only target border tiles in a ship, so there is an advantage to packing them tightly and using armor on the periphery (this is intentionally analogous to walls in RTS games).

Some features have area effects, such as SHIELD and CLOAK generators. One must use multiple instances to cover a large ship.

It is raining quite hard. Several motorists do not understand correct etiquite/legally required maneuvers at crosswalks, such as pausing their headlong rush to a damp collision-induced grave long enough to admit a pedestrian to cross, much less not drenching said pedestrian as they hurtle past unminding and, quite likely, unconscious in any higher-order neural sense. Nonetheless, I reached lab without (new) physical injury.

Pan and zoom work on the world map and in ship windows. I had to add some extra hooks to G3D to support processing mouse events directly on a GuiWindow. Usually we process events on GuiControls instead, so this case had never occured before.

Build GUI infrastructure for popup ship windows (equivalent to the main view in a traditional RTS)

Window render

Window draw

Window resize

Window close

Zoom control

Ship View inside the popup windows

Draw ships (with zoom and pan)

Show modules as plain hexagons

Right-mouse pans view inside of a window

Find the module under a mouse

Draw module icons

Draw main view that shows a "realistic" universe (equivalent to a minimap in a traditional RTS)

Integrate starfield prototype

Overlay GUI

Show ships

Show free modules

Draw paths

Main view interaction

Zoom control

Right mouse pans

Support selection of ships

Provide waypoint GUI

Warp-drive

Modules & interaction

Make hexification symmetric

Drag within ship

Drag outside ship

Drag inside ship

Click to activate module

Target modules in other ships

Simulation

Compute dynamic commodities, e.g., heat, power, etc.

Simulate attacks

Trading (needs more GUI)

Polish graphics

Starfield background pan and zoom

Per-user color

GUI stylization: bloom, noise, ripple on hit

Re-coloring of ships

Clip module view to the actual window bounds

Polish UI

Clip the mouse to the window when panning, or hide the mouse and allow it to go outside

I modified G3D so that it supports vertex colors throughout the system, and by default uses them to add to the ambient light.

Then I made a mapping from vertices to their adjacent patches, and every time I iterate on radiosity I replace the color at a given vertex with a simple average.

Lots left to do, not the least of which is checking the radiometry. But first I'll continually run it while moving the light source to get a nice video, but then I need to modify the algorithm to allow me to load Sponza. Right now I'm taking the easy way out and computing the form factors for all pairs of patches in advance. This is n^2, so on scenes with a million triangles, this takes 4 TB of space... If I switch to only storing all the form factors for one patch at a time I can reign this in to be reasonable.

Thursday, August 8, 2013

so i took a little break but have gotten back to work. I have got the basic lambertian shading finished and have done a good deal of optimizations to decrease the time within the inner loop. After profiling i can say that the greatest amount of time is being used to make up for my sloppy way of making sure that my rasterizer can render from any camera position. I pretty much just translate everything into the cameras space at each step. As the render is now it cannot truly render cornell box in real time but is not to far off. Here is a video, while it may seem that it is rendering really fast, that is just the magic of the g3d recorder that takes the video and makes it 30 frames a second.

I will probably work a little bit longer tonight and then get some sleep and get ready for a hard day of coding tomorrow in my attempt to reach real-time. If i fix up the sloppy coordinate conversions and add a better algorithm to determine pixel coverage i should be able to achieve real time.

Some more problems done...now my problems aren't dealing with ridiculous languages, its dealing with the whiplash from changing languages so quickly and getting confused on basic syntax for that reason, and more mundane issues...such as using floor instead of ceiling in my solution for #10, which let one perfect square slip into a list of all primes < 2000000.

So I spent the morning and a portion of the afternoon reading different sources on radiosity and implementing a new feature in G3D: automatic subdivision of triangles until a threshold edge length is met by all edges. See it here on the Cornell Box with a threshold of 0.45 meters (all edges are less than that).

The next thing I worked on was the "form factor" part of the radiosity algorithm (described here). It basically describes the fraction of energy that leaves one patch of surface and arrives at another, given that the energy scatters diffusely. I treat each triangle in the scene as a patch, and compute form factors between all patches. I then multiply the form factor by the visibility function (which I treat as 1 or 0 for now, depending on whether the center of the patches are visible from each other. To get more accurate results, I can either subdivide the triangles more or implement a stochastic approximation of visibility.

Anyway, I can visualize the form factors for any given patch. I diplay the patch values as GL_POINTS in the center of the patch. The red dot is the center of the patch I am currently visualizing the form factors for, and the other dots represent the magnitude of the form factor for the other patches paired with the selected patch. Brighter means higher form factors.

Note the values aren't purely form factors, I also combine with visibility before display: see how the back left is all black where the tall box blocks the line-of-sight to the red patch.

Finally, I actually implemented radiosity... I chose a progressive variant that evaluates a bounce at a time.

Here's a gif of 0-3 bounce illumination using this technique (displayed in the same way as the form factors... as GL_POINTS at the center of the patches).

You can see it starts out with almost everything black (besides a few patches in the top at the emitter, which are hard to see over the bloom of the direct light). The first bounce is direct illumination, and illuminates most areas (though not those in direct shadow. After the next bounce, you can start to see color bleeding on the sides of the boxes.

Next up: pushing the radiosity values out to vertices and doing a full render.

We broke for pizza and then reconvened to hack some more. My iPod died--it had been playing for 12 hours straight! Here's the current rendering of Starlight2:

Ships in the starfield and popup GUI windows for inspecting them

The hexification isn't properly centered, but first I want to take on getting panning working correctly on the ship and main views to help with debugging. My task list, with completed items in green, is below.

Build GUI infrastructure for popup ship windows (equivalent to the main view in a traditional RTS)

Window render

Window draw

Window resize

Window close

Zoom control

Ship View inside the popup windows

Draw ships (with zoom and pan)

Show modules as plain hexagons

Left mouse selects, drags, and activates module

Right-mouse pans view inside of a window

Icon modules

Draw main view that shows a "realistic" universe (equivalent to a minimap in a traditional RTS)

3 more problems down...one was in Ruby, which was easy/fun enough, one in Whenever, which is a ridiculous language except for when it is easy to write a solution in one line, and one is in Ook, a variant of Brainfuck. Despite how fun it has been to write brainfuck code, if I actually want to reach my goal, I am going to have to stick with more "reasonable" languages for a bit

So after some work i have a functioning rasterizer that will render a simple scene like Cornell Box pretty fast. I was originally running into a but where i did not properly convert the points to camera space before projecting them onto the camera plane. This caused a weird error which looked like this.

After i fixed the issue it looks like this. The change in brightness is not from my render but from a change in the scene.

The shading might look pretty bad right now but that is because i am not focusing on it. What I want to do now is optimize the hell out of the rasterizer and then at the end I will deal with trying to make the shading look nice. right now it is just a simple lambertian.

Because of the difficulty of using it, I decided that problem number 1 should be written in BrainF. It took most of the morning, but I have succeeded at this task. I unfortunately needed to compromise my rule of "programs must output the solution, not an intermediary value needed to compute it", but because the intermediary value was extremely easy to parse into a solution (I output a number of characters equal to the solution), but it would have been incredibly difficult to actually print a number, I decided to stick with the intermediary version. My next problem will be done using a much more sane language...maybe something like Haskell, which I have never used, though it is a language that is actually meant to be used.

Monday, August 5, 2013

I don't have any good ideas for games/etc. floating around in my head right now (though the Dominion AI idea proposed over lunch today sounds interesting...that may or may not happen at some later date). So, I am deciding to pick up a proposal that came up over an earlier lunch during the year that sounded like it would be fun - try to solve as many Project Euler problems as possible (in 48 hours), but each solution must be written in a different language. My goal for now is to do at least 20, though I can hope for more.

Learn the basics of some "real" programming languages that I have never gotten a chance to use (like Haskell, Perl, Ruby...)

Muck around with silly / ridiculous programming languages while having an actual goal in mind for their use instead of playing with them just to play with them.

In order to make specific what I will be doing, I have established a set of rules to formalize my task:

Rules:

Each "solution" must both follow the Project Euler rule of taking about a minute or less to run to completion, and in addition must actually be capable of outputting the solution in some manner - a program that gives information that can then be used to deduce the solution through additional work or guess and check over a small range is not sufficient.

Two languages, in order to be considered "different," must not be related by age or have a subset relation in code. For example, Java 1.5, Java 1.6, and Java 1.7 will all be considered "Java," even though each is a slightly different language. Also, C/C++ will be considered the same language as any Project Euler C++ code will probably use very few, if any features that are not in the C subset. In addition, for the purpose of this challenge, "assembly" and "machine code" will be considered one language - I am not going to just go around and write assembly for a bunch of different architectures.

A "language" is defined loosely as basically anything you can write in in order to instruct a computer to perform a sequence of instructions - languages need not be Turing complete or live up to any other such qualifications. Meta-languages such as the C Preprocessor and the C++ template meta-language will be considered unique languages, though preference will generally be given to "real" languages before working with them.

I will say that non-programming solutions are invalid - among these would be pencil and paper, calculator usage, graph plotting, excel spreadsheets, etc - due to the increased difficulty in establishing an adequate metric for difference among such methods, and due to not being in the spirit of this challenge. However, this rule may change at a later date, as trying to solve problems in this way could be pretty fun.

Programs must be either hand-written or programatically written by programs I wrote - a solution is not in "Java Bytecode" because I used the Java compiler, but a solution could be in Whitespace if I wrote a Python script that allowed me to convert semi-human-readable text into Whitespace.

A new Project Euler account will be made for this project in order to record my progress

Outside Project-Euler specific help is not allowed, including but not limited to looking at the forums for a problem and looking at my own older solutions (most of which are written in Scheme/Racket, Python, or Java)

I will post my solutions to the Project Euler forums for each problem as I complete them

Thursday, August 1, 2013

The Williams graphics group will run a two-day graphics hackathon to celebrate the end of summer research internships. Others are welcome to join us, but based on the short notice we're not going to do a full game jam and explicitly invite people.

Proposal Deadline: Monday 2013-08-05. Projects can be solo or group, and need not be a game. This is a great chance to design a new G3D feature, implement a graphics algorithm that you've always been curious about, or just play with a demo effect (e.g., maybe in shadertoy). If you want to make a game, that's of course welcome--I'm currently planning to make a game myself.

Start: 2013-08-08 9:00am ET (early starts and exploration are fine)End: 2013-08-09 3:00pm ET...for real this time, so that we can have a cool-down party.

Sleeping and showering at some point in during the hackathon period is highly encouraged. We'll have a mix of takeout and meals out in the lab--sometimes taking a walk for coffee, or half hour at the pizza place is better for workflow than plowing through and eating at your desk.

As usual, post your proposal to the blog before the deadline and then post regularly during the hackathon to document our progress.