Ejemplo n.º 1
0
void SurfaceVisual::initialize()
{
	m_VertexBuffer.resize( 4 );
	m_VertexBuffer.allocHostMemory();
	m_VertexBuffer[ 0 ] = LineVertex( 0.0f, 0.0f );
	m_VertexBuffer[ 1 ] = LineVertex( 0.0f, 1.0f );
	m_VertexBuffer[ 2 ] = LineVertex( 1.0f, 1.0f );
	m_VertexBuffer[ 3 ] = LineVertex( 1.0f, 0.0f );
	m_VertexBuffer.copyToDevice();

	ShaderManager& shaders = engine.shaders;
	m_pVertexShader =
		shaders.getShader<Shader::Type::Vertex>( "line" );
	m_pTessControlShader =
		shaders.getShader<Shader::Type::TessellationControl>( "surface" );
	m_pTessEvalShader =
		Shader::fromName( Shader::Type::TessellationEvaluation, "surface" );
	m_pFragmentShader =
		shaders.getShader<Shader::Type::Fragment>( "line" );

//	setFunction( GpuFunctionSource( 2, 3,
//				"return vec3( v, 0.0 );" ) );
	setFunction( GpuFunctionSource( 2, 3,
				"float R = 2.0;\n"
				"float rmin = 1.0;\n"
				"float rmax = R;\n"
				"float s = R - v.y * ( ( rmax - rmin ) * 0.5 * ( sin( t ) + 1.0 ) + rmin );\n"
				"return vec3( 10.0 * v.x - sin( 0.5 * t ) * 2.0 * ( ( s / R - 1.0 ) * ( s / R - 1.0 ) ), s * 2.0 * sin( 1.0 * f_time + PERIODS * v.x * TWO_PI ), s * 2.0 * cos( 1.0 * f_time + PERIODS * v.x * TWO_PI ) );" ) );
}
Ejemplo n.º 2
0
/** Plots a vector of floats */
void BaseLineRenderer::PlotNumbers(const std::vector<float>& values, const D3DXVECTOR3& location, const D3DXVECTOR3& direction, float distance, float heightScale, const D3DXVECTOR4& color)
{
	for(unsigned int i=1;i<values.size();i++)
	{
		AddLine(LineVertex(location + (direction * (float)(i-1) * distance) + D3DXVECTOR3(0,0,values[i-1]*heightScale), color), 
				LineVertex(location + (direction * (float)i * distance) + D3DXVECTOR3(0,0,values[i]*heightScale), color));
	}
}
Ejemplo n.º 3
0
/** Adds a ring to the renderlist */
void BaseLineRenderer::AddRingZ(const D3DXVECTOR3& location, float size, const D3DXVECTOR4& color, int res)
{
	std::vector<D3DXVECTOR3> points;
	float step = (float)(D3DX_PI * 2) / (float)res;

	for(int i=0;i<res;i++)
	{
		points.push_back(D3DXVECTOR3(size * sinf(step * i) + location.x, size * cosf(step * i) + location.y, location.z));
	}

	for(unsigned int i=0; i<points.size()-1;i++)
	{
		AddLine(LineVertex(points[i], color), LineVertex(points[i+1], color));
	}

	AddLine(LineVertex(points[points.size()-1], color), LineVertex(points[0], color));
}
Ejemplo n.º 4
0
/** Visualizes the grass-meshes */
void GVegetationBox::VisualizeGrass(const D3DXVECTOR4& color)
{
	// Draw bounding box
	Engine::GraphicsEngine->GetLineRenderer()->AddAABBMinMax(BoxMin, BoxMax, color);

	// Draw grass
	for(unsigned int i=0;i<VegetationSpots.size();i++)
	{
		if(i % 10 != 0)
			continue; // Only render every 10th grassmesh

		D3DXVECTOR3 spot = D3DXVECTOR3(VegetationSpots[i]._14, VegetationSpots[i]._24, VegetationSpots[i]._34); 
		D3DXVECTOR3 scale = D3DXVECTOR3(0,0,0);
		D3DXVECTOR4* m = (D3DXVECTOR4*)&VegetationSpots[i];

		// Compute scale
		//scale.x = D3DXVec3Length((D3DXVECTOR3 *)&m[0]);
		scale.y = D3DXVec3Length((D3DXVECTOR3 *)&m[1]);
		//scale.z = D3DXVec3Length((D3DXVECTOR3 *)&m[2]);

		Engine::GraphicsEngine->GetLineRenderer()->AddLine(LineVertex(spot, color), LineVertex(spot + scale * 2.0f, color));
	}
}
Ejemplo n.º 5
0
/** Adds a point locator to the renderlist */
void BaseLineRenderer::AddPointLocator(const D3DXVECTOR3& location, float size, const D3DXVECTOR4& color)
{
	D3DXVECTOR3 u = location; u.z += size;
	D3DXVECTOR3 d = location; d.z -= size;

	D3DXVECTOR3 r = location; r.x += size;
	D3DXVECTOR3 l = location; l.x -= size;

	D3DXVECTOR3 b = location; b.y += size;
	D3DXVECTOR3 f = location; f.y -= size;

	AddLine(LineVertex(u, color), LineVertex(d, color));
	AddLine(LineVertex(r, color), LineVertex(l, color));
	AddLine(LineVertex(f, color), LineVertex(b, color));
}
Ejemplo n.º 6
0
/** Adds a plane to the renderlist */
void BaseLineRenderer::AddPlane(const D3DXVECTOR4& plane, const D3DXVECTOR3& origin, float size, const D3DXVECTOR4& color)
{
	D3DXVECTOR3 pNormal = D3DXVECTOR3(plane);

	D3DXVECTOR3 DebugPlaneP1;
	DebugPlaneP1.x = 1;
	DebugPlaneP1.y = 1;
	DebugPlaneP1.z = ((-plane.x - plane.y) / plane.z);

	D3DXVec3Normalize(&DebugPlaneP1,&DebugPlaneP1);

	D3DXVECTOR3 DebugPlaneP2;
	D3DXVec3Cross(&DebugPlaneP2, &pNormal, &DebugPlaneP1);

	//DebugPlaneP2 += SlidingPlaneOrigin;
	D3DXVECTOR3& p1 = DebugPlaneP1;
	D3DXVECTOR3& p2 = DebugPlaneP2;
	D3DXVECTOR3 O = origin;

	D3DXVECTOR3 from; D3DXVECTOR3 to;
	from = (O - p1) - p2; 
	to = (O - p1) + p2; 
	AddLine(LineVertex(from), LineVertex(to));

	from = (O - p1) + p2; 
	to = (O + p1) + p2; 
	AddLine(LineVertex(from), LineVertex(to));

	from = (O + p1) + p2; 
	to = (O + p1) - p2; 
	AddLine(LineVertex(from), LineVertex(to));

	from = (O + p1) - p2; 
	to = (O - p1) - p2; 
	AddLine(LineVertex(from), LineVertex(to));
}
Ejemplo n.º 7
0
/** Adds an AABB-Box to the renderlist */
void BaseLineRenderer::AddAABB(const D3DXVECTOR3& location, float halfSize, const D3DXVECTOR4& color)
{
	// Bottom -x -y -z to +x -y -z
	AddLine(LineVertex(D3DXVECTOR3(location.x - halfSize, location.y - halfSize, location.z - halfSize), color), LineVertex(D3DXVECTOR3(location.x + halfSize, location.y - halfSize, location.z - halfSize), color));

	AddLine(LineVertex(D3DXVECTOR3(location.x + halfSize, location.y - halfSize, location.z - halfSize), color), LineVertex(D3DXVECTOR3(location.x + halfSize, location.y + halfSize, location.z - halfSize), color));

	AddLine(LineVertex(D3DXVECTOR3(location.x + halfSize, location.y + halfSize, location.z - halfSize), color), LineVertex(D3DXVECTOR3(location.x - halfSize, location.y + halfSize, location.z - halfSize), color));

	AddLine(LineVertex(D3DXVECTOR3(location.x - halfSize, location.y + halfSize, location.z - halfSize), color), LineVertex(D3DXVECTOR3(location.x - halfSize, location.y - halfSize, location.z - halfSize), color));

	// Top
	AddLine(LineVertex(D3DXVECTOR3(location.x - halfSize, location.y - halfSize, location.z + halfSize), color), LineVertex(D3DXVECTOR3(location.x + halfSize, location.y - halfSize, location.z + halfSize), color));

	AddLine(LineVertex(D3DXVECTOR3(location.x + halfSize, location.y - halfSize, location.z + halfSize), color), LineVertex(D3DXVECTOR3(location.x + halfSize, location.y + halfSize, location.z + halfSize), color));

	AddLine(LineVertex(D3DXVECTOR3(location.x + halfSize, location.y + halfSize, location.z + halfSize), color), LineVertex(D3DXVECTOR3(location.x - halfSize, location.y + halfSize, location.z + halfSize), color));

	AddLine(LineVertex(D3DXVECTOR3(location.x - halfSize, location.y + halfSize, location.z + halfSize), color), LineVertex(D3DXVECTOR3(location.x - halfSize, location.y - halfSize, location.z + halfSize), color));

	// Sides
	AddLine(LineVertex(D3DXVECTOR3(location.x - halfSize, location.y - halfSize, location.z + halfSize), color), LineVertex(D3DXVECTOR3(location.x - halfSize, location.y - halfSize, location.z - halfSize), color));

	AddLine(LineVertex(D3DXVECTOR3(location.x + halfSize, location.y - halfSize, location.z + halfSize), color), LineVertex(D3DXVECTOR3(location.x + halfSize, location.y - halfSize, location.z - halfSize), color));

	AddLine(LineVertex(D3DXVECTOR3(location.x + halfSize, location.y + halfSize, location.z + halfSize), color), LineVertex(D3DXVECTOR3(location.x + halfSize, location.y + halfSize, location.z - halfSize), color));

	AddLine(LineVertex(D3DXVECTOR3(location.x - halfSize, location.y + halfSize, location.z + halfSize), color), LineVertex(D3DXVECTOR3(location.x - halfSize, location.y + halfSize, location.z - halfSize), color));

}
Ejemplo n.º 8
0
/** Adds a triangle to the renderlist */
void BaseLineRenderer::AddTriangle(const D3DXVECTOR3& t0, const D3DXVECTOR3& t1, const D3DXVECTOR3& t2, const D3DXVECTOR4& color)
{
	AddLine(LineVertex(t0, color), LineVertex(t1, color));
	AddLine(LineVertex(t0, color), LineVertex(t2, color));
	AddLine(LineVertex(t1, color), LineVertex(t2, color));
}
Ejemplo n.º 9
0
void BaseLineRenderer::AddAABBMinMax(const D3DXVECTOR3& min, const D3DXVECTOR3& max, const D3DXVECTOR4& color)
{
	AddLine(LineVertex(D3DXVECTOR3(min.x, min.y, min.z), color), LineVertex(D3DXVECTOR3(max.x, min.y, min.z), color));
	AddLine(LineVertex(D3DXVECTOR3(max.x, min.y, min.z), color), LineVertex(D3DXVECTOR3(max.x, max.y, min.z), color));
	AddLine(LineVertex(D3DXVECTOR3(max.x, max.y, min.z), color), LineVertex(D3DXVECTOR3(min.x, max.y, min.z), color));
	AddLine(LineVertex(D3DXVECTOR3(min.x, max.y, min.z), color), LineVertex(D3DXVECTOR3(min.x, min.y, min.z), color));
													
	AddLine(LineVertex(D3DXVECTOR3(min.x, min.y, max.z), color), LineVertex(D3DXVECTOR3(max.x, min.y, max.z), color));
	AddLine(LineVertex(D3DXVECTOR3(max.x, min.y, max.z), color), LineVertex(D3DXVECTOR3(max.x, max.y, max.z), color));
	AddLine(LineVertex(D3DXVECTOR3(max.x, max.y, max.z), color), LineVertex(D3DXVECTOR3(min.x, max.y, max.z), color));
	AddLine(LineVertex(D3DXVECTOR3(min.x, max.y, max.z), color), LineVertex(D3DXVECTOR3(min.x, min.y, max.z), color));
												
	AddLine(LineVertex(D3DXVECTOR3(min.x, min.y, min.z), color), LineVertex(D3DXVECTOR3(min.x, min.y, max.z), color));
	AddLine(LineVertex(D3DXVECTOR3(max.x, min.y, min.z), color), LineVertex(D3DXVECTOR3(max.x, min.y, max.z), color));
	AddLine(LineVertex(D3DXVECTOR3(max.x, max.y, min.z), color), LineVertex(D3DXVECTOR3(max.x, max.y, max.z), color));
	AddLine(LineVertex(D3DXVECTOR3(min.x, max.y, min.z), color), LineVertex(D3DXVECTOR3(min.x, max.y, max.z), color));
}
Ejemplo n.º 10
0
 void Line3D::DrawLine(const Vector3& Start, const Vector3& End, const ColourValue& Colour)
 {
     this->Points.push_back( LineVertex(Start,Colour) );
     this->Points.push_back( LineVertex(End,Colour) );
 }
