Showing posts with label Rendering. Show all posts
Showing posts with label Rendering. Show all posts

Wednesday, 22 August 2012

Render Module Updates:

A lot has happened since my most recent post. It's time to share more work on the Render Module. So I am grabbing some tea and getting ready to share it with you all:

Improvements to Render Interface

Toolbar:

You don't have to edit a Render Feature to preview it. Simply ensure that the settings are set up to how you desire. Then click the preview buttons within the toolbar.

Buttons (From Left):
1) Add Render Feature
2) Render Preview Window
3) Render Preview (uses stored settings in Render Feature)
4) Add materials when editing a Render Feature


Render Task View:

Further updates to improve the completeness of the Render Task View. Render Presets and Templates are correctly set from the combo boxes. 


Material Selection:

All render materials that have been assigned within the Render Feature are now displayed in a list view. These can be selected and deleted, or if double clicked , the material properties can be edited. 


View shows material Labels:

When editing a Render Feature, all materials that are assigned to any objects has some Material Labels displayed. This is very basic admittedly, but for now will suffice to help keep track of what materials are assigned within your scene.

Render Templates:

The inclusion of the Render Templates was the last remaining major feature that was to be implemented. This has further been improved so that they are positioned in a more optimal place respective to the scene geometry and the camera. This is not perfect but is certainly ideal in most cases.

We can more easily now zoom really far out like this.


Or zoom in really close:


The Render Template will take into consideration the bounding box of the visible parts in the scene and the camera itself. It will move the template to the middle of the scene bounding box and then scale it according to  furthest point away from the bounding box center.

Material Selection & Editing:

