LuxCore: Shape Strands

Discussion related to the implementation of new features & algorithms to the Core Engine.

Moderators: Dade, jromang, tomb, zcott, coordinators

LuxCore: Shape Strands

Postby Dade » Mon Mar 30, 2015 9:37 am

Introduction

I have added the support for Shape Strands to LuxCore. An introduction to the concept of LuxCore Shape can be find here: viewtopic.php?f=8&t=12012
At the moment, it is pretty much a port of old LuxRender hairs code. A detailed description of the features can be found here: viewtopic.php?f=11&t=3058&start=70#p93612

hair.jpg


Some of the old demos:

Image
Image
Image
Image
Image
Image
Image

LuxCore SDL

This is the definition of a Shape Strands in LuxCore SDL:

Code: Select all
scene.shapes.hair_shape.type = strands
scene.shapes.hair_shape.file = scenes/strands/straight.hair
## RIBBON Tessellation
#scene.shapes.hair_shape.tesselation.type = ribbon
#scene.shapes.hair_shape.tesselation.usecameraposition = 1
## RIBBONADAPTIVE Tessellation
#scene.shapes.hair_shape.tesselation.type = ribbonadaptive
#scene.shapes.hair_shape.tesselation.adaptive.maxdepth = 12
#scene.shapes.hair_shape.tesselation.adaptive.error = 0.075
#scene.shapes.hair_shape.tesselation.type = solid
#scene.shapes.hair_shape.tesselation.solid.sidecount = 3
## SOLIDADAPTIVE Tessellation
scene.shapes.hair_shape.tesselation.type = solidadaptive
scene.shapes.hair_shape.tesselation.solid.sidecount = 8
scene.shapes.hair_shape.tesselation.adaptive.maxdepth = 16
scene.shapes.hair_shape.tesselation.adaptive.error = 0.05


LuxCore C++ API

A Shape Strands can be defined in C++ as in this example: https://bitbucket.org/luxrender/luxrays ... ult#cl-359
Or using Scene::DefineStrands().

LuxCore Python API

A Shape Strands can be defined in Python as in this example: https://bitbucket.org/luxrender/luxrays ... ult#cl-295

Code: Select all
# Add strands
points = []
segments = []
strandsCount = 30
for i in range(strandsCount):
   x = random.random() * 2.0 - 1.0
   y = random.random() * 2.0 - 1.0
   points.append((x , y, 0.0))
   points.append((x , y, 1.0))
   segments.append(1)

scene.DefineStrands("strands_shape", strandsCount, 2 * strandsCount, points, segments,
   0.025, 0.0, (1.0, 1.0, 1.0), None, "ribbon",
   0, 0, 0, False, False, True)

strandsProps = pyluxcore.Properties()
strandsProps.SetFromString("""
   scene.objects.strands_obj.material = whitematte
   scene.objects.strands_obj.shape = strands_shape
   """)
scene.Parse(strandsProps)


Produces:

image.png


scene.DefineStrands() has the following arguments:

- a string for the shape name
- an int for the strands count
- an int for the vertices count
- a list of vertices (es. [(0, 0, 0), (1, 0, 0), etc.])
- a list of how long is each strand (in term of segments, es. [1, 1, 12, 5], etc.) OR the default int value for all hairs (es. 1)
- a list of thickness for each vertex es. [0.1, 0.05, etc.]) OR the default float value for all hairs (es. 0.025)
- a list of transparencies for each vertex (es. [0.0, 1.0, etc.]) OR the default float value for all hairs (es. 0.0)
- a list of colors for each vertex ( es. [(1.0, 0.0, 0.0), etc.]) OR the default tuple value for all hairs (es. (1.0, 0.0, 0.0))
- a list of UVs for each vertex ( es. [(1.0, 0.0), etc.]) OR None if the UVs values have to be automatically computed
- the type of tessellation: ribbon, ribbonadaptive, solid or solidadaptive
- the max. number of subdivision for ribbonadaptive/solidadaptive
- the threshold error for ribbonadaptive/solidadaptive
- the number of side faces for solid/solidadaptive
- if to use a cap for strand bottom for solid/solidadaptive
- if to use a cap for strand top for solid/solidadaptive
- a boolean to set if the ribbons has to be oriented with camera position for ribbon/ribbonadaptive
User avatar
Dade
Developer
 