Ejemplo n.º 11
0
 void Line3D::AddPoint(const Vector3& NewPoint, const ColourValue& Colour)
 {
     this->Points.push_back( LineVertex(NewPoint,Colour) );
 }
Ejemplo n.º 12
0
/** Draws the surrounding scene into the cubemap */
void D3D11PointLight::RenderCubemap(bool forceUpdate)
{
	if(!InitDone)
		return;

	//if(!GetAsyncKeyState('X'))
	//	return;
	D3D11GraphicsEngineBase* engineBase = (D3D11GraphicsEngineBase *)Engine::GraphicsEngine;
	D3D11GraphicsEngine* engine = (D3D11GraphicsEngine *) engineBase; // TODO: Remove and use newer system!


	D3DXVECTOR3 vEyePt = LightInfo->Vob->GetPositionWorld();
	//vEyePt += D3DXVECTOR3(0,1,0) * 20.0f; // Move lightsource out of the ground or other objects (torches!)
	// TODO: Move the actual lightsource up too!

	/*if(WantsUpdate())
	{
		// Move lights with colorchanges around a bit to make it look more light torches
		vEyePt.y += (float4(LastUpdateColor).x - 0.5f) * LIGHT_COLORCHANGE_POS_MOD;
		vEyePt.x += (float4(LastUpdateColor).y - 0.5f) * LIGHT_COLORCHANGE_POS_MOD;
		vEyePt.z += (float4(LastUpdateColor).y - 0.5f) * LIGHT_COLORCHANGE_POS_MOD;
	}*/

    D3DXVECTOR3 vLookDir;
    D3DXVECTOR3 vUpDir;

	if(!NeedsUpdate() && !WantsUpdate())
	{
		if(!forceUpdate)
			return; // Don't update when we don't need to
	}else
	{
		if(LightInfo->Vob->GetPositionWorld() != LastUpdatePosition)
		{
			// Position changed, refresh our caches
			VobCache.clear();
			SkeletalVobCache.clear();

			// Invalidate worldcache
			WorldCacheInvalid = true;
		}
	}

	

	// Update indoor/outdoor-state
	LightInfo->IsIndoorVob = LightInfo->Vob->IsIndoorVob();

	D3DXMATRIX proj;

	const bool dbg = false;

	// Generate cubemap view-matrices
    vLookDir = D3DXVECTOR3( 1.0f, 0.0f, 0.0f ) + vEyePt;
    vUpDir = D3DXVECTOR3( 0.0f, 1.0f, 0.0f );
	if(dbg)Engine::GraphicsEngine->GetLineRenderer()->AddLine(LineVertex(vEyePt, float4(1.0f,0,0,1)), LineVertex((vLookDir - vEyePt) * 50.0f + vEyePt, float4(1.0f,1.0f,0,1)));
    D3DXMatrixLookAtLH( &CubeMapViewMatrices[0], &vEyePt, &vLookDir, &vUpDir );
    vLookDir = D3DXVECTOR3( -1.0f, 0.0f, 0.0f ) + vEyePt;
    vUpDir = D3DXVECTOR3( 0.0f, 1.0f, 0.0f );
	if(dbg)Engine::GraphicsEngine->GetLineRenderer()->AddLine(LineVertex(vEyePt, float4(1.0f,0,0,1)), LineVertex((vLookDir - vEyePt) * 50.0f + vEyePt, float4(1.0f,1.0f,0,1)));
    D3DXMatrixLookAtLH( &CubeMapViewMatrices[1], &vEyePt, &vLookDir, &vUpDir );
    vLookDir = D3DXVECTOR3( 0.0f, 0.0f + 1.0f, 0.0f ) + vEyePt;
    vUpDir = D3DXVECTOR3( 0.0f, 0.0f, -1.0f );
	if(dbg)Engine::GraphicsEngine->GetLineRenderer()->AddLine(LineVertex(vEyePt, float4(1.0f,0,0,1)), LineVertex((vLookDir - vEyePt) * 50.0f + vEyePt, float4(1.0f,1.0f,0,1)));
    D3DXMatrixLookAtLH( &CubeMapViewMatrices[2], &vEyePt, &vLookDir, &vUpDir );
    vLookDir = D3DXVECTOR3( 0.0f, 0.0f - 1.0f, 0.0f ) + vEyePt;
    vUpDir = D3DXVECTOR3( 0.0f, 0.0f, 1.0f );
	if(dbg)Engine::GraphicsEngine->GetLineRenderer()->AddLine(LineVertex(vEyePt, float4(1.0f,0,0,1)), LineVertex((vLookDir - vEyePt) * 50.0f + vEyePt, float4(1.0f,1.0f,0,1)));
    D3DXMatrixLookAtLH( &CubeMapViewMatrices[3], &vEyePt, &vLookDir, &vUpDir );
    vLookDir = D3DXVECTOR3( 0.0f, 0.0f, 1.0f ) + vEyePt;
    vUpDir = D3DXVECTOR3( 0.0f, 1.0f, 0.0f );
	if(dbg)Engine::GraphicsEngine->GetLineRenderer()->AddLine(LineVertex(vEyePt, float4(1.0f,0,0,1)), LineVertex((vLookDir - vEyePt) * 50.0f + vEyePt, float4(1.0f,1.0f,0,1)));
    D3DXMatrixLookAtLH( &CubeMapViewMatrices[4], &vEyePt, &vLookDir, &vUpDir );
    vLookDir = D3DXVECTOR3( 0.0f, 0.0f, -1.0f ) + vEyePt;
    vUpDir = D3DXVECTOR3( 0.0f, 1.0f, 0.0f );
	if(dbg)Engine::GraphicsEngine->GetLineRenderer()->AddLine(LineVertex(vEyePt, float4(1.0f,0,0,1)), LineVertex((vLookDir - vEyePt) * 50.0f + vEyePt, float4(1.0f,1.0f,0,1)));
    D3DXMatrixLookAtLH( &CubeMapViewMatrices[5], &vEyePt, &vLookDir, &vUpDir );

	for(int i=0;i<6;i++)
		D3DXMatrixTranspose(&CubeMapViewMatrices[i], &CubeMapViewMatrices[i]);

	// Create the projection matrix
	float zNear = 15.0f;
	float zFar = LightInfo->Vob->GetLightRange() * 2.0f;
    D3DXMatrixPerspectiveFovLH( &proj, ((float)D3DX_PI * 0.5f), 1.0f, zNear, zFar );
	D3DXMatrixTranspose(&proj, &proj);

	// Setup near/far-planes. We need linear viewspace depth for the cubic shadowmaps.
	Engine::GAPI->GetRendererState()->GraphicsState.FF_zNear = zNear;
	Engine::GAPI->GetRendererState()->GraphicsState.FF_zFar = zFar;
	Engine::GAPI->GetRendererState()->GraphicsState.SetGraphicsSwitch(GSWITCH_LINEAR_DEPTH, true);

	bool oldDepthClip = Engine::GAPI->GetRendererState()->RasterizerState.DepthClipEnable;
	Engine::GAPI->GetRendererState()->RasterizerState.DepthClipEnable = true;

	// Upload view-matrices to the GPU
	CubemapGSConstantBuffer gcb;
	for(int i=0;i<6;i++)
	{
		gcb.PCR_View[i] = CubeMapViewMatrices[i];
		gcb.PCR_ViewProj[i] = proj * CubeMapViewMatrices[i];
	}

	ViewMatricesCB->UpdateBuffer(&gcb);
	ViewMatricesCB->BindToGeometryShader(2);

	//for(int i=0;i<6;i++)
	//	RenderCubemapFace(CubeMapViewMatrices[i], proj, i);
	RenderFullCubemap();

	if(dbg)
	{
		for(auto it = VobCache.begin();it!=VobCache.end();it++)
			Engine::GraphicsEngine->GetLineRenderer()->AddLine(LineVertex(vEyePt, float4(1.0f,0,0,1)), LineVertex((*it)->Vob->GetPositionWorld(), float4(1.0f,1.0f,0,1)));
	}

	Engine::GAPI->GetRendererState()->RasterizerState.DepthClipEnable = oldDepthClip;
	Engine::GAPI->GetRendererState()->GraphicsState.SetGraphicsSwitch(GSWITCH_LINEAR_DEPTH, false);

	LastUpdateColor = LightInfo->Vob->GetLightColor();
	LastUpdatePosition = vEyePt;
	DrawnOnce = true;
}