示例#1
0
LampTile::LampTile(int blockId, const std::string& texture, Material const* material) : Tile(blockId, texture, material) {
	init();
	if(isLit()) setLightEmission(1.0F);
	creativeTab = CreativeTab::ITEMS;
	setNameId("redstoneLight");
	destroyTime = 0.3F;
	soundType = &Tile::SOUND_GLASS;
}
示例#2
0
文件: Logic.C 项目: aehyvari/OpenSMT2
// A term is literal if its sort is Bool and
//  (i)   number of arguments is 0
//  (ii)  its symbol is sym_NOT and argument is a literal (nested nots
//        create literals?)
//  (iii) it is an atom stating an equivalence of non-boolean terms (terms must be purified at this point)
bool Logic::isLit(PTRef tr) const
{
    Pterm& t = getPterm(tr);
    if (sym_store[t.symb()].rsort() == getSort_bool()) {
        if (t.size() == 0) return true;
        if (t.symb() == getSym_not() ) return isLit(t[0]);
        // At this point all arguments of equivalence have the same sort.  Check only the first
        if (isEquality(tr) && (sym_store[getPterm(t[0]).symb()].rsort() != getSort_bool())) return true;
        if (isUP(tr)) return true;
    }
    return false;
}
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
}
示例#4
0
void Tree::draw(const Camera& camera, const vector<Light*>& lights)
{

	ID3DX11EffectScalarVariable* fx_time = getFX()->GetVariableByName("border")->AsScalar();
	fx_time->SetFloat(counter);
	
	
	if (bLeaves)
		_leaves.draw(camera, lights);

	// Material
	Mesh::setMaterial(getFX());

	context()->IASetInputLayout(getInputLayout());


	// World Matrix
	XMMATRIX mWorld = XMLoadFloat4x4(&(mtxWorld()));
	fx_m_World->SetMatrix((float*)&mWorld);
	fx_m_WorldViewProj->SetMatrix((float*)&(mWorld * camera.getViewMatrix() * camera.getProjectionMatrix()));
	fx_pEye->SetFloatVector((float*)&(camera.getPosVector3()));

	// Light // mView, shadow_map, light params
	for (unsigned int i=0; i<lights.size(); ++i)
	{
		fx_m_L_ViewProj =	getFX()->GetVariableByName("m_L_ViewProj")->GetElement(i)->AsMatrix();
		fx_lights =			getFX()->GetVariableByName("lights")->GetElement(i);
		fx_tex_shadow_map = getFX()->GetVariableByName("tex_shadow_map")->GetElement(i)->AsShaderResource();
		
		fx_m_L_ViewProj->SetMatrix(		(float*)&(lights[i]->getViewProjMatrix())	);
		fx_tex_shadow_map->SetResource(	lights[i]->getShadowMapSRV())	;
		fx_lights->SetRawValue(	(void*)&(lights[i]->getLightStructure()), 0, sizeof(Light_Params)	);
	}
	ID3DX11EffectScalarVariable*	fx_shadow_size = getFX()->GetVariableByName("shadow_size")->AsScalar();
	fx_shadow_size->SetInt(lights[0]->getShadowMapSize());
	fx_num_lights->SetInt(lights.size());
	

	fx_bShadowed->SetBool(isShadowReceiver());
	fx_bUsePCSS->SetBool(PCSS());

	ID3DX11EffectScalarVariable*  fx_bLit = getFX()->GetVariableByName("bLit")->AsScalar();
	fx_bLit->SetBool(isLit());

	if (render_mode == Tree::NonTexturedNonLitWireframe)
		Mesh::draw(0, getFX(), "Tree_NonTexturedNonLitWireframe"); 
	else if (render_mode == Tree::NonTexturedFlatShaded)
		Mesh::draw(0, getFX(), "Tree_NonTexturedFlatShaded"); 
	else if (render_mode == Tree::NonTexturedSmoothShaded)
		Mesh::draw(0, getFX(), "Tree_NonTexturedSmoothShaded");
	else if (render_mode == Tree::TexturedSmoothShaded)
		Mesh::draw(0, getFX(), "Tree");
	else
	{
		ID3DX11EffectShaderResourceVariable*	fx_tex_heightmap = getFX()->GetVariableByName("tex_heightmap")->AsShaderResource();
		fx_tex_heightmap->SetResource(srv_heightmap);

		Mesh::draw(0, getFX(), "Tree_DisplacementMapping");
	}

	for (unsigned int i=0; i<lights.size(); ++i) {
		fx_tex_shadow_map = getFX()->GetVariableByName("tex_shadow_map")->GetElement(i)->AsShaderResource();
		fx_tex_shadow_map->SetResource(0);
	}
	ID3DX11EffectTechnique* tech = getFX()->GetTechniqueByName("Tree");
	tech->GetPassByIndex(0)->Apply(0, context());

}
示例#5
0
//////////////////////////////////////////////////////////////////////////
// onAttach
//virtual
void ScnModelComponent::onAttach( ScnEntityWeakRef Parent )
{
	Super::onAttach( Parent );

	// Duplicate node data for update/rendering.
	BcU32 NoofNodes = Model_->pHeader_->NoofNodes_;
	pNodeTransformData_ = new ScnModelNodeTransformData[ NoofNodes ];
	BcMemCopy( pNodeTransformData_, Model_->pNodeTransformData_, sizeof( ScnModelNodeTransformData ) * NoofNodes );

	// Create material instances to render with.
	ScnModelMeshRuntimeList& MeshRuntimes = Model_->MeshRuntimes_;
	ScnMaterialComponentRef MaterialComponentRef;
	PerComponentMeshDataList_.reserve( MeshRuntimes.size() );
	for( BcU32 Idx = 0; Idx < MeshRuntimes.size(); ++Idx )
	{
		ScnModelMeshData* pMeshData = &Model_->pMeshData_[ Idx ];
		ScnModelMeshRuntime* pMeshRuntime = &MeshRuntimes[ Idx ];
		TPerComponentMeshData ComponentData;

		if( pMeshRuntime->MaterialRef_.isValid() )
		{
			BcAssert( pMeshRuntime->MaterialRef_.isValid() && pMeshRuntime->MaterialRef_->isReady() );

			ScnShaderPermutationFlags ShaderPermutation = pMeshData->ShaderPermutation_;

			// Setup lighting.
			if( isLit() )
			{
				ShaderPermutation |= ScnShaderPermutationFlags::LIGHTING_DIFFUSE;
			}
			else
			{
				ShaderPermutation |= ScnShaderPermutationFlags::LIGHTING_NONE;
			}
						
			// Even on failure add. List must be of same size for quick lookups.
			ComponentData.MaterialComponentRef_ = Parent->attach< ScnMaterialComponent >( 
				BcName::INVALID, pMeshRuntime->MaterialRef_, ShaderPermutation );
		}

		// Create uniform buffer for object.
		if( pMeshData->IsSkinned_ )
		{
			ComponentData.UniformBuffer_ = RsCore::pImpl() ? 
				RsCore::pImpl()->createBuffer( 
					RsBufferDesc( 
						RsBufferType::UNIFORM,
						RsResourceCreationFlags::STREAM,
						ScnShaderBoneUniformBlockData::StaticGetClass()->getSize() ) ) : nullptr;
		}
		else
		{
			ComponentData.UniformBuffer_ = RsCore::pImpl() ? 
				RsCore::pImpl()->createBuffer( 
					RsBufferDesc( 
						RsBufferType::UNIFORM,
						RsResourceCreationFlags::STREAM,
						ScnShaderObjectUniformBlockData::StaticGetClass()->getSize() ) ) : nullptr;
		}

		//
		PerComponentMeshDataList_.push_back( ComponentData );
	}

	// Update nodes.
	UpdateFence_.increment();
	updateNodes( BaseTransform_ * getParentEntity()->getWorldMatrix() );
}
    virtual void addVertex(Vertex& vertex)
    {
        osg::Vec3Array* vertices = getOrCreateVertexArray(*_geometry);
        vertices->push_back(vertex._coord);

        if (isGouraud())
        {
            osg::Vec4Array* colors = getOrCreateColorArray(*_geometry);
            if (vertex.validColor())
            {
                colors->push_back(vertex._color);
            }
            else
            {
                // Use face color if vertex color is -1 in a gouraud polygon.
                // http://www.multigen-paradigm.com/ubb/Forum1/HTML/000967.html
                // Incorporate Face transparency per osg-users thread "Open Flight
                // characteristic not reflected in the current OSG" (Sept/Oct 2011)
                colors->push_back(osg::Vec4(_primaryColor.r(), _primaryColor.g(),
                    _primaryColor.b(), ( 1.0 - getTransparency() ) ));
            }
        }

        bool strict = false; // prepare for "strict" reader option.
        if (strict)
        {
            if (vertex.validNormal())
            {
                osg::Vec3Array* normals = getOrCreateNormalArray(*_geometry);
                normals->push_back(vertex._normal);
            }
        }
        else
        {
            // Add normal only if lit.
            if (isLit())
            {
                osg::Vec3Array* normals = getOrCreateNormalArray(*_geometry);

                if (vertex.validNormal())
                    normals->push_back(vertex._normal);
                else // if lit and no normal in Vertex
                {
                    // Use previous normal if available.
                    if (normals->empty())
                        normals->push_back(osg::Vec3(0,0,1));
                    else
                        normals->push_back(normals->back());
                }
            }
        }

        for (int layer=0; layer<Vertex::MAX_LAYERS; layer++)
        {
            if (vertex.validUV(layer))
            {
                osg::Vec2Array* UVs = getOrCreateTextureArray(*_geometry,layer);
                UVs->push_back(vertex._uv[layer]);
            }
        }
    }
示例#7
0
GlowComponent::GlowComponent(const bool& lit, const int& glowCount)
{
    mGlowCount = glowCount;
    isLit(lit);
}
示例#8
0
void LampTile::tick(TileSource* region, int x, int y, int z, Random* random) {
	if(isLit() && !region->isBlockIndirectlyGettingPowered(x, y, z))
		region->setTileAndData(x, y, z, {Tile::offlamp->id, 0}, 3);
}
示例#9
0
void LampTile::neighborChanged(TileSource* region, int x, int y, int z, int newX, int newY, int newZ) {
	if(isLit() && !region->isBlockIndirectlyGettingPowered(x, y, z))
		region->scheduleBlockUpdate(x, y, z, id, 4);
	else if(!isLit() && region->isBlockIndirectlyGettingPowered(x, y, z))
		region->setTileAndData(x, y, z, {Tile::onlamp->id, 0}, 3);
}