SceneKit shaderModifiers

So I started with the basic GameKit, this gives you a colorful jet object in the scene.

By default the code in the GameViewController.m looks like the following:

There’s not much going on other than adding models, lights and cameras to the scene. I wanted to do some learning up on shaderModifiers so I started by getting the mesh in the ship.dae.

To do that I need to get to the material on the ship.

The above shows up with nothing, the ship included in the scene has no geometry in the ship node. This took a few minutes of fiddling before I found that the ship has a shipMesh child object.

Screen Shot 2014-07-25 at 6.48.44 PMThe child is called shipMesh, and that’s the node that would have a firstMaterial. To get to that I used

The line assigns the actual mesh I need to get to the *shipMesh SCNNode object. now I can use the following:

This assigns the shipMesh’s material to the SCNMaterial *mat so I can start adding shaderModifiers to the object in the scene.

Starting with the basics I tried out:

this turned the ship to a grey color. on the iPad:

Screen Shot 2014-07-25 at 6.55.28 PMSo this was expected, vec3(0.5) tells GLSL to make a rgb color of r 0.5, g 0.5. b 0.5, it’s a handy short-hand for color making. Another thing I tried was the following.

This wasn’t assigning color.rgb but color, which expects a vec4, and I got the same result; a grey jet appears on the iPad. Just to be thorough, I tried assigning an interesting value to the color.

The above turned into a reddish jet.

Screen Shot 2014-07-25 at 6.58.46 PM

So this again was expected. I took some code from the WWDC presentation and found some code to try out on the jet.

The above made the jet all wobbly.

Screen Shot 2014-07-25 at 7.00.46 PMAll of the verts were going off of a sin(u_time) which is a value in the GLSL world that all shaders have access to. Cool stuff so far. After this I found some interesting car paint shader from the WWDC presentation and tweaked it to get the following result.


Screen Shot 2014-07-25 at 7.04.07 PMStrangely enough I didn’t delete the code that made the jet wobbly, so I’m guessing something was overwritten. The shaderModifiers is being assigned one value when we use = to assign the value an @{“”}; object. So a bit of looking at the shaderModifiers object in the materials and I see that it’s an NSDictionary. The NSMutableDictionary and NSDictionary are supposedly compatible, so I make a new NSMutableDictionary with the following:

I’ll use that and assign multiple keys with code to the *shaders dictionary.

this looks like the following:

The different SCNShaderModifierEntryPointGeometry and PointSurfaces are key values with objects assigned to them. At the end we assign mat.shaderModifiers = shaders to assign both of these objects in the NSMutableDictionary to the material. So now the final result looks like the following:

Screen Shot 2014-07-25 at 7.09.39 PM


A wobbly pink jet. The significance of all of this is that to apply multiple shaders to the object you need to create a dictionary first, and use the different entrypoint constant values as keys. Hope this all made sense.


Read More

Looking for some Unreal Stuff?

The archives and what’s been going on can be found on the link above. Updates and adventures will be forthcoming as well as a few project announcements.

IMG_20140610_083914Making the most of a small workshop means approaching a critical density of stuff. I need to organize this into something more sensible, and some cool gizmos will be coming to this site soon. Check back often!


Read More

notes on Objective-C

Getting and setting variables in obj-c

The @properties in the @interface allow the class to define any instance or class variables. setting values which are static are done in the @implementation section.

using them is either with the .dot operator or through [class object] interface.

the output for the above is

the last line where we use classVars staticFloat had no @synthesize or @property, anyone know why those weren’t necessary?

Read More

Finished with edits, next steps.

So, the first and second rounds of edits on my book have been submitted to my editor.

I’ve been working non stop, procrastinating, thinking, living, and dwelling on my Unity C# book for over a year. Last night at around 1am I wrote an email, attached a bunch of word files and pdfs that contained the last round of comments and answers to questions from my editor. I’ve put off going to the gym, running, and having a life on the weekends having to re-read and re-work much of my book, and now I’m done.

I have to admit, I’m already considering my next book, I think I might approach something more fun this time. To be honest, I’ve started reading more fiction books and it’s inspired me. I do find myself curious if I could handle making a living from writing. At this point I’ll leave that subject for my day dreaming, I’ve got a lot of game projects to tackle.

I do have a puzzle game I want to finish up. Once I get the mechanic for that working I’m planning on releasing the code on github to allow for as many people to clone it as possible. I’m not planning on making money from the game, or it’s mechanics. It’s a cool idea, and I have plans for how to use the puzzle as a mechanic for a different game which I do want to add some fun/profitable collection game play aspects.

There’s also the rest of life to get back to.

Read More

Gravity waves, and expansion.

Today there’s a new announcement about new data recorded at a telescope in the south pole. A study of the radiation over the course of 9 years, 9 freakn’ years has resulted in a pattern emerging in the background radiation of our universe. This pattern infers gravity waves, a direct result of the math Einstein used to explain gravity.

Not related to E=mc^2, relativity is used every day to figure out where your cell phone is. GPS requires a very precise clock to compare signals traveling at the speed of light from a satellite to a matching pattern in your phone. Depending on where the patterns match up determines where you are on the planet. As civilians we’re not allowed to use devices as accurate as those used by the military. Otherwise, you’d be able to locate your cellphone hidden under a ball cap in the corner of your living room next to a marble.

From the wiki page the satellites need to transmit on an ever so slightly slower frequency; 10.22999999543mhz compared to the receiver on land at 10.23mhz. That small difference in frequency is to compensate for relativity. If that adjustment wasn’t made, GPS simply wouldn’t work. That same calculation can be applied to many more things other than GPS, like gravity waves being propagated by the big bang. The number didn’t come about by guessing. That number was determined by a physicist before the satellite went up.

The significance of the evidence by the telescope is huge. The math predicted that there should be something observable in the form of gravity waves in the microwave background noise of space. If this background noise didn’t exhibit this property then the big bang theory would need to be tossed out and a new theory would have to replace it. However, the prediction found supporting evidence.

This is cool, the math behind it is cool. The prediction is amazing, and the evidence found to support the prediction took a long time to record. I almost feel bad that the evidence was found to match so well. This means the other theories are losing to the big bang leaving fewer options with supporting evidence.

Read More