Exemplo n.º 1
0
	void main1_3(void *arg)
	{
		color Kd = color(diffuse(), diffuse(), diffuse());

		normal Nf = faceforward(normalize(N()), I());
		vector V = -normalize(I());

		while (illuminance(P(), Nf, PI / 2.0f))
		{
			color C = 0.0f;
			SAMPLE_LIGHT_2(color, C, 0.0f,
				C += Cl() * (
					color_() * Kd * (normalize(L()) % Nf) 
					+ cosinePower() * specularColor() * specularbrdf(normalize(L()), Nf, V, 0.1f/*roughness()*/)
					)
				);

			Ci() += C;
		}

		if ( ! less_than( &transparency(), LIQ_SCALAR_ALMOST_ZERO ) )
		{//transparent
			Ci() = Ci() * ( 1.0f - transparency() ) + trace_transparent() * transparency();
		}//else{ opacity }
		setOutputForMaya();
	}
Exemplo n.º 2
0
QString PictureShape::saveStyle(KOdfGenericStyle& style, KShapeSavingContext& context) const
{
    if (transparency() > 0.0) {
        style.addProperty("draw:image-opacity", QString("%1%").arg((1.0 - transparency()) * 100.0));
    }
    return KShape::saveStyle(style, context);
}
Exemplo n.º 3
0
void MinimapGui::renderMap(Renderer& renderer, Rectangle target) {
  mapBufferTex.update(mapBuffer);
  renderer.drawImage(target, info.bounds, mapBufferTex);
  Vec2 topLeft = target.getTopLeft();
  double scale = min(double(target.getW()) / info.bounds.getW(),
      double(target.getW()) / info.bounds.getH());
  for (Vec2 v : info.roads) {
    Vec2 rrad(1, 1);
    Vec2 pos = topLeft + (v - info.bounds.getTopLeft()) * scale;
    if (pos.inRectangle(target.minusMargin(rrad.x)))
      renderer.drawFilledRectangle(Rectangle(pos - rrad, pos + rrad), colors[ColorId::BROWN]);
  }
  Vec2 rad(3, 3);
  Vec2 player = topLeft + (info.player - info.bounds.getTopLeft()) * scale;
  if (player.inRectangle(target.minusMargin(rad.x)))
    renderer.drawFilledRectangle(Rectangle(player - rad, player + rad), colors[ColorId::BLUE]);
  for (Vec2 pos : info.enemies) {
    Vec2 v = (pos - info.bounds.getTopLeft()) * scale;
    renderer.drawFilledRectangle(Rectangle(topLeft + v - rad, topLeft + v + rad), colors[ColorId::RED]);
  }
  for (auto loc : info.locations) {
    Vec2 v = (loc.pos - info.bounds.getTopLeft()) * scale;
    if (loc.text.empty())
      renderer.drawText(colors[ColorId::LIGHT_GREEN], topLeft.x + v.x + 5, topLeft.y + v.y, "?");
    else {
      renderer.drawFilledRectangle(topLeft.x + v.x, topLeft.y + v.y,
          topLeft.x + v.x + renderer.getTextLength(loc.text) + 10, topLeft.y + v.y + 25,
          transparency(colors[ColorId::BLACK], 130));
      renderer.drawText(colors[ColorId::WHITE], topLeft.x + v.x + 5, topLeft.y + v.y, loc.text);
    }
  }
}
Exemplo n.º 4
0
	void main1(void *arg)
	{
		color Kd = color(diffuse(), diffuse(), diffuse());

		normal Nf = faceforward(normalize(N()), I());
		vector V = -normalize(I());

		while (illuminance(P(), Nf, PI / 2.0f))
		{
			color	C = 0.0f;
			color	last = 0.0f;
			int		num_samples = 0;

			while (sample_light())
			{
				C += Cl() * (
					color_() * Kd * (normalize(L()) % Nf) 
					+ cosinePower() * specularColor() * specularbrdf(normalize(L()), Nf, V, 0.1f/*roughness()*/)
					);

				++ num_samples;

				if ((num_samples % 4) == 0)
				{
					color	current = C * (1.0f / (scalar)num_samples);

					if (converged(current, last)){
						break;
					}
					last = current;
				}
			}

			C *= (1.0f / (scalar)num_samples);
			Ci() += C;
		}

		if ( ! less_than( &transparency(), LIQ_SCALAR_ALMOST_ZERO ) )
		{//transparent
			Ci() = Ci() * ( 1.0f - transparency() ) + trace_transparent() * transparency();
		}//else{ opacity }
		setOutputForMaya();
	}
