Rendering学習日記

日々、3DCGの世界は進歩しています。勉強して理解したことをまとめていきます。RenderMan互換レンダラーやグローバル・イルミネーション。いろんなことに好奇心を持って、面白くなる。目指せShader書き!!
ありがとうございます。

Lightflow C API sample ball3

main3.cpp
#includeの両側に半角スペースが入っています。

#include < Lightflow/LfLocalSceneProxy.h >

int main()
{
LfLocalSceneProxy* s = new LfLocalSceneProxy();
LfArgList list;

list.Reset();
list << "position" << LfPoint( 5.0, -5.0, 4.0 );
list << "color" << LfColor( 300.0, 300.0, 300.0 );
s->LightOn( s->NewLight( "point", list ) );


list.Reset();
list << "kr" << LfColor( 1.0, 0.9, 0.8 );
list << "kaf" << 0.3;
list << "density" << 0.3;
list << "sampling" << 40.0;
list << "shadow-caching" << LfPoint( -1.2, -1.2, -1.2 ) << LfPoint(
1.2, 1.2, 1.2 );
LfInt gas = s->NewInterior( "dust", list );

s->InteriorBegin( gas );

list.Reset();
LfInt cloud = s->NewMaterial( "transparent", list );

s->InteriorEnd();


s->MaterialBegin( cloud );

list.Reset();
list << "radius" << 1.2;
s->AddObject( s->NewObject( "sphere", list ) );

s->MaterialEnd();


list.Reset();
list << "ka" << LfColor( 0, 0, 0.5 );
list << "kc" << LfColor( 1, 0.5, 0.5 );
list << "kd" << 0.5;
list << "km" << 0.1;
LfInt plastic = s->NewMaterial( "standard", list );

s->MaterialBegin( plastic );

list.Reset();
list << "radius" << 0.5;
s->AddObject( s->NewObject( "sphere", list ) );

s->MaterialEnd();


list.Reset();
list << "file" << "ball3.tga";
LfInt saver = s->NewImager( "tga-saver", list );

s->ImagerBegin( saver );

list.Reset();
list << "eye" << LfPoint( 0, -4, 0 );
list << "aim" << LfPoint( 0, 0, 0 );
LfInt camera = s->NewCamera( "pinhole", list );

s->ImagerEnd();

s->Render( camera, 300, 300 );

delete s;
}


$ /usr/local/gcc-2.95/bin/g++ -I ./include -lLightflow main3.cpp -o simplescene3
$ ./simplescene3
$ convert ball3.tga ball3.jpg
$ eog ball3.jpg
ball3.jpg
  • -
  • -

Lightflow C API sample lights

main4.cpp
#includeの両側に半角スペースが入っています。

#include < Lightflow/LfLocalSceneProxy.h >

int main()
{
LfLocalSceneProxy* s = new LfLocalSceneProxy();
LfArgList list;
LfTransform trs;

list.Reset();
list << "position" << LfPoint( 4.0, -6.0, -5.0 );
list << "color" << LfColor( 200.0, 200.0, 200.0 );
s->LightOn( s->NewLight( "point", list ) );

list.Reset();
list << "position" << LfPoint( -7.5, -6.0, 2.0 );
list << "color" << LfColor( 300.0, 150.0, 150.0 );
LfInt light1 = s->NewLight( "point", list );

list.Reset();
list << "position" << LfPoint( -2.0, 0.0, 8.0 );
list << "color" << LfColor( 150.0, 300.0, 150.0 );
LfInt light2 = s->NewLight( "point", list );

list.Reset();
list << "position" << LfPoint( 8.0, -6.0, 5.0 );
list << "color" << LfColor( 150.0, 150.0, 300.0 );
LfInt light3 = s->NewLight( "point", list );


s->LightBegin();
s->LightOn( light1 );

list.Reset();
list << "ka" << LfColor( 0.1, 0.1, 0.1 );
list << "kc" << LfColor( 1, 1, 1 );
list << "kd" << 0.5;
list << "km" << 0.1;
LfInt plastic1 = s->NewMaterial( "standard", list );

s->LightEnd();

s->LightBegin();
s->LightOn( light2 );

list.Reset();
list << "ka" << LfColor( 0.1, 0.1, 0.1 );
list << "kc" << LfColor( 1, 1, 1 );
list << "kd" << 0.5;
list << "km" << 0.1;
LfInt plastic2 = s->NewMaterial( "standard", list );

s->LightEnd();

s->LightBegin();
s->LightOn( light3 );

list.Reset();
list << "ka" << LfColor( 0.1, 0.1, 0.1 );
list << "kc" << LfColor( 1, 1, 1 );
list << "kd" << 0.5;
list << "km" << 0.1;
LfInt plastic3 = s->NewMaterial( "standard", list );

s->LightEnd();


s->TransformBegin( trs.Translation( LfVector3( -2.0, 0, 0 ) ) );

s->MaterialBegin( plastic1 );

list.Reset();
list << "radius" << 1.0;
s->AddObject( s->NewObject( "sphere", list ) );

s->MaterialEnd();

s->TransformEnd();


s->MaterialBegin( plastic2 );

list.Reset();
list << "radius" << 1.0;
s->AddObject( s->NewObject( "sphere", list ) );

s->MaterialEnd();


s->TransformBegin( trs.Translation( LfVector3( 2.0, 0, 0 ) ) );

s->MaterialBegin( plastic3 );

list.Reset();
list << "radius" << 1.0;
s->AddObject( s->NewObject( "sphere", list ) );

s->MaterialEnd();

s->TransformEnd();


list.Reset();
list << "file" << "lights.tga";
LfInt saver = s->NewImager( "tga-saver", list );

s->ImagerBegin( saver );

list.Reset();
list << "eye" << LfPoint( 0, -4, 0 );
list << "aim" << LfPoint( 0, 0, 0 );
list << "fov" << atan( 0.5 / 0.75 )*2.0;
LfInt camera = s->NewCamera( "pinhole", list );

s->ImagerEnd();

s->Render( camera, 300, 300 );

delete s;
}


