Looking for some Unreal Stuff?

http://okita.com/alex/unreal-game-development-archive/

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

Starting with Python scripts in Modo

So after searching for a while, I couldn’t find any really clear Modo tutorials on Python. So here’s a clear and simple one.

My Setup: Using Modo 801 sp3 Sublime Text 3 (though you can use any other regular text editor) osX 10.10 Some general understanding of what python is (it’s a nice programming language which uses a lot of white space) That’s all you’ll need.

First of all, this will be a really simple hello world example for a simple script. You’ll want to open up Modo, and then go open the following menu System->Open User Scripts Folder

This will open up the location where your scripts will go. Modo scans this directory for any files which have the appropriate contents and then you’ll be able to run them from Modo’s command line if everything is setup right.

In osX it’s in a hidden directory called Library, I’m not sure why it’s hidden, but ya, it’s hidden.

For me it’s located at this path:

/Users/alexokita/Library/Application Support/Luxology/Scripts

If you’ve installed a script written by someone else and downloaded they’ll also go in this directory.

Next we’ll open up our text editor, don’t use Word, or something that’s going to allow formatting of any kind. I’ll use Sublime text since it’s got some nice code highlighting features. Here’s a link to Sublime. It’s not free, but it’s worth it if you’re going to be doing any more python.

sublime

The first thing you’re going to write in your text editor is

This is actually a python comment, but this is important for Modo in particular. Modo is scanning the Scripts directory, and any file with this hashtag at the top of it tells Modo to expect to run the following text in the file as a python script.

Now save it as something simple but make sure that you use the .py file extension

don’t forget the .py

This is another little thing that lets Modo know that this is a python script for it to execute, this also tells your text editor to apply the appropriate syntax highlighting to make things look nice. Even though there’s nothing in this you’ll already be able to run the script in Modo. So how is it used?

you’ll find the command line in Modo down in the lower right from the Modeling view.

This unassuming little box is where you get to call your scripts from. To run our new myScript.py or whatever you named it.py starts here. put the following text in there

@myScript.py

and hit enter.

do it!

If all goes well, nothing should happen. This is great, actually. this means that it read the correct file, and actually executed the python in it. And so far there’s nothing in it.

If you grab the top left of the command line window, you can pull it out and expand it.

success!

Select the Results tab on the top right, and you’ll see @myScript.py has been successfully executed!

Okay, so lets make this more interesting. In the text editor enter the following

That’s it, so go back into Modo and enter the @myScript.py command again but this time we’ll open a new window called the Event Log To do this select Layout->Windows->New Window->Normal

new window

Then once you have a new window, select the little grey triangle on the top right and expand the menu and select Application->Event Log

Event Log

This window will show you the ‘hello world’ that was executed in the myScript.py file.

So what can go wrong?

Make sure that you use the @ sign in the command window

oops

if you just use myScript then you’ll get an error Unknown Command ‘myScript’ of course upper and lower case also matter as well as spelling.

In any case, that’s all for this post, if you have any questions then find me in the Modo SDK Skype channel.

Read More

Adding joints to a weighted mesh.

So just recently I’ve been working on a character. The rig has some 150+ joints, and I really hate redoing weighting, so when I found out some of the joints were excluded from the weighting I was pretty annoyed. But I figure Modo isn’t stupid, so there should be some way to add joints and weights to the mesh even after an initial heat mapping of the joints. So yes, there’s a way add joints and weights to a mesh after having weighted a mesh to some joints.

So here’s a simple start.

first three

In some apps there would be a problem if I really wanted to have the other joints included in the deformation.

oops.

So here’s the result as you might expect.

