Musings of a Fondue

Learning Shaders 2

Here are some additional resources I’ve come across for learning shaders.

Book of Shaders

Great resource because it starts from the absolute basics and builds up, rather than skipping to all the fancy stuff. Emphasis is placed on understanding the fundamentals and developing an intuitive understanding of how things work.

Lighthouse3D

Good introduction to lighting. The tutorials are based on OpenGL but can be adapted to Three.js (which is what I used to follow along). Here’s a toon shader I made from one of the lessons (click image for animation):

Shader School

I think it’s a bit useless to work through this one if you do not have prior exposure to GLSL. But once you do, it’s an awesome series. There’s even a section that touches on using the GPU for general purpose computing.

WebGL Workshop

It is intended to be taken after Shader School. The course teaches you how WebGL (based on OpenGL) works. Basically all the stuff libraries like Three.js do on your behalf. Even if you don’t intend to write your applications using raw WebGL it is useful to understand what is happening behind the scenes.

A neat trick I learned from the course was discard. You can either render a pixel (default) or specify that it be ‘discarded’ (i.e. skipped). Here is a slicing effect I made using this (click image for animation):

Interactive 3D Graphics

Though not strictly a shader focused course, it covers so many fundamental concepts with regards to 3D graphics that skipping it would be doing yourself a disservice. The course is taught using Three.js and touches on pretty much everything you need to know about how 3D computer graphics work and how to create them.


Sidenote: The demos above build on this official Three.js example. The teapot geometry used can be found here and comes from the Interactive 3D Graphics course.

Learning VHDL

I chose to use VHDL to program the FPGA because it is closer to a schematic representation than Verilog. Verilog seems (to me) like learning a new programming language whereas VHDL is more like describing the circuit.

For example, take the construction of a full adder. Here is a video of the structure generated by my code below:

An ADC for the Computer

I bought an analog to digital converter for the computer.

IMG_20160831_154310

The FPGA can only process digital signals (on or off, 3.3V or 0V) but the touch screen outputs analog signals (values ranging from 3.3V to 0V each representing a relative position).

It was my first time soldering (the header pins). As you can see, all the flux was used.

A Keyboard for the Computer

Much like Charles’s hardware setup (see a pattern here?), I decided to use part of the touch screen as the keyboard for the computer.

Design

I roughed out the design using Inkscape. (Because unlike Photoshop or Gimp, you can easily move and resize shapes around after creating them).

I then recreated the design using JavaScript. I used Khan Academy’s coding environment* to do this because its live update feature made iteration and tweaking a breeze. Converting the Inkscape design to code using the Arduino IDE would have been a tedious process as I would have had to upload the sketch each time I wanted to see the effect of a change made.

In the JavaScript code, I used only basic functions that are supported by the Adafruit Graphics Library such as drawRect, drawText, and fillColor. The color scheme is based on this palette with tweaks here and there.

Below is the Javascript mockup. Try typing. Clicking the up arrow toggles the keyboard’s style.

Non-volatile Memory for the Computer

I’m looking at the SD card reader attached to the Mcufriend LCD shield… and thinking it can act as the non-volatile memory for the Hack computer.

When used with the Arduino SD Library, one can easily read, write, create, and remove files (and directories).

The SD card solution is also very convenient! You can plug the SD card into any regular computer (or phone) and copy onto it any programs you want to run on the Hack Computer (for example these games on Github). (Think game cartridge or USB thumb drive). Similarly, if you write a program and save it onto the SD card when using the Hack Computer, you can then open it up later on any other computer (or phone).

An FPGA for the Computer

I’ll be using the Altera Cyclone II - Mini Development Board as the main FPGA of the Hack Computer V1 (name pending).

Cyclone II Mini Dev Board

I got it for $20 on eBay and the kit came with a (knockoff) USB Blaster for programming. The idea to use the board came from Charles Cole’s hardware setup of his homebrew Z-Machine. The price is great and I love that it only has the bare minimum components on it.

I worked through this excellent getting started guide by Trey Dahlberg on Youtube and everything seems to be running well.

Specs:

  • Altera Cyclone II EP2C5T144C8
  • 50MHz clock
  • Schematic

Update (January 18, 2017):

I recently came across the Multicomp project by Grant Searle. In it he uses this development board and consequentially has a ton of really helpful information on the board and some of the things it’s capable of. The project is described by Hackaday as a ‘pick and mix retrocomputer’ which allows you to use the FPGA as a Z80, 6502, 6800 or whatever CPU mashup you feel inspired to. His project also describes in detail interfacing with various devices including SRAM, SD cards, VGA, composite video, PS/2, USB - basically I found the holy grail! Check out the project page to learn more about the board, and maybe even build a mix and match computer of your own.

Note: if you use this development board, make sure to desolder the four zero ohm resistors as explained in Grant’s project page.

A Screen for the Computer

I bought this Mcufriend touch screen. It’s the unbranded version of this one sold by Adafruit.

Front

Back

I got it for $10 compared to Adafruit’s price of $40. I came across the screen through this awesome video by Charles Cole where he walks through his FPGA implementation of a Z-Machine. I also bought the Altera mini dev board he recommends ($20 which is a steal) but that’s another post.

My gameplan is

  • To first get it working on Arduino (since there is information available online on how to do so).
  • Once it works on Arduino, convert the relevant files (driver, graphics) from C, Python, or whichever language is used to Hack Computer’s high level language.
  • Then change a few things here and there on the Hack Computer so that it outputs for the LCD screen instead of Tkinter.

Part 1) Getting the screen to work

Particles and SketchUp Shenanigans

Particles are cool! Example,

I had this idea back in 2014 of getting the points from premade 3D models (similar to the video above), and using them to do fancy animations in Threejs. Then I hit a knowledge wall and shelved it. Until today…