$ /usr/local/gcc-2.95/bin/g++ -I ./include -lLightflow main4.cpp -o simplescene4
$ ./simplescene4
$ convert lights.tga lights.jpg
$ eog lights.jpg
lights.jpg
  • -
  • -

Lightflow C API sample cloud

main5.cpp
#includeの両側に半角スペースが入っています。


#include < Lightflow/LfLocalSceneProxy.h >

void main()
{
LfLocalSceneProxy* s = new LfLocalSceneProxy();
LfArgList list;

list.Reset();
list << "direction" << LfVector3( 8.0, 5.0, -6.0 );
list << "color" << LfColor( 1.0, 1.0, 1.0 );
s->LightOn( s->NewLight( "directional", list ) );


list.Reset();
list << "value"
<< 0.3 << 1.0 << 1.0
<< 0.5 << 0.0 << 0.0;
list << "scale" << 1.0;
list << "turbulence.omega" << 0.55;
list << "turbulence.lambda" << 1.8;
list << "turbulence.octaves" << LfInt( 6 );
LfInt cloudpattern1 = s->NewPattern( "granite", list );

// Make a granite-like volumetric pattern.
// Note the keyword "value", followed by two rows of three parameters
// each.
// This is an example of value-gradient. A gradient is a function which
// interpolates many values, which may be numbers, colors, or entire
// patterns and materials.
// By convention numeric gradients are called value-gradients, color ones
// are named color-gradients and so on.
// As a function a gradient associates a value to a real variable.
// You can imagine it in cartesian coordinates, putting the variable on
// the abscissas and the associated value on the ordinates.
// Here the first expected argument is the abscissa at which the value
// of the function is specified, then the value follows. The value is
// specified both at the right and at the left of the abscissa in order
// to model discontinuities, so it is composed by two numbers.
// You can specify how many abscissas (and values) you want.
// This gradient is used to model the output of our fractal pattern,
// that we will use to describe the spatial density of the cloud.
// Here the gradient smoothly blends from the value of 1 at the point 0.3,
// to the value of 0 at the point 0.5.
// Normally the output would be a value between 0 and 1, but we
// make it droppoff rapidly from 1 to 0 to model masses of clouds that
// are denser at their center and that disappear at their boundaries.

list.Reset();
list << "value"
<< 0.8 << 1.0 << 1.0
<< 1.0 << 0.0 << 0.0;
list << "scale" << 1.2;
LfInt cloudpattern2 = s->NewPattern( "radial", list );

// Make a radial pattern, that is to say a spherical figure that is
// dense at its center and that has zero density at its border.
// This sphere has a radius of 1.2.

list.Reset();
list << "patterns" << cloudpattern1 << cloudpattern2;
LfInt cloudpattern = s->NewPattern( "compose", list );

// Compose the two patterns. Here the output of cloudpattern1 is used
// as the input of cloudpattern2. Since the radial pattern uses its
// input to scale its output, the result will be a sphere containing a
// granitic texture which diminishes its intensity near the border.

list.Reset();
list << "kr" << LfColor( 0.7, 0.85, 1.0 );
list << "kaf" << LfColor( 0.2, 0.35, 0.5 );
list << "density" << 1.0;
list << "density" << cloudpattern;
list << "sampling" << 20.0;
list << "shadow-caching" << LfPoint( -1.2, -1.2, -1.2 ) << LfPoint( 1.2, 1.2, 1.2 );
list << "density-caching" << LfInt( 2048 ) << LfPoint( -1.2, -1.2, -1.2 ) << LfPoint( 1.2, 1.2, 1.2 );
LfInt cloudinterior = s->NewInterior( "cloud", list );

// Here you should note how we described density.
// It has been specified with a single value of 1 and then with the
// pattern we modeled before. The value of 1 will be used as a input to
// cloudpattern1, which will scale its output by this factor. In
// this case there will be no scaling, and the output will go from 1 to
// 0, as we stated above.
// The "shadow-caching" and "density-caching" attributes specify the use of
// two different caching mechanisms that will be used to speed-up
// computations. They both require a bounding box where to work, and
// the density cache also requires the maximum allowed memory
// occupancy, which is expressed in Kb (here 2048, i.e. 2 Mb).
// The "sampling" value specifies how many samples will be taken into a
// segment long one.

s->InteriorBegin( cloudinterior );

list.Reset();
LfInt cloud = s->NewMaterial( "transparent", list );

s->InteriorEnd();


s->MaterialBegin( cloud );

list.Reset();
list << "radius" << 1.2;
s->AddObject( s->NewObject( "sphere", list ) );

s->MaterialEnd();


list.Reset();
list << "file" << "cloud.tga";
LfInt saver = s->NewImager( "tga-saver", list );

s->ImagerBegin( saver );

list.Reset();
list << "eye" << LfPoint( 0, -4, 0 );
list << "aim" << LfPoint( 0, 0, 0 );
LfInt camera = s->NewCamera( "pinhole", list );

s->ImagerEnd();

s->Render( camera, 300, 300 );

delete s;
}

$ /usr/local/gcc-2.95/bin/g++ -I ./include -lLightflow main5.cpp -o simplescene5
$ ./simplescene5
$ convert cloud.tga cloud.jpg
$ eog cloud.jpg
cloud.jpg
  • -
  • -
<< 24/25 >>