I have finished of the material selection interface, so you can set and edit parameters. Now this has undo-redo system built in making things easier. On a similar note materials and cameras can be saved. (Material properties aren't saved yet).

The colour chooser and number inputs now correctly retrieve and store values. It needs refinement but most importantly is function. Ideally it needs a button to allow more sophisticated selection from a QtColorChooser Dialog. Other ideas are having predefined material presets, which become more important on more complex materials such as plastics and glasses.

The above screenshots show that material properties are dynamic. Just define the properties in the XML file and the GUI figures out how to use them and store them. Here's the XML sample for the right:



Well that's most of the major changes! I need help with testing and making materials and templates for people to use.

TODO List:

  1. Ability to Save Material Properties
  2. Make adjustments to the user inteface
  3. Add more render materials and scenes
  4. Python bindings
  5.  ???




Wednesday, 15 August 2012

Creating FreeCAD Lux Render Template

This is for the upcoming Render Module. Despite my very limited experience with rendering and modelling it appears that to get that 'wow' factor it will take a lot of scenes. Most people have better things to do so that is where templates come into play.

This guide will hopefully show how it will be possible to specify your own templates (for lux render):

Beginning with Blender & Lux Render:

The easiest way to create a template is to start with blender. A useful build and instruction guide for compiling Lux Render and using this in  Blender has been provided by Yorik on his blog

I don't have any clue how to use Blender, so you will have to figure that for yourselves. Nevertheless the important that you must have the scene normalised to a unit length. Ideally you have a cube with side lengths as one and build up a scene around this.
This is important because the scene will be scaled to the bounding box of the scene. I cannot guarantee this will work in all situations but it should give satisfactory results. Within blender you will need to export the scene to a  Lux Render Scene File Format with an extension .lxs 

Yorik created three example scenes that I am going to show you how to import as a Render Template in FreeCAD, these I have made available using google docs




Importing templates into FreeCAD:

For the scene template, we only need to find lights, geometry and materials information.

Materials are most likely to be used on the geometry within the scene. Using a templates like this means we can texture surfaces, which isn't going to appear within FreeCAD in the near future.

In this example open up luxscene-classic.lxs

Essentially we need everything from World Begin to World End. So extract all of this and you should be left with http://pastebin.com/qe3m0qXu 

One thing we need to change:

I discovered the long way that there is a problem with the way Blender exports the scene information to Lux Render. Unfortunately, you will need to go through the file and look for lines like these:


Transform [-0.083770856261253 0.000000133886644 -0.996485054492950 0.000000000000000 -0.000000133886729 1.000000000000000 0.000000145614280 0.000000000000000 0.996485054492950 0.000000145614365 -0.083770856261253 0.000000000000000 -0.465571254491806 -0.011301971040666 0.364225387573242 1.000000000000000]


These are transformation Matrices. These need to be removed and replaced with seperate Translation and Rotation properties for each object like so:

Tanslate x y z
Rotate angle x y z


With the rotation, you specify an angle about a given axis, so in the case of blender this may have to be done three times, in the x,y,z directions.

For example in the classic scene:

Select the Plane.006 object and look the object properties



So you would replace the Transform line with this: 
Tanslate 0.459 -0.01 0.6
Rotate 253.4 0 1 0



Place this into a file such as luxsceneClassic.lxs

Then inside the FreeCAD build folder navigate to data/Mod/Raytracing/Templates





Create a folder in Templates/Lux to hold your template such as Templates/Lux/Classic. Then copy the file luxSceneClassic.lxs you previously created inside here.

Within the same folder create an xml file and copy into this file the following excerpt:

<?xml version="1.0" encoding="iso-8859-1" ?>
<!--
 FreeCAD Scene Template for LUX Render, see http://free-cad.sourceforge.net for more information...
-->
<Document SchemaVersion="1">
  <Templates render="lux">
    <Template id="lux_classic" source="external">
      <label>Lux Classic Scene</label>
      <description> Classical Elegance</description>
      <provides>classic</provides>
      <filename>luxSceneClassic.lxs</filename>
    </Template>
  </Templates>
</Document>

For reference you only have to change the following:
  • id="lux_classic" : this attribute must be a unique identifier for the template
  • <label> Label for the scene template </label> : a graphical name for the scene
  • <description>Description for the scene template</description> : a descriptive identifier
  • <filename>luxSceneClassic.lxs</filename> the file name that contains the scene information
You should have a file structure like this:


I am not sure when you compile and build FreeCAD each time if this template folder will be deleted. Most likely not. Later, I will make a preference option so you can use your own folder. 

Using the Template:

Launch FreeCAD and switch to the Raytracing Workbench:

Create a new Render Feature.


A task view will appear. FreeCAD will automatically find your template. You can now select the template that is used in your scene. If nothing appears when you render, it is likely that the Lux Render Scene File Format has incorrect syntax...






Now position the camera where you want and hit Preview Window. Currently there might be times where the render is just a black screen - so to quickly solve this just play around with the camera a bit. 

Hopefully this make sense, feel free to post questions on here if you're stuck!

We have working render templates!


After a few days of working with a day off finally getting out of the small village I live in, we have a render template system that is working.

Here is the Schenkel part - does anybody know what this is? Attached with a Matte material with an orange colour:

Before:




After the render:




Now lets turn it into glass!



Here I am using the classic theme created by Yorilk. It's a basic box scene with two area lights. It's not bad to say it takes about 30 seconds to set up. 

Thursday, 9 August 2012

Render Module Updates

I have been working the past couple of days tidying things up by implementing a new Render Feature into the document tree. This further abstracts data between Renderers, so technically you make simultaneous renders providing your machine is powerful enough, assign different materials to prototype different visualisations or have different views or possible even using different Render Backends... I'm not sure about the last one, atleast regarding material selection.

U-Tube Video:

I decided it was an appropriate time to showcase some of the work that I've been doing for the past two weeks with some notes to accompany it for those interested. It hopefully shows the current state of the Render Module development for those who haven't yet tried the rendering branch. Apologies for no audio commentary, but I don't have a microphone. 


Current State:

We now have a basic UI which gives the ability to start and stop render previews and set basic options such as the output size. This also can be done through python but adds little benefit... 

Currently per RenderFeature, only one Render Process can be used, which makes sense. Buttons are disabled accordingly. 

The annoying thing with QML is that basic components such as ComboBoxes and Number Inputs don't exits - you have to create them yourselves. It's actually not bad as it sounds and slowly I'm building up a slick interface.


The Render Output preview window now works correctly. It can be scaled using the mouse wheel button and dragged around. Sadly I couldn't figure out how to zoom to cursor.

Currently it just uses a polling mechanism, but I later plan to use QFileWatcher to more intelligently check when a new output is created so we don't get LibPNG checks.



Drag and Drop Material Goodness:


This feature I'm really happy with after wrestling with the QT event system for an afternoon, the Drag & Drop material interface now works. In the screenshot above the icons are missing. 

Currently it only intends to assign materials per feature, but later this behaviour can be changed. QML however is not playing very nicely with the current task view. So I may even have to make my own sub class just so that it's contents are scaled correctly, but it would mean slight inconsistency not having the OK | CANCEL buttons unless implemented within the QML File.

So that's it for now. Still more work to do on this!





Monday, 6 August 2012

Render Appearances

Firstly kudos to NASA for landing their 1 tonne Mars Rover last night whilst us Brits were snoozing in Bed. Despite being a year of Olympics, it's looking like 2012 will be the biggest year in science/engineering for a long time.

Appearances:

Lets get back on topic. A library of materials is defined within separate XML files which are specific to each Render Plugin. In most CAD packages there are generic realistic materials such as steel, copper or brass. In the base materials library these will be defined so that you can more easily switch render plugins. These XML files can provide 'built in' or 'external' materials. External materials are essentially templates defined in separate files.  See here for an example of this proposed XML description.



These Library Materials are used for reference: FreeCAD will create a new material referencing this RenderMaterial which includes a default set of values for each parameter. These parameters can be overriden to change material properties such as the Matte colours (Kd). These render materials are later used within the Render and their properties are used to define the material. I am hoping this structure provides a more flexible approach to managing a wide variety of materials from different render plugins.

These Material Libraries can be extended by adding more XML descriptions and perhaps late in the future, users can post their materials on-line in a repository which can be universally accessed.


Thursday, 2 August 2012

Render Module: It's Alive!


I think the above is how I felt when it was working. Thankfully the night I got it working, I was treat to some BBQ duck which went down a treat along with the excitement of this.

Generating the Scenefile format

I'd thought I'd share a bit on Lux Render Scene file format: Scene File Format 1.0 This is based on RenderMan's scene file format (from the guys who make Toy Story!) . The structure of the scene descriptions is very similar to Povray which despite its age is very easy to read, the only difficulty is getting used to the syntax having being so familiar with c++ development. For example:

"float focaldistance" [1.5]
Nevertheless with a bit of practice it soon becomes second nature. Essentially the steps I took at producing the scene file description were to look at the output produced from the povray example included in FreeCAD and with the wiki page on Lux Render. By making this converter I could build up some of the infrastructure with the RenderPlugin and RenderClass. An output created from the RenderPlugin which is a pretty simple plane and cube is on pastebin

Using luxrender GUI I could then import and quickly find problems with the syntax. Sadly nothing works perfect the first time and I was getting outputs like the following:



It took a lot of perserverence to get correct. From here it took several tweaks to get it to work but mainly the following
  1. Triangular Mesh Indices were in the incorrect order (BRep_IncrementMesh) produces them in the incorrect order.
  2. Lot of formatting problems with the output
  3. Quite surprisingly but 'LookAt' descriptor must come before the Camera descriptor which is mentioned in the documentation!

Drum Roll Please... Finaly we got some output! 



Giving the program a few more tweaks and letting the material colour inherit from the Part Appearance colour property, eventually we get some nice looking eye candy! We can make things made in FreeCAD look sexy.


Just for proof, to show that it did originate from FreeCAD 


This is just beginning there's still more work to do and more graphical goodness to share!





Wednesday, 1 August 2012

Work begins on the Freecad Rendering module

Freecad: Rendering Module

How did it get to this:

I reached a point where work on a new improved sketch plane feature (Github Branch) was coming to a slow down - waiting for jrheinlaenders robust references to be tested and merged into the mainline. The principle functionality was there but surprisingly FreeCAD development has been quiet during July in general which isn't practical after having too much free time after finishing summer term (semester) at University.

I was looking for something I could really get into without having to rely on other developers. Everyone loves shiny things and people always want to show their works to their contemporaries but currently there isn't a  way to really showcase people's great work in FreeCAD.

Currently:

Currently in 0.12 and early releases it can export a view and other scene information into a  Povray compatible scene description. This has to be edited and manipulated to get good results which is something else one must learn. Without being prejudice since I've never used Povray, I think there are more moder render suites available that use better algorithms and provide nice results.

A short list of opensource render:

Freestyle - non-photo-realistic renderer for line sketching 
Lux Render
Aqsis: Open Source Render based on Renderman

Blender's Cycles Render
Yafaray
The above seem actively developed and each distinctly offer advantages in quality, speed and features against each other. Excluding Freestyle, these renderers are unbiased renderers.

Unbiased Renderers?

Unbiased renderers produce realistic results by using a realistic physical light model, without taking short cuts from biased renderers. This is my take on explaining it: Essentially the render simulates the behaviour of a light path and how it changes when it bounces off material surfaces and reaches the camera film. Light sources emit packets of light / photos that are cast throughout a scene, these bounce and react to surfaces and its properties such as colour, direction change. These packets of light 'may' reach the camera and according to the type of camera, different effects such as Depth of Field can be produced like a real camera does by setting its aperture and focal distance.Over time samples build up and this continuous field of samples  generate the rendered output.

Modelling realistic behaviour of light is computational more expensive, and each renderer uses algorithms to locate the packets of light. Initially the rendered images will have noise but increasing the rendering time, more samples can be generated, reducing a noise. This could be from ten minutes to 5 hours, but it depends on the scene.

The overall plan of action

My intention is to liberate the FreeCAD user with these rendering tools but make it both simple and quick to create  realistic outputs but allow more adept users to tweak options. I don't intend for this module to be complex, otherwise the user is more inclined to use a more advanced 3D modeller such as blender.org . I want to achieve by providing a library of scenes that the user can choose from and later allow options to manipulate the scene. 

There are many different renderers to choose from and it's sometimes not best to 'put all your eggs in the same basket'. I decided that creating an abstract interface to allow different render plugins to be developed would give users the flexibility to choose what renderer they wanted. It would also allow proprietary renderers to be used providing that they used a scene file format.