Exemplo n.º 5
0
//
// DESCRIPTION:
///////////////////////////////////////////////////////
MStatus DispNode::compute(
const MPlug&      plug,
      MDataBlock& block ) 
{ 
    if ((plug == aOutColor) || (plug.parent() == aOutColor) ||
		(plug == aOutDisplacement))
	{
		MFloatVector resultColor(0.0,0.0,0.0);

		MFloatVector&  InputColor = block.inputValue( aColor ).asFloatVector();
		float MultValue = block.inputValue( aInputValue ).asFloat();

		resultColor = InputColor;

		float scalar = resultColor[0] + resultColor[1] + resultColor[2];
		if (scalar != 0.0) {
			scalar /= 3.0;
			scalar *= MultValue;
		}

		// set ouput color attribute
		MDataHandle outColorHandle = block.outputValue( aOutColor );
		MFloatVector& outColor = outColorHandle.asFloatVector();
		outColor = resultColor;
		outColorHandle.setClean();

		MDataHandle outDispHandle = block.outputValue( aOutDisplacement );
		float& outDisp = outDispHandle.asFloat();
		outDisp = scalar;
		outDispHandle.setClean( );
	}
	else if ((plug == aOutTransparency) || (plug.parent() == aOutTransparency))
	{
		// set output transparency to be opaque
		MFloatVector transparency(0.0,0.0,0.0);
		MDataHandle outTransHandle = block.outputValue( aOutTransparency );
		MFloatVector& outTrans = outTransHandle.asFloatVector();
		outTrans = transparency;
		outTransHandle.setClean( );
	}
	else
		return MS::kUnknownParameter;

    return MS::kSuccess;
}
Exemplo n.º 6
0
Point3D RayPointLight::transparency(RayIntersectionInfo& iInfo,RayShape* shape,Point3D cLimit){
	Point3D temp = location - iInfo.iCoordinate;
	double dist = sqrt(temp.dot(temp));
	double atten = 0;
	atten = (constAtten + (linearAtten*dist) + (quadAtten*pow(dist,2.0)));

	Ray3D testRay = Ray3D();
	
	testRay.direction = temp.unit();
	testRay.position = iInfo.iCoordinate + testRay.direction;

	Point3D out = Point3D(1,1,1);	

	if(shape->intersect(testRay, iInfo, dist) != -1){		
		Point3D trans = iInfo.material->transparent;
		out = out * trans;
		out = out * transparency(iInfo, shape, cLimit / trans);
	}
	//1 = inShadow, 0 = no shadow
	return out;
}
void
FltExportVisitor::writeMesh( const osg::Geode& geode, const osg::Geometry& geom )
{
    enum DrawMode
    {
        SOLID_BACKFACE = 0,
        SOLID_NO_BACKFACE = 1,
        WIREFRAME_CLOSED = 2,
        WIREFRAME_NOT_CLOSED = 3,
        SURROUND_ALTERNATE_COLOR = 4,
        OMNIDIRECTIONAL_LIGHT = 8,
        UNIDIRECTIONAL_LIGHT = 9,
        BIDIRECTIONAL_LIGHT = 10
    };
    enum TemplateMode
    {
        FIXED_NO_ALPHA_BLENDING = 0,
        FIXED_ALPHA_BLENDING = 1,
        AXIAL_ROTATE_WITH_ALPHA_BLENDING = 2,
        POINT_ROTATE_WITH_ALPHA_BLENDING = 4
    };

    // const unsigned int TERRAIN_BIT      = 0x80000000u >> 0;
    //const unsigned int NO_COLOR_BIT     = 0x80000000u >> 1;
    //const unsigned int NO_ALT_COLOR_BIT = 0x80000000u >> 2;
    const unsigned int PACKED_COLOR_BIT = 0x80000000u >> 3;
    //const unsigned int FOOTPRINT_BIT    = 0x80000000u >> 4;    // Terrain culture cutout
    const unsigned int HIDDEN_BIT       = 0x80000000u >> 5;
    //const unsigned int ROOFLINE_BIT     = 0x80000000u >> 6;
    uint32 flags( PACKED_COLOR_BIT );
    if (geode.getNodeMask() == 0)
        flags |= HIDDEN_BIT;

    enum LightMode
    {
        FACE_COLOR = 0,
        VERTEX_COLOR = 1,
        FACE_COLOR_LIGHTING = 2,
        VERTEX_COLOR_LIGHTING = 3
    };
    int8 lightMode;
    osg::Vec4 packedColorRaw( 1., 1., 1., 1. );
    uint16 transparency( 0 );
    if (geom.getColorBinding() == osg::Geometry::BIND_PER_VERTEX)
    {
        if (isLit( geom ))
            lightMode = VERTEX_COLOR_LIGHTING;
        else
            lightMode = VERTEX_COLOR;
    }
    else
    {
        const osg::Vec4Array* c = dynamic_cast<const osg::Vec4Array*>( geom.getColorArray() );
        if (c && (c->size() > 0))
        {
            packedColorRaw = (*c)[0];
            transparency = flt::uint16((1. - packedColorRaw[3]) * (double)0xffff);
        }

        if (isLit( geom ))
            lightMode = FACE_COLOR_LIGHTING;
        else
            lightMode = FACE_COLOR;
    }
    uint32 packedColor;
    packedColor = (int)(packedColorRaw[3]*255) << 24 |
        (int)(packedColorRaw[2]*255) << 16 | (int)(packedColorRaw[1]*255) << 8 |
        (int)(packedColorRaw[0]*255);


    int8 drawType;
    osg::StateSet const* ss = getCurrentStateSet();

    {
        // Default to no facet culling
        drawType = SOLID_NO_BACKFACE;

        // If facet-culling isn't *dis*abled, check whether the CullFace mode is BACK
        if (ss->getMode(GL_CULL_FACE) & osg::StateAttribute::ON)
        {
            osg::CullFace const* cullFace = static_cast<osg::CullFace const*>(
                ss->getAttribute(osg::StateAttribute::CULLFACE) );
            if( cullFace->getMode() == osg::CullFace::BACK )
                drawType = SOLID_BACKFACE;

            // Note: OpenFlt can't handle FRONT or FRONT_AND_BACK settings, so ignore these(??)
        }
    }

    // Determine the material properties for the face
    int16 materialIndex( -1 );
    if (isLit( geom ))
    {
        osg::Material const* currMaterial = static_cast<osg::Material const*>(
            ss->getAttribute(osg::StateAttribute::MATERIAL) );
        materialIndex = _materialPalette->add(currMaterial);
    }

    // Get base texture
    int16 textureIndex( -1 );
    if (isTextured( 0, geom ))
    {
        const osg::Texture2D* texture = static_cast<const osg::Texture2D*>(
            ss->getTextureAttribute( 0, osg::StateAttribute::TEXTURE )  );
        if (texture != NULL)
            textureIndex = _texturePalette->add( 0, texture );
        else
        {
            std::string warning( "fltexp: Mesh is textured, but Texture2D StateAttribute is NULL." );
            osg::notify( osg::WARN ) << warning << std::endl;
            _fltOpt->getWriteResult().warn( warning );
        }
    }

    // Set the appropriate template mode based
    // on blending or Billboarding.
    TemplateMode templateMode( FIXED_NO_ALPHA_BLENDING );
    const osg::Billboard* bb = dynamic_cast< const osg::Billboard* >( &geode );
    if (bb != NULL)
    {
        if( bb->getMode() == osg::Billboard::AXIAL_ROT )
            templateMode = AXIAL_ROTATE_WITH_ALPHA_BLENDING;
        else
            templateMode = POINT_ROTATE_WITH_ALPHA_BLENDING;
    }
    else if ( ss->getMode( GL_BLEND ) & osg::StateAttribute::ON )
    {
        const osg::BlendFunc* bf = static_cast<const osg::BlendFunc*>(
            ss->getAttribute(osg::StateAttribute::BLENDFUNC) );
        if( (bf->getSource() == osg::BlendFunc::SRC_ALPHA) &&
            (bf->getDestination() == osg::BlendFunc::ONE_MINUS_SRC_ALPHA) )
            templateMode = FIXED_ALPHA_BLENDING;
    }


    uint16 length( 84 );
    IdHelper id( *this, geode.getName() );

    _records->writeInt16( (int16) MESH_OP );
    _records->writeUInt16( length );
    _records->writeID( id );
    _records->writeInt32( 0 ); // Reserved
    _records->writeInt32( 0 ); // IR color code
    _records->writeInt16( 0 ); // Relative priority
    _records->writeInt8( drawType ); // Draw type
    _records->writeInt8( 0 ); // Texture white
    _records->writeInt16( -1 ); // Color name index
    _records->writeInt16( -1 ); // Alternate color name index
    _records->writeInt8( 0 ); // Reserved
    _records->writeInt8( templateMode ); // Template (billboard)
    _records->writeInt16( -1 ); // Detail texture pattern index
    _records->writeInt16( textureIndex ); // Texture pattern index
    _records->writeInt16( materialIndex ); // Material index
    _records->writeInt16( 0 ); // Surface material code
    _records->writeInt16( 0 ); // Feature ID
    _records->writeInt32( 0 ); // IR material code
    _records->writeUInt16( transparency ); // Transparency
    _records->writeInt8( 0 ); // LOD generation control
    _records->writeInt8( 0 ); // Line style index
    _records->writeUInt32( flags ); // Flags
    _records->writeInt8( lightMode ); // Light mode
    _records->writeFill( 7 ); // Reserved
    _records->writeUInt32( packedColor ); // Packed color, primary
    _records->writeUInt32( 0x00ffffff ); // Packed color, alternate
    _records->writeInt16( -1 ); // Texture mapping index
    _records->writeInt16( 0 ); // Reserved
    _records->writeInt32( -1 ); // Primary color index
    _records->writeInt32( -1 ); // Alternate color index
    // Next four bytes:
    //   15.8: two 2-byte "reserved" fields
    //   15.9: one 4-byte "reserved" field
    _records->writeInt16( 0 ); // Reserved
    _records->writeInt16( -1 ); // Shader index
}
Exemplo n.º 8
0
QString PictureShape::saveStyle(KoGenStyle& style, KoShapeSavingContext& context) const
{
    if(transparency() > 0.0) {
        style.addProperty("draw:image-opacity", QString("%1%").arg((1.0 - transparency()) * 100.0));
    }

    // this attribute is need to work around a bug in LO 3.4 to make it recognice us as an
    // image and not just any shape. But we shouldn't produce illegal odf so: only for testing!
    // style.addAttribute("style:parent-style-name", "dummy");

    // Mirroring
    if (m_mirrorMode != MirrorNone) {
        QString mode;

        if (m_mirrorMode & MirrorHorizontal)
            mode = "horizontal";
        else if (m_mirrorMode & MirrorHorizontalOnEven)
            mode = "horizontal-on-even";
        else if (m_mirrorMode & MirrorHorizontalOnOdd)
            mode = "horizontal-on-odd";

        if (m_mirrorMode & MirrorVertical) {
            if (!mode.isEmpty())
                mode += ' ';
            mode += "vertical";
        }

        style.addProperty("style:mirror", mode);
    }

    switch(m_colorMode)
    {
    case Standard:
        style.addProperty("draw:color-mode", "standard");
        break;
    case Greyscale:
        style.addProperty("draw:color-mode", "greyscale");
        break;
    case Watermark:
        style.addProperty("draw:color-mode", "watermark");
        break;
    case Mono:
        style.addProperty("draw:color-mode", "mono");
        break;
    }

    KoImageData *imageData = qobject_cast<KoImageData*>(userData());

    if (imageData != 0) {
        QSizeF imageSize = imageData->imageSize();
        ClippingRect rect = m_clippingRect;

        rect.normalize(imageSize);
        rect.bottom = 1.0 - rect.bottom;
        rect.right = 1.0 - rect.right;

        if (!qFuzzyCompare(rect.left + rect.right + rect.top + rect.bottom, qreal(0))) {
            style.addProperty("fo:clip", QString("rect(%1pt, %2pt, %3pt, %4pt)")
                .arg(rect.top * imageSize.height())
                .arg(rect.right * imageSize.width())
                .arg(rect.bottom * imageSize.height())
                .arg(rect.left * imageSize.width())
            );
        }
    }

    return KoTosContainer::saveStyle(style, context);
}
Exemplo n.º 9
0
void drawFrame(GifFileType* gif, AndroidBitmapInfo*  info, int* pixels, int frame_no, bool force_dispose_1) {
  GifColorType *bg;
  GifColorType *color;
  SavedImage * frame;
  ExtensionBlock * ext = 0;
  GifImageDesc * frameInfo;
  ColorMapObject * colorMap;
  int *line;
  int width, height,x,y,j,loc,n,inc,p;
  int* px;

  width = gif->SWidth;
  height = gif->SHeight;

  frame = &(gif->SavedImages[frame_no]);
  frameInfo = &(frame->ImageDesc);
  if (frameInfo->ColorMap) {
      colorMap = frameInfo->ColorMap;
    } else {
      colorMap = gif->SColorMap;
  }

  bg = &colorMap->Colors[gif->SBackGroundColor];

  for (j=0; j<frame->ExtensionBlockCount; j++) {
    if (frame->ExtensionBlocks[j].Function == GRAPHICS_EXT_FUNC_CODE) {
      ext = &(frame->ExtensionBlocks[j]);
      break;
    }
  }

  // For dispose = 1, we assume its been drawn
  px = pixels;
  if (ext && dispose(ext) == 1 && force_dispose_1 && frame_no > 0) {
    drawFrame(gif, info, pixels, frame_no-1, true);
  }
  else if (ext && dispose(ext) == 2 && bg) {
    for (y=0; y<height; y++) {
      line = (int*) px;
      for (x=0; x<width; x++) {
        line[x] = argb(255, bg->Red, bg->Green, bg->Blue);
      }
      px = (char*)px + info->stride;
    }
  } else if (ext && dispose(ext) == 3 && frame_no > 1) {
    drawFrame(gif, info, pixels, frame_no-2, true);
  }
  px = pixels;
  if (frameInfo->Interlace && false) {
    n = 0;
    inc = 8;
    p = 0;
    px = (char*)px + info->stride*frameInfo->Top;
    for (y=frameInfo->Top; y<frameInfo->Top+frameInfo->Height; y++) {
      for (x=frameInfo->Left; x<frameInfo->Left+frameInfo->Width; x++) {
        loc = (y - frameInfo->Top)*frameInfo->Width + (x - frameInfo->Left);
        if (ext && frame->RasterBits[loc] == trans_index(ext) && transparency(ext)) {
          continue;
        }

        color = (ext && frame->RasterBits[loc] == trans_index(ext)) ? bg : &colorMap->Colors[frame->RasterBits[loc]];
        if (color)
          line[x] = argb(255, color->Red, color->Green, color->Blue);
      }
      px = (char*)px + info->stride*inc;
      n += inc;
      if (n >= frameInfo->Height) {
        n = 0;
        switch(p) {
          case 0:
          px = (char *)pixels + info->stride*(4+frameInfo->Top);
          inc = 8;
          p++;
          break;
          case 1:
          px = (char *)pixels + info->stride*(2+frameInfo->Top);
          inc = 4;
          p++;
          break;
          case 2:
          px = (char *)pixels + info->stride*(1+frameInfo->Top);
          inc = 2;
          p++;
        }
      }
    }
  }
  else {
    px = (char*)px + info->stride*frameInfo->Top;
    for (y=frameInfo->Top; y<frameInfo->Top+frameInfo->Height; y++) {
      line = (int*) px;
      for (x=frameInfo->Left; x<frameInfo->Left+frameInfo->Width; x++) {
        loc = (y - frameInfo->Top)*frameInfo->Width + (x - frameInfo->Left);
        if (ext && frame->RasterBits[loc] == trans_index(ext) && transparency(ext)) {
          continue;
        }
        color = (ext && frame->RasterBits[loc] == trans_index(ext)) ? bg : &colorMap->Colors[frame->RasterBits[loc]];
        if (color)
        	line[x] = argb(255, color->Red, color->Green, color->Blue);
      }
      px = (char*)px + info->stride;
    }
  }
}
Exemplo n.º 10
0
//
// DESCRIPTION:
///////////////////////////////////////////////////////
MStatus VolumeNode::compute(const MPlug& plug, MDataBlock& block ) 
{ 
    if ((plug != aOutColor) && (plug.parent() != aOutColor) && 
		(plug != aOutTransparency) && (plug.parent() != aOutTransparency))
		return MS::kUnknownParameter;


    MFloatVector&  InputColor = block.inputValue( aColor ).asFloatVector();
    float Distance = block.inputValue( aInputValue ).asFloat();

    MFloatVector&  FarCamera = block.inputValue( aFarPointC ).asFloatVector();
    MFloatVector&  FarObject = block.inputValue( aFarPointO ).asFloatVector();
    MFloatVector&  FarWorld = block.inputValue( aFarPointW ).asFloatVector();
    MFloatVector&  PointCam = block.inputValue( aPointC ).asFloatVector();
    MFloatVector&  PointObj = block.inputValue( aPointO ).asFloatVector();
    MFloatVector&  PointWor = block.inputValue( aPointW ).asFloatVector();

    bool  Camera  = block.inputValue( aToggleCamera ).asBool();
    bool  Object  = block.inputValue( aToggleObject ).asBool();
    bool  World   = block.inputValue( aToggleWorld ).asBool();

    MFloatVector interval(0.0,0.0,0.0);
    if (Camera) {
		interval = FarCamera - PointCam;
    }
    if (Object) {
		interval = FarObject - PointObj;
    }
    if (World) {
		interval = FarWorld - PointWor;
    }

    double value,dist;
    if ((value = ((interval[0]*interval[0]) +
				 (interval[1]*interval[1]) + 
                 (interval[2]*interval[2])) ))
    {
		dist = sqrt ( value );
    }
    else dist = 0.0;

    MFloatVector resultColor(0.0,0.0,0.0);
    if (dist <= Distance) {
	    resultColor[0] = InputColor[0];
	    resultColor[1] = InputColor[1];
	    resultColor[2] = InputColor[2];
    }

    // set ouput color attribute
    MDataHandle outColorHandle = block.outputValue( aOutColor );
    MFloatVector& outColor = outColorHandle.asFloatVector();
    outColor = resultColor;
    outColorHandle.setClean();

    // set output transparency
    MFloatVector transparency(resultColor[2],resultColor[2],resultColor[2]);
    MDataHandle outTransHandle = block.outputValue( aOutTransparency );
    MFloatVector& outTrans = outTransHandle.asFloatVector();
    outTrans = transparency;
    outTransHandle.setClean( );
 
    MDataHandle outAlphaHandle = block.outputValue( aOutAlpha );
    float& outAlpha = outAlphaHandle.asFloat();
    outAlpha = resultColor[2];
    outAlphaHandle.setClean( );

    return MS::kSuccess;
}