OGLFlatVertexColorShader.kl

Types

OGLFlatVertexColorShader (object)

バージョン 1.12.0 で追加.

The OGLFlatVertexColorShader inherits the OGLInlineShader. It extends the OGLInlineShader for shading with flat colors, using the vertexColors attribute for the diffuse.

Attributes

Name Type Description
positions Vec3 Geometry positions
vertexColors Color Color per vertex
/*
** Example: OGLFlatVertexColorShader
*/

require InlineDrawing;

function Vec3 randomVector(Scalar radius, io UInt32 offset)
{
  const UInt32 seed = 16841;
  return Vec3(
    (mathRandomFloat32(seed, offset++) - 0.5) * radius,
    (mathRandomFloat32(seed, offset++) - 0.5) * radius,
    (mathRandomFloat32(seed, offset++) - 0.5) * radius
  );
}

operator entry(){
    // Create a new Points geometry with a vertex colors attribute.
    Points points();
    Ref<ColorAttribute> vertexColors = points.getAttributes().getOrCreateColorAttribute( 'vertexColors' );
    UInt32 offset = 0;
    UInt32 numPoints = 200;
    Scalar radius = 100.0;
    points.resize(numPoints);
    for( UInt32 i = 0; i < numPoints; ++i ) {
      points.setPosition( i, randomVector( radius, offset ) );
      // Assign Red to every even point, and green to every odd point
      if(i%2 == 0)
        vertexColors.values[i] = Color(1.0, 0.0, 0.0);
      else
        vertexColors.values[i] = Color(0.0, 1.0, 0.0);
    }

    // Now display the points using InlineDrawing.
    InlineDrawing drawing = OGLInlineDrawing_GetInstance();
    InlineShader vertexColorsShader = drawing.registerShader(OGLFlatVertexColorShader);
    InlineMaterial vertexColorsShaderMaterial = vertexColorsShader.getOrCreateMaterial('vertexColors');

    InlineTransform pointsTransform = InlineTransformBase('pointsTransform', Xfo());
    drawing.getRoot().addChild(pointsTransform);
    InlineShape pointsShape = InlinePointsShape("points", points);

    InlineInstance pointsInstance = InlineInstance("points", pointsTransform, pointsShape, vertexColorsShaderMaterial);
}

/*
** Output:


*/