Posts: 8358
Joined: Sat Apr 19, 2008 6:04 pm
Location: Italy

Re: LuxCore: Shape Strands

Postby DrPingy » Mon Mar 30, 2015 11:27 am

Perhaps I didn't find it in LuxCore C++ API:
How can I set Points and Segment without a hair file?
In Python Scene.DefineStrands does this.
But in C++ there is only a difintiion with hair files.
I can set the strands Count, but not the Points? :shock:
DrPingy
 
Posts: 141
Joined: Mon Dec 27, 2010 4:48 am

Re: LuxCore: Shape Strands

Postby Dade » Mon Mar 30, 2015 11:37 am

DrPingy wrote:Perhaps I didn't find it in LuxCore C++ API:
How can I set Points and Segment without a hair file?
In Python Scene.DefineStrands does this.
But in C++ there is only a difintiion with hair files.
I can set the strands Count, but not the Points? :shock:


luxrays::cyHairFile can be easily initialize from a file but also from C++ (i.e. it doesn't need a file) like I do in Python/C++ glue: https://bitbucket.org/luxrender/luxrays ... ult#cl-632

Check luxrays::cyHairFile source for some more details: https://bitbucket.org/luxrender/luxrays ... at=default
User avatar
Dade
Developer
 
Posts: 8358
Joined: Sat Apr 19, 2008 6:04 pm
Location: Italy

Re: LuxCore: Shape Strands

Postby DrPingy » Mon Mar 30, 2015 1:22 pm

Dade wrote:luxrays::cyHairFile can be easily initialize from a file but also from C++ (i.e. it doesn't need a file) like I do in Python/C++ glue: https://bitbucket.org/luxrender/luxrays ... ult#cl-632

Check luxrays::cyHairFile source for some more details: https://bitbucket.org/luxrender/luxrays ... at=default


Ok, thank you for the fast reply.
Pyluxcore gives a good example.
I've misinterpreted the function names. GetPointsArray() gives the pointer to Set Point Array. ;)
DrPingy
 
Posts: 141
Joined: Mon Dec 27, 2010 4:48 am

Re: LuxCore: Shape Strands

Postby pixie » Mon Mar 30, 2015 4:45 pm

How's for memory consumption?
pixie
 
Posts: 165
Joined: Sun Nov 11, 2007 10:30 am
Location: Neverland

Re: LuxCore: Shape Strands

Postby Dade » Wed Apr 01, 2015 3:42 am

pixie wrote:How's for memory consumption?


It uses 1267MB of GPU ram (everything included: frame buffer, geometry, materials, etc.) for the first image with an insane level of tessellation generating nearly 10 millions of triangles. It uses 620MB with a more reasonable level of tessellation generating 1.9 million of triangles:

tes.jpg


Note: LuxCore uses about 380MB of ram (in order to accelerate the performance) to render an empty scene. This fixed ram cost can be reduced, at a slight cost in performance, with a parameter.

Note2: LuxCore uses a quite compact geometry memory storage, from the above test you can see how it uses about 1GB GPU ram for storing more than 10 million of triangles. GPU memory is usually consumed more by texture maps than geometry.
User avatar
Dade
Developer
 
Posts: 8358
Joined: Sat Apr 19, 2008 6:04 pm
Location: Italy

Re: LuxCore: Shape Strands

Postby DrPingy » Thu Apr 02, 2015 2:09 am

I made a simple test with the c++ api and have 2 questions now:

I use this code to get one simple hair:
Code: Select all
{
         luxrays::cyHairFile strandsObject;
         const int strandsCount = 1;
         strandsObject.SetHairCount(strandsCount);
         strandsObject.SetPointCount(2 * strandsCount);
         strandsObject.SetDefaultSegmentCount(1);
         strandsObject.SetArrays(CY_HAIR_FILE_POINTS_BIT | CY_HAIR_FILE_SEGMENTS_BIT | CY_HAIR_FILE_THICKNESS_BIT | CY_HAIR_FILE_COLORS_BIT);   //points and segments must be

         Point* p = (Point*)strandsObject.GetPointsArray();
         p[0] = Point(0.0f, 0.0f, 0.7f);         //base point on top of box1
         p[1] = p[0] + Point(0.0f, 0.0f, 1.0f);
         
         u_short *s = strandsObject.GetSegmentsArray();
         s[0] = 1;
         
         float *t = strandsObject.GetThicknessArray();
         t[0] = 0.1f;
         
         float *c = strandsObject.GetColorsArray();
         c[0] = 0.0f;      //r
         c[1] = 0.0f;      //g
         c[2] = 1.0f;      //b
         
         scene->DefineStrands("strand_shape", strandsObject,
            Scene::TESSEL_SOLID_ADAPTIVE,   //StrandsTessellationType
            16,            // adaptiveMaxDepth
            0.01f,         // adaptiveError
            8,            // solidSideCount
            false,         // solidCapBottom
            true,         // solidCapTop
            true);         // useCameraPosition

         // Add the object to the scene
         Properties props;
         props.SetFromString(
            "scene.objects.strand_obj.shape = strand_shape\n"
            "scene.objects.strand_obj.material = mat_white\n"
            "scene.objects.strand_obj.transformation = 1.0 0.0 0.0 0.0 \
                                            0.0 1.0 0.0 0.0 \
                                            0.0 0.0 1.0 0.0 \
                                            0.0 0.0 0.0 1.0"      //scale and translate, if necessary
            );
         scene->Parse(props);
      }


With this I have got this Image (only the hair in the middle is of interest):
image5.png


1. Why is the hair not a cylinder?
I test with solidCapTop true and false with the same result.
2. What does the ColorsArray do?
In my case nothing! Only the materials Setting in props is used.
DrPingy
 
Posts: 141
Joined: Mon Dec 27, 2010 4:48 am

Re: LuxCore: Shape Strands

Postby Dade » Thu Apr 02, 2015 2:34 am

DrPingy wrote:1. Why is the hair not a cylinder?


The thickness array must have the same number of values of the point array (2 in your case). The same is true for the color array. LuxCore is using the values after the end of the array at the moment (i.e. random memory) and it could easily crash.

Just set the second value to something > 0.0

DrPingy wrote:2. What does the ColorsArray do?
In my case nothing!


You have to use 2 values and to use texture hitpointcolor, something like:

Code: Select all
scene.materials.hc_tex.type = hitpointcolor

scene.materials.hair_mat.type = matte
scene.materials.hair_mat.kd = hc_tex
User avatar
Dade
Developer
 
Posts: 8358
Joined: Sat Apr 19, 2008 6:04 pm
Location: Italy

Re: LuxCore: Shape Strands

Postby DrPingy » Thu Apr 02, 2015 3:39 am

Thank you for the fast reply.

The thickness works fine.

But with hitpointcolors I got an error.
I programmed that:
Code: Select all
props.SetFromString(
            "scene.materials.hc_tex.type = hitpointcolor\n"
            "scene.objects.strand_obj.shape = strand_shape\n"
            "scene.objects.strand_obj.material = matte\n"
            "scene.objects.strand_obj.kd = hc_tex\n"
            "scene.objects.strand_obj.transformation = 1.0 0.0 0.0 0.0 \
                                            0.0 1.0 0.0 0.0 \
                                            0.0 0.0 1.0 0.0 \
                                            0.0 0.0 0.0 1.0"      //scale and translate, if necessary
            );


And got following error:
hitpointerror.jpg


I use the latest responsivity.
DrPingy
 
Posts: 141
Joined: Mon Dec 27, 2010 4:48 am

Re: LuxCore: Shape Strands

Postby Dade » Thu Apr 02, 2015 3:48 am

DrPingy wrote:But with hitpointcolors I got an error.


Sorry, it was a typo, it is a texture, not a material:

Code: Select all
scene.textures.hc_tex.type = hitpointcolor
User avatar
Dade
Developer
 
Posts: 8358
Joined: Sat Apr 19, 2008 6:04 pm
Location: Italy

Next

Return to Architecture & Design

Who is online

Users browsing this forum: No registered users and 1 guest