void PrimitiveShapeRenderer::RenderWireframeBox( const Vector3& vEdgeLengths, const Matrix34& world_pose, const SFloatRGBAColor& wireframe_color )
{
	if( !sg_NoLightingShader.IsLoaded() )
		sg_NoLightingShader = GetNoLightingShader();

	// Wireframes are always rendered without lighting
	ShaderManager *pShaderMgr = sg_NoLightingShader.GetShaderManager();

//	ShaderManager *pShaderMgr = GetShaderManagerForPrimitiveShape();

	if( !pShaderMgr )
		return;

	ShaderManager& shader_mgr = *pShaderMgr;

	Result::Name res = shader_mgr.SetTexture( 0, GetSingleColorWhiteTexture() );
	res = shader_mgr.SetTexture( 1, GetSingleColorWhiteTexture() );

	Vector3 r( vEdgeLengths * 0.5f );
	shader_mgr.SetWorldTransform( ToMatrix44(world_pose) * Matrix44Scaling(r.x,r.y,r.z) );

//	Vector3 radii = vEdgeLengths * 0.5f;
	Vector3 vertices[8] =
	{
		Vector3( 1, 1, 1),// * radii,
		Vector3( 1, 1,-1),// * radii,
		Vector3(-1, 1,-1),// * radii,
		Vector3(-1, 1, 1),// * radii,
		Vector3( 1,-1, 1),// * radii,
		Vector3( 1,-1,-1),// * radii,
		Vector3(-1,-1,-1),// * radii,
		Vector3(-1,-1, 1),// * radii,
	};
/*
	uint indices[24] =
	{
		0, 1, 1, 2, 2, 3, 3, 0,
		0, 1, 1, 2, 2, 3, 3, 0,
		0, 1, 1, 2, 2, 3, 3, 0
	};

	GetPrimitiveRenderer().DrawIndexedLines( vertices, 8, indices, 24, wireframe_color );
*/
	Vector3 *v = vertices;
	const Vector3 points[24] =
	{
		v[0], v[1], v[1], v[2], v[2], v[3], v[3], v[0],
		v[0], v[4], v[1], v[5], v[2], v[6], v[3], v[7],
		v[4], v[5], v[5], v[6], v[6], v[7], v[7], v[4],
	};

	shader_mgr.Begin();

	const int num_edges = 12;
	for( int i=0; i<num_edges; i++ )
	{
		GetPrimitiveRenderer().DrawLine( points[i*2], points[i*2+1], wireframe_color, wireframe_color );
	}
}
ShaderManager *PrimitiveShapeRenderer::GetShaderManagerForPrimitiveShape()
{
	ShaderManager *pShaderMgr = m_Shader.GetShaderManager();

	if( pShaderMgr )
		return pShaderMgr;

	if( !sg_NoLightingShader.IsLoaded() )
		sg_NoLightingShader = GetNoLightingShader();

	return sg_NoLightingShader.GetShaderManager();
}
Пример #3
0
void ShadowMapDemo::RenderShadowReceivers( Camera& camera, ShaderHandle *shaders, ShaderTechniqueHandle *shader_techniques )
{
//	ShaderManager *pShaderMgr = m_pShadowMapManager->GetShader().GetShaderManager();
	ShaderHandle shader = shaders[VertexBlendType::NONE];
	ShaderManager *pShaderMgr = shader.GetShaderManager();
	if( !pShaderMgr )
		return;

	ShaderManager& shader_mgr = *pShaderMgr;

	ShaderTechniqueHandle tech = m_pShadowMapManager->ShaderTechniqueForShadowReceiver();
	Result::Name res = shader_mgr.SetTechnique( tech );

	RenderScene( shader_mgr );
}
void C2DPrimitiveRenderer_GL::Render( General2DVertex *paVertex, int num_vertices, PrimitiveType::Name primitive_type )
{
	ShaderHandle shader
		= sg_2DPrimitiveCommonShaders.GetShader( C2DPrimitiveCommonShaders::ST_DIFFUSE_COLOR );

	ShaderManager *pShaderMgr = shader.GetShaderManager();

	if( !pShaderMgr )
	{
		LOG_PRINT_ERROR( "The shader for 2D primitives is not available." );
		return;
	}

	pShaderMgr->Begin();

	RenderViaVertexAttribArray( paVertex, num_vertices, NULL, 0, ToGLPrimitiveType(primitive_type) );
}
void C2DPrimitiveRenderer_GL::Render( const General2DVertex *pVertices, uint num_vertices, U16 *indices, uint num_indices, PrimitiveType::Name primitive_type, TextureHandle texture )
{
	ShaderHandle shader
		= sg_2DPrimitiveCommonShaders.GetShader( C2DPrimitiveCommonShaders::ST_DIFFUSE_COLOR_AND_TEXTURE );

	ShaderManager *pShaderMgr = shader.GetShaderManager();

	if( !pShaderMgr )
	{
		return;
	}

	pShaderMgr->SetTexture( 0, texture );

	pShaderMgr->Begin();

	RenderViaVertexAttribArray( pVertices, num_vertices, indices, num_indices, ToGLPrimitiveType(primitive_type) );
}
Пример #6
0
void MiscShaderDemo::RenderMeshes()
{
	GraphicsDevice().Enable( RenderStateType::LIGHTING );
	GraphicsDevice().Enable( RenderStateType::DEPTH_TEST );
	GraphicsDevice().Enable( RenderStateType::FACE_CULLING );
	GraphicsDevice().SetCullingMode( CullingMode::COUNTERCLOCKWISE );

	GraphicsDevice().Enable( RenderStateType::ALPHA_BLEND );

	ShaderHandle shader = GetCurrentShader();
	ShaderManager *pShaderMgr = shader.GetShaderManager();

	if( !pShaderMgr )
		return;

	ShaderManager& shader_mgr = *pShaderMgr;

	// render the scene

	shader_mgr.SetViewerPosition( GetCurrentCamera().GetPosition() );

//	SetLights( pShaderMgr ? true : false );

	shader_mgr.SetWorldTransform( Matrix44Identity() );

//	GetShaderManagerHub().PushViewAndProjectionMatrices( GetCurrentCamera() );

	if( 2 < m_Meshes.size() )
	{
		boost::shared_ptr<BasicMesh> pMesh = m_Meshes[2].GetMesh();
		if( pMesh )
			pMesh->Render( shader_mgr );
	}

//	GetShaderManagerHub().PopViewAndProjectionMatrices_NoRestore();
}
Пример #7
0
void BaseEntity::RenderAsShadowReceiver(CCopyEntity* pCopyEnt)
{
	ONCE( LOG_PRINT_ERROR( " Not implemented yet." ) );

	PROFILE_FUNCTION();

	// set option to disable texture settings

	ShadowMapManager *pShadowMgr = m_pStage->GetEntitySet()->GetRenderManager()->GetShadowManager();
	if( !pShadowMgr )
		return;

	shared_ptr<BasicMesh> pMesh = pCopyEnt->m_MeshHandle.GetMesh();
	if( !pMesh )
		return;

	ShaderHandle shader = pShadowMgr->GetShader();
	ShaderManager *pShaderMgr = shader.GetShaderManager();
	if( !pShaderMgr )
		return;

	pShaderMgr->SetWorldTransform( pCopyEnt->GetWorldPose() );

	ShaderTechniqueHandle tech;
	const U32 entity_flags = pCopyEnt->GetEntityFlags();
	if( entity_flags & BETYPE_SHADOW_RECEIVER )
		tech = pShadowMgr->ShaderTechniqueForShadowReceiver( VertexBlendType::NONE );
	else // i.e. entity_flags & BETYPE_SHADOW_CASTER. See EntityNode::RenderShadowReceivers() for details.
		tech = pShadowMgr->ShaderTechniqueForNonShadowedCasters( VertexBlendType::NONE );

	pShaderMgr->SetTechnique( tech );

	pMesh->Render( *pShaderMgr );

/*	shared_ptr<MeshContainerRenderMethod> pMeshRenderMethod;
	const bool is_skeletal_mesh = (pMesh->GetMeshType() == MeshType::SKELETAL);
	if( is_skeletal_mesh )
	{
		pMeshRenderMethod = this->m_MeshProperty.m_pSkeletalShadowReceiverRenderMethod;

		shared_ptr<SkeletalMesh> pSkeletalMesh
			= dynamic_pointer_cast<SkeletalMesh,BasicMesh>(pMesh);

//		if( !this->m_MeshProperty.m_pBlendTransformsLoader )
//			InitShadowCasterReceiverSettings( pSkeletalMesh, this->m_MeshProperty );

		this->m_MeshProperty.m_pBlendTransformsLoader->SetSkeletalMesh( pSkeletalMesh );

//		pSkeletalMesh->SetLocalTransformToCache( 0, Matrix34Identity() );
//		pSkeletalMesh->SetLocalTransformsFromCache();
	}
	else
		pMeshRenderMethod = this->m_MeshProperty.m_pShadowReceiverRenderMethod;

	if( true )//render_all_subsets )
	{
//		pMeshRenderMethod->MeshRenderMethod().resize( 1 );
		SubsetRenderMethod& mesh_render_method = pMeshRenderMethod->MeshRenderMethod()[0];
		mesh_render_method.m_Shader    = pShadowMgr->GetShader();
//		const char *tech = is_skeletal_mesh ? "SceneShadowMap_VertexBlend" : "SceneShadowMap";
//		mesh_render_method.m_Technique.SetTechniqueName( tech );
		VertexBlendType::Name blend_type = is_skeletal_mesh ? VertexBlendType::QUATERNION_AND_VECTOR3 : VertexBlendType::NONE;
		mesh_render_method.m_Technique = pShadowMgr->ShaderTechniqueForShadowReceiver( blend_type );
//		render_method.SetMeshRenderMethod( mesh_render_method, 0 );
		pMeshRenderMethod->RenderMesh( pCopyEnt->m_MeshHandle, pCopyEnt->GetWorldPose() );
	}
	else
	{
		// how to render the mesh if each subset is rendered by different render methods
	}
*/
}