:(

So how do we add in the other three joints?

With the mesh selected go to the Lists tab, and then click on ( new map ) to add in a new weight map.

new weight map

This will allow you to add to the influences of the heat map. The problem is that the auto-magic of the heat weighting will not be able to be applied, but alas, some things are a bit hard to do after the fact. For me, the joints that weren’t added to the weights were too small to contribute to the heat map, and thus didn’t get Weight Maps generated for them. So this is why I had to figure this out. And since there’s not a whole lot of documentation on this sort of stuff I felt the need to share.

adjusting.

So here we’ll add some weights to the new Weight map… for some reason modo named it “__item_locator” but if i feel like it It’s easily renamed later on. BUT, I’m lazy and don’t want to think of a more useful name. so, “__item_locator” it is.

After adding one, I’ll add in two more weight maps. for the other two joints roughly approximating where the weights should influence.

Not perfect, but who cares.

So here they are selected, looks like one of them is a bit weak, but that’s easily adjusted after the fact. The point is, there are three new weight maps, but they’re not really doing anything yet since they aren’t associated with a joint.

I hate macs.

So there’s a popup, when i did the screen cap it was actually visible, but osX fails at simple things…

I had to take a screen shot of a screen shot for this.

I had to take a full screen screen shot and then take a screen shot of the result of that to make the above shot of the popup menu.

doh…

Work flow wise, this isn’t optimal, it would be cool if there were an option to add the transform effector from a selected item in the scene, but instead modo creates a new locator for you in place of that. So I believe I’ll be writing a script for this soon-ish (Actually, not till I have a reasonable amount of free time to both learn how to and implement such a thing. )

Look, nodes!

There might be a way to do this outside of the schematic, but this sort of feels faster. (though in reality it might not be but I haven’t timed it and I hope you don’t care.)

swap!

So drag the joint you actually want to use on the weight map into the schematic too. Then you can swap which locator is connected to the Effector input of the weight map. Now you can delete the extra Transform Effector that was added. But we’re not quite done yet.

Deformer List.

Now the joint is associated with the weight map, but if you move the joint right now the weight map isn’t actually going to matter, the joint will not deform the mesh correctly, you’ll get a weird double transform!? (also don’t forget to get out of setup mode to test the deformations like I did. I thought I missed a step…)

ooo weird.

This shows that just rotating the 3rd joint, not the 5th is still deforming the __item_locator twice!? That’s because the deform influence isn’t included in the normalized folder. Why is this happening? The 3rd joint and the 5th joint are actually both moving through world space. So since the 3rd joint is moving the 5th they both move the mesh verts that were weighted to them.

yay fixed!

I’m not going to repeat this another couple of times for the other joints, the process is the same and repetitive. This is more encouragement to write a script to replace the tedium.

Baked normalization.

Right clicking on the Normalizing Folder will bring up a popup with the “Bake Weights” option. This will actually make the weight maps normalized against one another. This will also make painting the weightings easier since the weight map for Joint 5 and 3 will not both have values of 100% on the same verts.

Hope this helps someone. If you have any questions leave a comment below.

 

Read More

The Foundry’s Modo Vertex Map and Schematic Tutorial to make a Crinkle mask.

Here’s a quick little tutorial looking at a cool trick to make a vertex map into a displacement mask based on some simple joint positions.

I start with this simple setup, but this can be used on a character, or on a barrel of oil bending, etc.

Basic cylinder and a couple of joints

Cylinder

After this I just used a simple binding to get this effect to look like it’s doing something interesting.

Binding result.

So here it’s bent. Naturally, this result isn’t all that interesting. It’s what you can expect on a low polygon mesh with default binding.

Weight Map

So I’m adding a Vertex Map, it’s just a weight map and I’m calling it Bent_WeightMap. This will mask a displacement map so we can get some more interesting crinkled details.

Smoothed weights

So here’s some results with a basic assignment, the red shows where the map approaches 100%, the rest should be set at 0%.

Assigned Material

So the crinkle, or Krinkle (because im edgy) is assigned to the mesh. Well use the Mask in a moment after this.

Back in setup, we’ll bring the joints into the schematic view.

Setup.

So To get the joints into the schematic view Drag the joint from the Items list into the Schematic view.

Once all three joints are in the schematic select each one, right click and select Add Channel… World Position.

Then Add in a new node called Measure Angle. In the schematic select the Add… ->Channel Modifier -> Measure -> Measure Angle.

I’d post a screen shot but for some reason osX hates making screen shots of sub-popup menus in Modo.

Wired Nodes.

So Wire the World Position of Joint2, not 1 or 3, to the Position From input. This will be the sort of center point where to measure the angle from. Assign the First joint to the Position to A and the end joint, Joint3 to the Position to B.

Angle shows on Joints.

The joint angle will now be displayed over the joints when you have the Measure Angle node selected in the Schematic view.

Now add three more math nodes.

Math Nodes.

The first is a divide by 180, this gives us a number that starts at 1, when the joints are straightened out and 0 when they begin to bend.

Then we add a subtract 1 node from that so we get 0 when they are straight and -1 when they’re bent.

Then last we multiply by -3 so we get 0 when it’s straight and 3 when it’s bent.

Now we add a displacement map, but we’ll want to start off as diffuse so we can easily visualize what it’s doing.

Add a Modo texture.

After that menu I select Enhance:modo Textures -> Water -> Waves

I adjust the scale to get the following resulting diffuse appearance.

Waves going across the bend.

I’ve also set the projection type to UV and selected Texture so it’s easier to scale.

As Displacement.

Then change diffuse color to displacement. Then add a new Layer -> processing -> Weight Map Texture and drag it into the displacement layer.

Weight Map Texture.

Modo automatically changes the weight map into a Layer Mask. The result should look like there’s a bunch of crinkled folds where we painted the weight mask.

Displacement as Bump.

I notice i get weird seams where the displacement gets flat near the 0% weighted verts, but this Displacement as Bump check box seems t fix that. Now drag the Weight Map Texture from the Shading panel into the schematic view.

Weight Map in Schematic.

Then plug the result of the math into the Value 2 of the Weight Map Texture.

When the joints are bent we get the above result. When they’re straightened out we the the result below.

Unbent.

The crinkled displacement thins out.

 

Download the scene file here if you would like to see the completed scene.

Read More

Epic cuts Unreal Engine loose!

Epic does away with their monthly fee to access the UE4 github repo. That makes Unreal Engine the most affordable game engine to get into which has the most advanced features of pretty much any game engine out there. The fee is gone, and there’s no royalty for people doing simulations visualizations or film, so basically, if you’ve got a real-time demo you wanna try out in UE4; go for it.

So to that end

Read More

SCNTechnique in SceneKit

New in ios8 is the SCNTechnique. It’s a way to get your models to pass through a custom shader program. This is an added layer on top of an objects filters. For instance, you’re able to apply a Gaussian blur to a single node in a SceneKit scene, then pass the scene to a fragment shader to change the color of the scene.

Getting started I’m setting up a new ios game.Screen Shot 2014-08-22 at 10.46.31 AM

This will create the scene view that SceneKit uses to render it’s 3d objects to. I’ve named the project SCNTechnique, this will make it obvious what this project is being used for.

Screen Shot 2014-08-22 at 10.47.22 AM

I’m also enabling the local source control, I think git is required for this to work. If you don’t have this then I suggest you use it. If you break something it’s useful to know what you changed.

In the project we’ll want to set up a new dictionary that’s used to reference and define data going to and from the SCNTechnique rendering pass. I’m adding an iOS property list. Selecting add new file to the project to open this choose a template for your new file dialog:

Screen Shot 2014-08-22 at 10.57.10 AM

Then I’m naming it firstPass, it’ll add the plist file extension for me. A property list is an XML file which Xcode allows us to edit with a more friendly interface.

Screen Shot 2014-08-22 at 10.57.28 AM

The file appears with Root as the only section of data. We need to populate this with a few things to turn it into something that can be used by SCNTechnique. There are three entries [sequence, passes, symbols] where sequence is an Array and passes and symbols are both Dictionaries. These are added with the plus icon, and the type is changed with a popup menu under the type column.

Screen Shot 2014-08-22 at 11.11.29 AM

sequence defines what pass is rendered when. To be honest, I think this means that you can define multiple passes in a single SCNTechnique, but so far this seems to be quite buggy and I can’t seem to get more than one pass working. Passes defines what parameters are passed to and from the shader programs. We’ll get to shader programs in a moment. symbols defines what name and type the data is passed from your code into the shaders.

So shader programs, I couldn’t find any appropriate templates to start with for these, so I ended up picking iOS/Other/Empty template. Which isn’t much of a template… But it is necessary to ensure that the project is aware of your new file. I added two files, a firstProgram.vsh and a firstProgram.fsh.

Screen Shot 2014-08-22 at 11.17.05 AM

These live in the project like so.

Screen Shot 2014-08-22 at 11.19.12 AM

What is the fsh and vsh for? the fsh means fragment shader and the vsh means vertex shader. Basically these are common OpenGL type shader programs. To make the connection between these shader programs and SCNTechnique in your SceneKit scene you’ll need to add them to the firstPass.plist so back to defining the technique’s property list.

In the Sequence array we need to name a rendering pass in the passes list. This seems to be the entry point for the technique. I’m naming it renderingPass.

Screen Shot 2014-08-22 at 11.25.23 AM

This tells the Technique where to start. The item 0 of the sequence needs to point to an entry in the passes item. Then in passes we are require to have 4 entries.

Screen Shot 2014-08-22 at 11.28.19 AM

draw program inputs and outputs, draw is a string program is another string and inputs and outputs are both dictionaries.

Screen Shot 2014-08-22 at 12.23.46 PM

 

draw needs to be set to DRAW_QUAD which is used to draw data piped into the shader program, we also have DRAW_NODE or DRAW_SCENE. Each is used for specific reasons, but for now we’ll use DRAW_QUAD. The program refers to the .vsh and .fsh files we created and added to the project a moment ago. (note: the case and underscore are important) Don’t add the .vsh or .fsh to the program, Technique knows what to do with the name. I’ll always look for both files, if one or the other are missing the Technique will fail and your app will stop when looking for the program.

Screen Shot 2014-08-22 at 11.45.15 AMIt seems rather necessary that one of the inputs is COLOR which goes into a colorSampler. COLOR is an openGL data source and colorSampler will be available in the shader program with data coming from COLOR. the a_position is a variable which points to a_position-symbol. We will need to add this to the symbols section of the technique’s plist. So we’ll add that in next.

Screen Shot 2014-08-22 at 11.53.41 AMIn the a_position we add a_position-symbol and in symbols create a_position-symbol as a dictionary and add semantic vertex string to create a link between your SCNTechnique and the program. I’m not exactly sure why we don’t need to do this for colorSampler, but that’s how it works.

now we should add our code to both the .vsh and .fsh to make this work. In the firstProgram.fsh I’ve added the following code:

This isn’t objective-c it’s c, and the colorSampler here is being piped in from the plist which SCNTechnique is using to tunnel data through. gl_fragColor is the final output to the fragment shader.

In the vsh we need to add in the following code:

The gl_Position is the final output for the vertices in the vertex shader. With these two parts of the firstProgram in place and the firstPass.plist setup we can now use it in the GameViewController.m

In the template code we follow after the scnView is setup in the scene. Then we create a NSURL *url; to fill with url = [[NSBundle mainBundoe] URLForResource:@”firstPass” withExtension:@”plist”]; this makes a url that points to the firstPass.plist that we created with all of the data used to connect our shader program with the SCNTechnique. The we use SCNTechnique *firstTechnique to load in that dictionary. Finally we assign scnView.technique to the SCNTechnique we created from the plist.

IMG_0104

Horray, we’re drawing using a SCNTechnique, it doesn’t look like anything interesting is happening, but it’s really going through our shader program and not the usual scene.view. We can prove this by editing the shader program. We can draw the technique as red by changing the fsh to the following code.

This sets the gl_fragColor to red. And now the iPad draws the image as all red. I’m still working on more interesting things to do with all of this but if you’re familiar with openGL then you’ll be able to do quite a lot. I’m not that familiar with openGL myself, so I’m learning what I can while I can. Hope this tutorial helps.

 

Read More

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