Пример #1
0
void OvRenderer::RenderUnitRect( OvVertexShaderSPtr v_shader , OvPixelShaderSPtr p_shader )
{
	struct SScreenRect
	{
		OvPoint3 pos; OvPoint2 tex;
	};
	static D3DVERTEXELEMENT9 rect_elem[] =
	{
		{ 0, 0
		, D3DDECLTYPE_FLOAT3
		, D3DDECLMETHOD_DEFAULT
		, D3DDECLUSAGE_POSITION, 0 },

		{ 0, 12
		, D3DDECLTYPE_FLOAT2
		, D3DDECLMETHOD_DEFAULT
		, D3DDECLUSAGE_TEXCOORD, 0 },
		D3DDECL_END()
	};
	static SScreenRect rect[] = 
	{ {OvPoint3(-1,-1,0),OvPoint2(0,1)}
	, {OvPoint3(-1,+1,0),OvPoint2(0,0)}
	, {OvPoint3(+1,+1,0),OvPoint2(1,0)}
	, {OvPoint3(+1,-1,0),OvPoint2(1,1)}};

	static LPDIRECT3DVERTEXBUFFER9 rectVertBuffer = CreateVertexStream( (void*)&rect[0], sizeof( SScreenRect ), 4 );
	static LPDIRECT3DVERTEXDECLARATION9 rectDecl = CreateVertexDeclaration( rect_elem );

	if ( v_shader ) SetVertexShader( v_shader );
	if ( p_shader ) SetPixelShader( p_shader );
	SetVertexStream( 0, SVertexStreamInfo( rectVertBuffer, sizeof( SScreenRect ), 0) );
	SetVertexDeclaration( rectDecl );
	DrawPrimitive( D3DPT_TRIANGLEFAN, 2);
}
Пример #2
0
ShaderProgram::ShaderProgram(FragmentShader *pFragmentShader, VertexShader *pVertexShader)
{
    Init();

    SetFragmentShader(pFragmentShader);
    SetVertexShader(pVertexShader);

    CreateProgram();
}
//==============================================================================================================================
bool DebugGBufferDeferredShader::RenderDepth11(ID3D11ShaderResourceView* texture, Camera* camera)
{
	cbInvMatrixBuffer cMB;
	cMB.g_InvViewProj = camera->InvViewProj4x4();
	// Map the matrix buffer
	{
		D3D11_MAPPED_SUBRESOURCE mapped_res2;
		m_pD3DSystem->GetDeviceContext()->Map(m_pMatrixCB, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped_res2);
		{
			assert(mapped_res2.pData);
			*(cbInvMatrixBuffer*)mapped_res2.pData = cMB;
		}
		m_pD3DSystem->GetDeviceContext()->Unmap(m_pMatrixCB, 0);
	}

	ID3D11Buffer* ps_cbs[1] = { m_pMatrixCB };
	m_pD3DSystem->GetDeviceContext()->PSSetConstantBuffers(0, 1, ps_cbs);

	// Assign Texture
	ID3D11ShaderResourceView* ps_srvs[1] = { texture };
	ID3D11SamplerState* ps_samp[1] = { m_pD3DSystem->Point() };

	if (!m_Wireframe)
	{
		m_pD3DSystem->GetDeviceContext()->PSSetShaderResources(0, 1, ps_srvs);
		m_pD3DSystem->GetDeviceContext()->PSSetSamplers(0, 1, ps_samp);

		SwitchTo("DebugGBufferDepthDeferredPS", ZShadeSandboxShader::EShaderTypes::ST_PIXEL);
	}
	else
	{
		SwitchTo("DebugGBufferDeferredWireframePS", ZShadeSandboxShader::EShaderTypes::ST_PIXEL);
	}

	m_pD3DSystem->TurnOnAdditiveBlending();

	SetVertexShader();
	SetPixelShader();

	//Perform Drawing onto a fullscreen quad with a NULL Input Layout
	RenderDraw11(4);

	m_pD3DSystem->TurnOffAdditiveBlending();

	// Unbind
	if (!m_Wireframe)
	{
		ps_samp[0] = NULL;
		m_pD3DSystem->GetDeviceContext()->PSSetSamplers(0, 1, ps_samp);
		ps_srvs[0] = NULL;
		m_pD3DSystem->GetDeviceContext()->PSSetShaderResources(0, 1, ps_srvs);
	}

	return true;
}
Пример #4
0
/*virtual*/ void D3D9Renderer::SetShaderProgram(
    IShaderProgram* const pShaderProgram) {
  DEBUGASSERT(pShaderProgram);

  if (pShaderProgram == m_ShaderProgram) {
    return;
  }
  m_ShaderProgram = pShaderProgram;

  SetVertexShader(pShaderProgram->GetVertexShader());
  SetPixelShader(pShaderProgram->GetPixelShader());
}
Пример #5
0
    //-----------------------------------------------------------------------------
    //  CreateDefaultObjects
    //  Creates the default objects
    //-----------------------------------------------------------------------------
    void CRenderer::CreateDefaultObjects( void )
    {
        // Texture
        m_nDefaultTexture = LoadTexture2D( "Assets/Textures/DefaultTexture.png" );
        
        // Default mesh
        m_nDefaultMesh = CreateMesh();

        // debug sphere
        m_nSphereMesh = LoadMesh( "Assets/meshes/sphere.mesh" );

        // debug box
        m_nDebugBox = CreateDynamicBox();
        
        //////////////////////////////////////////
        //  Load Shaders
        LoadShaders();

        // a vertex shader for drawing lines        
        VPosColor pLineVertices[] =
        {
            { RVector3(  0.0f,  0.0f,  0.0f ), RVector4( 1.0f, 1.0f, 1.0f, 1.0f ) },
            { RVector3(  1.0f,  1.0f,  1.0f ), RVector4( 1.0f, 1.0f, 1.0f, 1.0f ) },
        };
        m_pLineBuffer = m_pDevice->CreateVertexBuffer( sizeof( pLineVertices ), pLineVertices );

        // Set the defaults
        SetVertexShader( eVS3DPosNorTexStd );
        SetPixelShader( ePS3DStd );
        SetSamplerState( eSamplerLinear );
        m_pDevice->SetPrimitiveType( GFX_PRIMITIVE_TRIANGLELIST );


        static float Vtx[] = 
        { 
            -1.0f, -1.0f, 
            -1.0f,  1.0f, 
             1.0f,  1.0f, 
             1.0f, -1.0f, 
        };
        static uint16 Idx[] = 
        { 
            0, 1, 2, 
            0, 2, 3,
        };

        m_pFSRectVB = m_pDevice->CreateVertexBuffer( sizeof( Vtx ), Vtx );
        m_pFSRectIB = m_pDevice->CreateIndexBuffer ( sizeof( Idx ), Idx );
    }
Пример #6
0
ShaderProgram::ShaderProgram(const char *pFragmentFile, const char *pVertexFile)
{
    Init();

    FragmentShader	*pFragmentShader	= new FragmentShader(pFragmentFile);
    VertexShader	*pVertexShader		= new VertexShader(pVertexFile);

    SetFragmentShader(pFragmentShader);
    SetVertexShader(pVertexShader);

    pFragmentShader->Release();
    pVertexShader->Release();

    CreateProgram();
}
Пример #7
0
			Air::U1 System::SetShader( Render::enumShaderType type,IShader* pShader ){
				IDirect3DVertexShader9*	pVS	=	NULL;
				IDirect3DPixelShader9*	pPS	=	NULL;
				if(type	==	enVS){
					if(pShader!=NULL){
						pVS	=	(DxVertexShader*)pShader->GetShader();
					}
					SetVertexShader(pVS);
				}else{
					if(pShader!=NULL){
						pPS	=	(DxPixelShader*)pShader->GetShader();
					}
					SetPixelShader(pPS);
				}
				return	true;
			}
Пример #8
0
void cShaderObject::CreateShaderProgram(cStringRef shader_source)
{
	// chop off leading newlines if possible: will make so that the source
	// file line numbers will match what the compiler sees
	cStringRef ss = shader_source;
	SetFragmentShader(ss.data());
	if(shader_source.find("{akj:use geometry}") != cStringRef::npos)
	{
		SetGeometryShader(ss.data());
	}
	SetVertexShader(ss.data());
	LinkShaderProgram();
	int is_linked;
	glGetProgramiv(mShaderProgram, GL_LINK_STATUS, &is_linked);
	if(!is_linked)
	{
		AKJ_THROW("Shader "+mObjectName + " Linking Failed.");
	}
}
Пример #9
0
//==============================================================================
// Shader
//------------------------------------------------------------------------------
void Shader::setVtxShader(const char* fileName) {
  auto pDevice = App::instance().getRenderer()->getDevice();

  if(fileName == nullptr) {
    pDevice->SetVertexShader(nullptr);
    _nowVtxShader = nullptr;
    return;
  }

  if(_nowVtxShader != nullptr && _nowVtxShader->filename == fileName) {
    return;
  }
  auto it = _vtxShaderMap.find(fileName);

  if(it == _vtxShaderMap.end()) {
    return;
  }

  setVtxShader(it->second);
}
//==============================================================================================================================
bool ShadowMapBuildShader::Render(int indexCount, XMMATRIX world, LightCamera* lightCamera)
{
	cbShadowMapConst cSMB;
	
	//m_pD3DSystem->SetRasterizerState(m_pD3DSystem->RSDepth());

	cSMB.g_World = ZShadeSandboxMath::ZMath::GMathMF(XMMatrixTranspose(world));
	cSMB.g_LightView = lightCamera->LightView4x4();
	cSMB.g_LightProj = lightCamera->LightProj4x4();
	
	// Map matrix constants
	{
		D3D11_MAPPED_SUBRESOURCE mapped_res;
		m_pD3DSystem->GetDeviceContext()->Map(m_pShadowMapCB, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped_res);
		{
			assert(mapped_res.pData);
			*(cbShadowMapConst*)mapped_res.pData = cSMB;
		}
		m_pD3DSystem->GetDeviceContext()->Unmap(m_pShadowMapCB, 0);
	}
	
	// Set the shadow map constant buffer into the Vertex Shader
	ID3D11Buffer* vs_cbs[1] = { m_pShadowMapCB };
	m_pD3DSystem->GetDeviceContext()->VSSetConstantBuffers(0, 1, vs_cbs);
	
	// Tell the shader what input layout to use
	SetInputLayout("ShadowMapBuildShader");
	
	// Assign the shaders to render the mesh
	SetVertexShader();
	//SetPixelShader();
	
	m_pD3DSystem->GetDeviceContext()->PSSetShader(NULL, NULL, 0);

	//Perform Drawing
	RenderIndex11(indexCount);
	
	return true;
}
//==============================================================================================================================
bool DebugGBufferDeferredShader::Render11(ID3D11ShaderResourceView* texture)
{
	// Assign Texture
	ID3D11ShaderResourceView* ps_srvs[1] = { texture };
	ID3D11SamplerState* ps_samp[1] = { m_pD3DSystem->Point() };
	
	if (!m_Wireframe)
	{
		m_pD3DSystem->GetDeviceContext()->PSSetShaderResources(0, 1, ps_srvs);
		m_pD3DSystem->GetDeviceContext()->PSSetSamplers(0, 1, ps_samp);
		
		SwitchTo("DebugGBufferDeferredPS", ZShadeSandboxShader::EShaderTypes::ST_PIXEL);
	}
	else
	{
		SwitchTo("DebugGBufferDeferredWireframePS", ZShadeSandboxShader::EShaderTypes::ST_PIXEL);
	}
	
	m_pD3DSystem->TurnOnAdditiveBlending();
	
	SetVertexShader();
	SetPixelShader();
	
	//Perform Drawing onto a fullscreen quad with a NULL Input Layout
	RenderDraw11(4);
	
	m_pD3DSystem->TurnOffAdditiveBlending();
	
	// Unbind
	if (!m_Wireframe)
	{
		ps_samp[0] = NULL;
		m_pD3DSystem->GetDeviceContext()->PSSetSamplers(0, 1, ps_samp);
		ps_srvs[0] = NULL;
		m_pD3DSystem->GetDeviceContext()->PSSetShaderResources(0, 1, ps_srvs);
	}
	
	return true;
}
Пример #12
0
void plLayer::CloneNoTexture( plLayerInterface *original )
{
    SetBlendFlags( original->GetBlendFlags() );
    SetClampFlags( original->GetClampFlags() );
    SetShadeFlags( original->GetShadeFlags() );
    SetZFlags( original->GetZFlags() );
    SetMiscFlags( original->GetMiscFlags() );
    SetState( original->GetState() );

    SetPreshadeColor( original->GetPreshadeColor() );
    SetRuntimeColor( original->GetRuntimeColor() );
    SetAmbientColor( original->GetAmbientColor() );
    SetSpecularColor( original->GetSpecularColor() );
    SetOpacity( original->GetOpacity() );
    SetTransform( original->GetTransform() );
    SetUVWSrc( original->GetUVWSrc() );
    SetLODBias( original->GetLODBias() );
    SetSpecularPower( original->GetSpecularPower() );

    SetVertexShader( original->GetVertexShader() );
    SetPixelShader( original->GetPixelShader() );
    SetBumpEnvMatrix( original->GetBumpEnvMatrix() );
}
Пример #13
0
static GLboolean _gld_mesa_render_stage_run(
	struct gl_context *ctx,
	struct tnl_pipeline_stage *stage)
{
	GLD_context				*gldCtx	= GLD_GET_CONTEXT(ctx);
	GLD_driver_dx9			*gld	= GLD_GET_DX9_DRIVER(gldCtx);
		
	TNLcontext				*tnl = TNL_CONTEXT(ctx);
	struct vertex_buffer	*VB = &tnl->vb;
	tnl_render_func				*tab;
	GLint					pass = 0;
	GLD_pb_dx9				*gldPB;

	/* Allow the drivers to lock before projected verts are built so
    * that window coordinates are guarenteed not to change before
    * rendering.
    */
	ASSERT(tnl->Driver.Render.Start);
	
	tnl->Driver.Render.Start( ctx );
	
	// NOTE: Setting D3DRS_SOFTWAREVERTEXPROCESSING for a mixed-mode device resets
	//       stream, indices and shader to default values of NULL or 0.
/*	if ((ctx->_TriangleCaps & DD_TRI_LIGHT_TWOSIDE) &&
		gld->VStwosidelight.hShader &&
		!ctx->Fog.Enabled)
	{
		IDirect3DDevice8_SetRenderState(gld->pDev, D3DRS_SOFTWAREVERTEXPROCESSING, !gld->VStwosidelight.bHardware);
		_GLD_DX9_DEV(SetVertexShader(gld->pDev, gld->VStwosidelight.hShader));
		gldPB = &gld->PBtwosidelight;
		tnl->Driver.Render.Points	= gld_Points2DTwoside_DX9;
		if (ctx->_TriangleCaps & DD_FLATSHADE) {
			tnl->Driver.Render.Line		= gld_Line2DFlatTwoside_DX9;
			tnl->Driver.Render.Triangle	= gld_Triangle2DFlatTwoside_DX9;
			tnl->Driver.Render.Quad		= gld_Quad2DFlatTwoside_DX9;
		} else {
			tnl->Driver.Render.Line		= gld_Line2DSmoothTwoside_DX9;
			tnl->Driver.Render.Triangle	= gld_Triangle2DSmoothTwoside_DX9;
			tnl->Driver.Render.Quad		= gld_Quad2DSmoothTwoside_DX9;
		}
	} else {*/
//		IDirect3DDevice8_SetRenderState(gld->pDev, D3DRS_SOFTWAREVERTEXPROCESSING, TRUE);
		IDirect3DDevice9_SetSoftwareVertexProcessing(gld->pDev, TRUE);
		gldPB = &gld->PB2d;
		_GLD_DX9_DEV(SetVertexShader(gld->pDev, NULL));
		_GLD_DX9_DEV(SetFVF(gld->pDev, gldPB->dwFVF));
		tnl->Driver.Render.Points	= _gldSetupPoints[gld->iSetupFunc];
		tnl->Driver.Render.Line		= _gldSetupLine[gld->iSetupFunc];
		tnl->Driver.Render.Triangle	= _gldSetupTriangle[gld->iSetupFunc];
		tnl->Driver.Render.Quad		= _gldSetupQuad[gld->iSetupFunc];
//	}

	_GLD_DX9_VB(Lock(gldPB->pVB, 0, 0, &gldPB->pPoints, D3DLOCK_DISCARD));
	gldPB->nPoints = gldPB->nLines = gldPB->nTriangles = 0;
	// Allocate primitive pointers
	// gldPB->pPoints is always first
	gldPB->pLines		= gldPB->pPoints + (gldPB->dwStride * gldPB->iFirstLine);
	gldPB->pTriangles	= gldPB->pPoints + (gldPB->dwStride * gldPB->iFirstTriangle);

	ASSERT(tnl->Driver.Render.BuildVertices);
	ASSERT(tnl->Driver.Render.PrimitiveNotify);
	ASSERT(tnl->Driver.Render.Points);
	ASSERT(tnl->Driver.Render.Line);
	ASSERT(tnl->Driver.Render.Triangle);
	ASSERT(tnl->Driver.Render.Quad);
	ASSERT(tnl->Driver.Render.ResetLineStipple);
	ASSERT(tnl->Driver.Render.Interp);
	ASSERT(tnl->Driver.Render.CopyPV);
	ASSERT(tnl->Driver.Render.ClippedLine);
	ASSERT(tnl->Driver.Render.ClippedPolygon);
	ASSERT(tnl->Driver.Render.Finish);
	
	tnl->Driver.Render.BuildVertices( ctx, 0, VB->Count, ~0 );
	
	if (VB->ClipOrMask) {
		tab = VB->Elts ? clip_render_tab_elts : clip_render_tab_verts;
		clip_render_tab_elts[GL_TRIANGLES] = clip_elt_triangles;
	}
	else {
		tab = (VB->Elts ? 
			tnl->Driver.Render.PrimTabElts : 
		tnl->Driver.Render.PrimTabVerts);
	}
	
	do {
		GLuint i, length, flags = 0;
		for (i = 0 ; !(flags & PRIM_END) ; i += length) {
			flags = VB->Primitive[i].mode;
			length= VB->Primitive[i].count;
			ASSERT(length || (flags & PRIM_END));
			ASSERT((flags & PRIM_MODE_MASK) <= GL_POLYGON+1);
			if (length)
				tab[flags & PRIM_MODE_MASK]( ctx, i, i + length, flags );
		}
	} while (tnl->Driver.Render.Multipass &&
		tnl->Driver.Render.Multipass( ctx, ++pass ));
	
	
//	tnl->Driver.Render.Finish( ctx );
	
	_GLD_DX9_VB(Unlock(gldPB->pVB));

	_GLD_DX9_DEV(SetStreamSource(gld->pDev, 0, gldPB->pVB, 0, gldPB->dwStride));

	if (gldPB->nPoints) {
		_GLD_DX9_DEV(DrawPrimitive(gld->pDev, D3DPT_POINTLIST, 0, gldPB->nPoints));
		gldPB->nPoints = 0;
	}

	if (gldPB->nLines) {
		_GLD_DX9_DEV(DrawPrimitive(gld->pDev, D3DPT_LINELIST, gldPB->iFirstLine, gldPB->nLines));
		gldPB->nLines = 0;
	}

	if (gldPB->nTriangles) {
		_GLD_DX9_DEV(DrawPrimitive(gld->pDev, D3DPT_TRIANGLELIST, gldPB->iFirstTriangle, gldPB->nTriangles));
		gldPB->nTriangles = 0;
	}

	return GL_FALSE;		/* finished the pipe */
}
Пример #14
0
void gld_update_state_DX9(
	struct gl_context *ctx,
	GLuint new_state)
{
	GLD_context		*gldCtx	= GLD_GET_CONTEXT(ctx);
	GLD_driver_dx9	*gld	= GLD_GET_DX9_DRIVER(gldCtx);
	TNLcontext		*tnl = TNL_CONTEXT(ctx);
	GLD_pb_dx9		*gldPB;

	if (!gld || !gld->pDev)
		return;

	_swsetup_InvalidateState( ctx, new_state );
	_vbo_InvalidateState( ctx, new_state );
	_tnl_InvalidateState( ctx, new_state );

	// SetupIndex will be used in the pipelines for choosing setup function
	if ((ctx->_TriangleCaps & (DD_TRI_LIGHT_TWOSIDE | DD_SEPARATE_SPECULAR)) ||
		(ctx->Fog.Enabled))
	{
		if (ctx->_TriangleCaps & DD_FLATSHADE)
			gld->iSetupFunc = GLD_SI_FLAT_EXTRAS;
		else
			gld->iSetupFunc = GLD_SI_SMOOTH_EXTRAS;
	} else {
		if (ctx->_TriangleCaps & DD_FLATSHADE)
			gld->iSetupFunc = GLD_SI_FLAT;	// Setup flat shade + texture
		else
			gld->iSetupFunc = GLD_SI_SMOOTH; // Setup smooth shade + texture
	}

	gld->bUseMesaTnL = _gldChooseInternalPipeline(ctx, gld);
	if (gld->bUseMesaTnL) {
		gldPB = &gld->PB2d;
		_GLD_DX9_DEV(SetSoftwareVertexProcessing(gld->pDev, TRUE));
		_GLD_DX9_DEV(SetRenderState(gld->pDev, D3DRS_CLIPPING, FALSE));
		_GLD_DX9_DEV(SetVertexShader(gld->pDev, NULL));
		_GLD_DX9_DEV(SetFVF(gld->pDev, gldPB->dwFVF));
	} else {
		gldPB = &gld->PB3d;
		_GLD_DX9_DEV(SetRenderState(gld->pDev, D3DRS_CLIPPING, TRUE));
//		if (gld->TnLPipeline == GLD_PIPELINE_D3D_VS_TWOSIDE) {
//			_GLD_DX9_DEV(SetRenderState(gld->pDev, D3DRS_SOFTWAREVERTEXPROCESSING, !gld->VStwosidelight.bHardware));
//			_GLD_DX9_DEV(SetVertexShader(gld->pDev, gld->VStwosidelight.hShader));
//		} else {
//			_GLD_DX9_DEV(SetRenderState(gld->pDev, D3DRS_SOFTWAREVERTEXPROCESSING, !gld->bHasHWTnL));
			_GLD_DX9_DEV(SetSoftwareVertexProcessing(gld->pDev, !gld->bHasHWTnL));
			_GLD_DX9_DEV(SetVertexShader(gld->pDev, NULL));
			_GLD_DX9_DEV(SetFVF(gld->pDev, gldPB->dwFVF));
//		}
	}

#define _GLD_TEST_STATE(a)		\
	if (new_state & (a)) {		\
		gld##a(ctx);			\
		new_state &= ~(a);		\
	}

#define _GLD_TEST_STATE_DX9(a)	\
	if (new_state & (a)) {		\
		gld##a##_DX9(ctx);		\
		new_state &= ~(a);		\
	}

#define _GLD_IGNORE_STATE(a) new_state &= ~(a);

//	if (!gld->bUseMesaTnL) {
		// Not required if Mesa is doing the TnL.
	// Problem: If gld->bUseMesaTnL is TRUE when these are signaled,
	// then we'll miss updating the D3D TnL pipeline.
	// Therefore, don't test for gld->bUseMesaTnL
	_GLD_TEST_STATE(_NEW_MODELVIEW);
	_GLD_TEST_STATE(_NEW_PROJECTION);
//	}

	_GLD_TEST_STATE_DX9(_NEW_TEXTURE); // extern, so guard with _DX9
	_GLD_TEST_STATE(_NEW_COLOR);
	_GLD_TEST_STATE(_NEW_DEPTH);
	_GLD_TEST_STATE(_NEW_POLYGON);
	_GLD_TEST_STATE(_NEW_STENCIL);
	_GLD_TEST_STATE(_NEW_FOG);
	_GLD_TEST_STATE(_NEW_LIGHT);
	_GLD_TEST_STATE(_NEW_VIEWPORT);

	_GLD_IGNORE_STATE(_NEW_TRANSFORM);

	// Scissor Test: New for DX9
	_GLD_TEST_STATE(_NEW_SCISSOR);

// Stubs for future use.
/*	_GLD_TEST_STATE(_NEW_TEXTURE_MATRIX);
	_GLD_TEST_STATE(_NEW_COLOR_MATRIX);
	_GLD_TEST_STATE(_NEW_EVAL);
	_GLD_TEST_STATE(_NEW_HINT);
	_GLD_TEST_STATE(_NEW_LINE);
	_GLD_TEST_STATE(_NEW_PIXEL);
	_GLD_TEST_STATE(_NEW_POINT);
	_GLD_TEST_STATE(_NEW_POLYGONSTIPPLE);
	_GLD_TEST_STATE(_NEW_PACKUNPACK);
	_GLD_TEST_STATE(_NEW_ARRAY);
	_GLD_TEST_STATE(_NEW_RENDERMODE);
	_GLD_TEST_STATE(_NEW_BUFFERS);
	_GLD_TEST_STATE(_NEW_MULTISAMPLE);
*/

// For debugging.
#if 0
#define _GLD_TEST_UNHANDLED_STATE(a)									\
	if (new_state & (a)) {									\
		gldLogMessage(GLDLOG_ERROR, "Unhandled " #a "\n");	\
	}
	_GLD_TEST_UNHANDLED_STATE(_NEW_TEXTURE_MATRIX);
	_GLD_TEST_UNHANDLED_STATE(_NEW_COLOR_MATRIX);
	_GLD_TEST_UNHANDLED_STATE(_NEW_EVAL);
	_GLD_TEST_UNHANDLED_STATE(_NEW_HINT);
	_GLD_TEST_UNHANDLED_STATE(_NEW_LINE);
	_GLD_TEST_UNHANDLED_STATE(_NEW_PIXEL);
	_GLD_TEST_UNHANDLED_STATE(_NEW_POINT);
	_GLD_TEST_UNHANDLED_STATE(_NEW_POLYGONSTIPPLE);
//	_GLD_TEST_UNHANDLED_STATE(_NEW_SCISSOR);
	_GLD_TEST_UNHANDLED_STATE(_NEW_PACKUNPACK);
	_GLD_TEST_UNHANDLED_STATE(_NEW_ARRAY);
	_GLD_TEST_UNHANDLED_STATE(_NEW_RENDERMODE);
	_GLD_TEST_UNHANDLED_STATE(_NEW_BUFFERS);
	_GLD_TEST_UNHANDLED_STATE(_NEW_MULTISAMPLE);
#undef _GLD_UNHANDLED_STATE
#endif

#undef _GLD_TEST_STATE
}
Пример #15
0
bool GLVideo::DrawRectangle(
	const math::Vector2 &v2Pos,
	const math::Vector2 &v2Size,
	const Color& color0,
	const Color& color1,
	const Color& color2,
	const Color& color3,
	const float angle,
	const Sprite::ENTITY_ORIGIN origin)
{
	if (v2Size == math::Vector2(0,0))
	{
		return true;
	}

	// TODO/TO-DO this is diplicated code: fix it
	math::Vector2 v2Center;
	switch (origin)
	{
	case Sprite::EO_CENTER:
	case Sprite::EO_RECT_CENTER:
		v2Center.x = v2Size.x / 2.0f;
		v2Center.y = v2Size.y / 2.0f;
		break;
	case Sprite::EO_RECT_CENTER_BOTTOM:
	case Sprite::EO_CENTER_BOTTOM:
		v2Center.x = v2Size.x / 2.0f;
		v2Center.y = v2Size.y;
		break;
	case Sprite::EO_RECT_CENTER_TOP:
	case Sprite::EO_CENTER_TOP:
		v2Center.x = v2Size.x / 2.0f;
		v2Center.y = 0.0f;
		break;
	case Sprite::EO_DEFAULT:
	default:
		v2Center.x = 0.0f;
		v2Center.y = 0.0f;
		break;
	};

	math::Matrix4x4 mRot;
	if (angle != 0.0f)
		mRot = math::RotateZ(math::DegreeToRadian(angle));
	m_rectVS->SetMatrixConstant("rotationMatrix", mRot);
	m_rectVS->SetConstant("size", v2Size);
	m_rectVS->SetConstant("entityPos", v2Pos);
	m_rectVS->SetConstant("center", v2Center);
	m_rectVS->SetConstant("color0", color0);
	m_rectVS->SetConstant("color1", color1);
	m_rectVS->SetConstant("color2", color2);
	m_rectVS->SetConstant("color3", color3);

	ShaderPtr prevVertexShader = GetVertexShader(), prevPixelShader = GetPixelShader();

	SetVertexShader(m_rectVS);
	SetPixelShader(ShaderPtr());

	UnsetTexture(0);
	UnsetTexture(1);
	GetVertexShader()->SetShader();
	m_rectRenderer.Draw(Sprite::RM_TWO_TRIANGLES);

	SetPixelShader(prevPixelShader);
	SetVertexShader(prevVertexShader);
	return true;
}
//==============================================================================================================================
bool MaterialTessellationShader::Render11
(	int indexCount
,	int instanceCount
,	ZShadeSandboxMesh::MeshRenderParameters mrp
,	ZShadeSandboxLighting::ShaderMaterial* material
)
{
	ID3D11ShaderResourceView* diffuseArrayTexture = 0;
	ID3D11ShaderResourceView* diffuseTexture = 0;
	ID3D11ShaderResourceView* ambientTexture = 0;
	ID3D11ShaderResourceView* specularTexture = 0;
	ID3D11ShaderResourceView* emissiveTexture = 0;
	ID3D11ShaderResourceView* normalMapTexture = 0;
	ID3D11ShaderResourceView* blendMapTexture = 0;
	ID3D11ShaderResourceView* detailMapTexture = 0;
	ID3D11ShaderResourceView* alphaMapTexture = 0;
	ID3D11ShaderResourceView* shadowMapTexture = 0;
	ID3D11ShaderResourceView* ssaoTexture = 0;
	ID3D11ShaderResourceView* displacementMapTexture = 0;

	material->GetTextures(
		diffuseArrayTexture,
		diffuseTexture,
		ambientTexture,
		specularTexture,
		emissiveTexture,
		normalMapTexture,
		blendMapTexture,
		detailMapTexture,
		alphaMapTexture,
		shadowMapTexture,
		ssaoTexture,
		displacementMapTexture
	);
	
	material->BuildMaterialTessellationBuffer(m_pTessellationCB, mrp.camera->Position());
	material->BuildMaterialDomainBuffer(m_pDomainCB, mrp.world, mrp.camera, mrp.clipplane, mrp.reflection);
	material->BuildMaterialConstantBuffer(m_pShadingCB, mrp.camera->Position(), mrp.clipplane);
	
	ZShadeSandboxLighting::LightManager::Instance()->BuildFinalLightBuffers(m_pLightCB, m_pSunCB);
	
	ID3D11Buffer* vs_cbs[1] = { m_pShadingCB };
	m_pD3DSystem->GetDeviceContext()->VSSetConstantBuffers(4, 1, vs_cbs);

	// Set the tessellation constant buffer into the Hull Shader
	ID3D11Buffer* hs_cbs[1] = { m_pTessellationCB };
	m_pD3DSystem->GetDeviceContext()->HSSetConstantBuffers(2, 1, hs_cbs);
	
	// Set the matrix constant buffer into the Domain Shader
	ID3D11Buffer* ds_cbs[2] = { m_pDomainCB, m_pShadingCB };
	m_pD3DSystem->GetDeviceContext()->DSSetConstantBuffers(3, 2, ds_cbs);
	
	ID3D11Buffer* ps_cbs[5] = { m_pLightCB, m_pSunCB, m_pTessellationCB, m_pDomainCB, m_pShadingCB };
	m_pD3DSystem->GetDeviceContext()->PSSetConstantBuffers(0, 5, ps_cbs);

	ID3D11ShaderResourceView* ps_srvs[11] = { diffuseArrayTexture, diffuseTexture, ambientTexture, specularTexture, emissiveTexture, normalMapTexture, blendMapTexture, detailMapTexture, alphaMapTexture, shadowMapTexture, ssaoTexture };
	ID3D11SamplerState* ps_samp[2] = { m_pD3DSystem->Point(), m_pD3DSystem->Linear() };

	ID3D11ShaderResourceView* disp_srvs[1] = { displacementMapTexture };

	if (!m_Wireframe)
	{
		// Assign Texture
		
		m_pD3DSystem->GetDeviceContext()->VSSetSamplers(0, 2, ps_samp);
		m_pD3DSystem->GetDeviceContext()->DSSetSamplers(0, 2, ps_samp);
		m_pD3DSystem->GetDeviceContext()->PSSetSamplers(0, 2, ps_samp);
		
		m_pD3DSystem->GetDeviceContext()->VSSetShaderResources(11, 1, disp_srvs);
		m_pD3DSystem->GetDeviceContext()->DSSetShaderResources(11, 1, disp_srvs);
		m_pD3DSystem->GetDeviceContext()->PSSetShaderResources(0, 11, ps_srvs);
		
		switch (mType)
		{
			case ZShadeSandboxLighting::EMaterialTessellationType::Type::eQuad:
				SwitchTo("QuadMaterialTessellationPS", ZShadeSandboxShader::EShaderTypes::ST_PIXEL);
			break;
			case ZShadeSandboxLighting::EMaterialTessellationType::Type::eTri:
				SwitchTo("TriMaterialTessellationPS", ZShadeSandboxShader::EShaderTypes::ST_PIXEL);
			break;
		}
	}
	else
	{
		switch (mType)
		{
			case ZShadeSandboxLighting::EMaterialTessellationType::Type::eQuad:
				SwitchTo("QuadMaterialTessellationWireframePS", ZShadeSandboxShader::EShaderTypes::ST_PIXEL);
			break;
			case ZShadeSandboxLighting::EMaterialTessellationType::Type::eTri:
				SwitchTo("TriMaterialTessellationWireframePS", ZShadeSandboxShader::EShaderTypes::ST_PIXEL);
			break;
		}
	}
	
	if (mrp.useInstancing)
	{
		SetInputLayout("MaterialTessellationShaderInstance");
		switch (mType)
		{
			case ZShadeSandboxLighting::EMaterialTessellationType::Type::eQuad:
				SwitchTo("QuadMaterialTessellationInstanceVS", ZShadeSandboxShader::EShaderTypes::ST_VERTEX);
			break;
			case ZShadeSandboxLighting::EMaterialTessellationType::Type::eTri:
				SwitchTo("TriMaterialTessellationInstanceVS", ZShadeSandboxShader::EShaderTypes::ST_VERTEX);
			break;
		}
	}
	else
	{
		SetInputLayout("MaterialTessellationShader");
		switch (mType)
		{
			case ZShadeSandboxLighting::EMaterialTessellationType::Type::eQuad:
				SwitchTo("QuadMaterialTessellationVS", ZShadeSandboxShader::EShaderTypes::ST_VERTEX);
			break;
			case ZShadeSandboxLighting::EMaterialTessellationType::Type::eTri:
				SwitchTo("TriMaterialTessellationVS", ZShadeSandboxShader::EShaderTypes::ST_VERTEX);
			break;
		}
	}
	
	SetVertexShader();
	SetHullShader();
	SetDomainShader();
	SetPixelShader();
	
	//Perform Drawing
	if (mrp.useInstancing)
	{
		RenderIndexInstanced11(indexCount, instanceCount);
	}
	else
	{
		RenderIndex11(indexCount);
	}

	// Unbind
	if (!m_Wireframe)
	{
		ps_samp[0] = NULL;
		m_pD3DSystem->GetDeviceContext()->VSSetSamplers(0, 2, ps_samp);
		m_pD3DSystem->GetDeviceContext()->DSSetSamplers(0, 2, ps_samp);
		m_pD3DSystem->GetDeviceContext()->PSSetSamplers(0, 2, ps_samp);
		
		disp_srvs[0] = NULL;
		m_pD3DSystem->GetDeviceContext()->VSSetShaderResources(11, 1, disp_srvs);
		m_pD3DSystem->GetDeviceContext()->DSSetShaderResources(11, 1, disp_srvs);

		for (int i = 0; i < 11; i++) ps_srvs[i] = NULL;
		m_pD3DSystem->GetDeviceContext()->PSSetShaderResources(0, 11, ps_srvs);
	}
	
	// Set Hull, Domain and Geometry Shaders to null in case they are not needed
	m_pD3DSystem->GetDeviceContext()->HSSetShader(NULL, NULL, 0);
	m_pD3DSystem->GetDeviceContext()->DSSetShader(NULL, NULL, 0);
	m_pD3DSystem->GetDeviceContext()->GSSetShader(NULL, NULL, 0);

	return true;
}
Пример #17
0
//==============================================================================================================================
bool MaterialShader::Render11
(	int indexCount
    ,	int instanceCount
    ,	ZShadeSandboxMesh::MeshRenderParameters mrp
    ,	ZShadeSandboxLighting::ShaderMaterial* material
)
{
    ID3D11ShaderResourceView* diffuseArrayTexture = 0;
    ID3D11ShaderResourceView* diffuseTexture = 0;
    ID3D11ShaderResourceView* ambientTexture = 0;
    ID3D11ShaderResourceView* specularTexture = 0;
    ID3D11ShaderResourceView* emissiveTexture = 0;
    ID3D11ShaderResourceView* normalMapTexture = 0;
    ID3D11ShaderResourceView* blendMapTexture = 0;
    ID3D11ShaderResourceView* detailMapTexture = 0;
    ID3D11ShaderResourceView* alphaMapTexture = 0;
    ID3D11ShaderResourceView* shadowMapTexture = 0;
    ID3D11ShaderResourceView* ssaoTexture = 0;
    ID3D11ShaderResourceView* displacementMapTexture = 0;

    if (material == 0) return false;

    material->GetTextures(
        diffuseArrayTexture,
        diffuseTexture,
        ambientTexture,
        specularTexture,
        emissiveTexture,
        normalMapTexture,
        blendMapTexture,
        detailMapTexture,
        alphaMapTexture,
        shadowMapTexture,
        ssaoTexture,
        displacementMapTexture
    );

    material->fBlendAmount = mrp.blendAmount;

    material->BuildMaterialConstantBuffer(m_pShadingCB, mrp.camera->Position(), mrp.clipplane);

    // Use the default light if there is no light
    if (mrp.light == 0)
    {
        MaterialShader::mDefaultLight->Update();
        mrp.light = MaterialShader::mDefaultLight;
    }

    mrp.camera->BuildCameraConstantBuffer(m_pD3DSystem, m_pMatrixCB, mrp.light, mrp.world, mrp.reflection);

    if (m_pD3DSystem->GetEngineOptions()->m_DimType == DimType::ZSHADE_3D)
        ZShadeSandboxLighting::LightManager::Instance()->BuildFinalLightBuffers(m_pLightCB, m_pSunCB);
    else
    {
        material->bEnableLighting = false;
        material->bHasDetailMapTexture = false;
    }

    ID3D11Buffer* vs_cbs[2] = { m_pShadingCB, m_pMatrixCB };
    m_pD3DSystem->GetDeviceContext()->VSSetConstantBuffers(2, 2, vs_cbs);

    ID3D11Buffer* ps_cbs[3] = { m_pLightCB, m_pSunCB, m_pShadingCB };
    m_pD3DSystem->GetDeviceContext()->PSSetConstantBuffers(0, 3, ps_cbs);

    ID3D11ShaderResourceView* ps_srvs[11] = { diffuseArrayTexture, diffuseTexture, ambientTexture, specularTexture, emissiveTexture, normalMapTexture, blendMapTexture, detailMapTexture, alphaMapTexture, shadowMapTexture, ssaoTexture };
    ID3D11SamplerState* ps_samp[2] = { m_pD3DSystem->Point(), m_pD3DSystem->Linear() };

    ID3D11ShaderResourceView* vs_srvs[1] = { displacementMapTexture };

    if (!m_Wireframe)
    {
        // Assign Texture

        m_pD3DSystem->GetDeviceContext()->VSSetSamplers(0, 2, ps_samp);
        m_pD3DSystem->GetDeviceContext()->PSSetSamplers(0, 2, ps_samp);

        m_pD3DSystem->GetDeviceContext()->VSSetShaderResources(11, 1, vs_srvs);
        m_pD3DSystem->GetDeviceContext()->PSSetShaderResources(0, 11, ps_srvs);

        SwitchTo("MaterialShaderPS", ZShadeSandboxShader::EShaderTypes::ST_PIXEL);
    }
    else
    {
        SwitchTo("MaterialShaderWireframePS", ZShadeSandboxShader::EShaderTypes::ST_PIXEL);
    }

    if (mrp.useInstancing)
    {
        SetInputLayout("MaterialShaderInstance");
        SwitchTo("MaterialShaderInstanceVS", ZShadeSandboxShader::EShaderTypes::ST_VERTEX);
    }
    else
    {
        SetInputLayout("MaterialShader");
        SwitchTo("MaterialShaderVS", ZShadeSandboxShader::EShaderTypes::ST_VERTEX);
    }

    SetVertexShader();
    SetPixelShader();

    //Perform Drawing
    if (mrp.useInstancing)
    {
        RenderIndexInstanced11(indexCount, instanceCount);
    }
    else
    {
        RenderIndex11(indexCount);
    }

    // Unbind
    if (!m_Wireframe)
    {
        ps_samp[0] = NULL;
        ps_samp[1] = NULL;
        m_pD3DSystem->GetDeviceContext()->VSSetSamplers(0, 2, ps_samp);
        m_pD3DSystem->GetDeviceContext()->PSSetSamplers(0, 2, ps_samp);

        vs_srvs[0] = NULL;
        m_pD3DSystem->GetDeviceContext()->VSSetShaderResources(11, 1, vs_srvs);

        for (int i = 0; i < 11; i++) ps_srvs[i] = NULL;
        m_pD3DSystem->GetDeviceContext()->PSSetShaderResources(0, 11, ps_srvs);
    }

    return true;
}
//==============================================================================================================================
bool AmbientLightDeferredShader::Render11
(	Camera* camera
,	ZShadeSandboxLighting::AmbientLight* light
,	XMFLOAT3 ambientUp
,	XMFLOAT3 ambientDown
,	ID3D11ShaderResourceView* colorTexture
,	ID3D11ShaderResourceView* normalTexture
,	ID3D11ShaderResourceView* depthTexture
)
{
	cbDeferredLightBuffer cLB;
	cLB.g_AmbientLightColor = light->DiffuseColor();
	cLB.g_AmbientDown = ambientDown;
	cLB.padding1 = 0;
	cLB.g_AmbientUp = ambientUp;
	cLB.padding2 = 0;
	cLB.g_InvViewProj = camera->InvViewProj4x4();
	// Map the light buffer
	{
		D3D11_MAPPED_SUBRESOURCE mapped_res2;
		m_pD3DSystem->GetDeviceContext()->Map(m_pLightCB, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped_res2);
		{
			assert(mapped_res2.pData);
			*(cbDeferredLightBuffer*)mapped_res2.pData = cLB;
		}
		m_pD3DSystem->GetDeviceContext()->Unmap(m_pLightCB, 0);
	}
	
	ID3D11Buffer* ps_cbs[1] = { m_pLightCB };
	m_pD3DSystem->GetDeviceContext()->PSSetConstantBuffers(0, 1, ps_cbs);
	
	// Assign Texture
	ID3D11ShaderResourceView* ps_srvs[3] = { colorTexture, normalTexture, depthTexture };
	ID3D11SamplerState* ps_samp[2] = { m_pD3DSystem->Point(), m_pD3DSystem->Linear() };
	
	if (!m_Wireframe)
	{
		m_pD3DSystem->GetDeviceContext()->PSSetShaderResources(0, 3, ps_srvs);
		m_pD3DSystem->GetDeviceContext()->PSSetSamplers(0, 2, ps_samp);
		
		SwitchTo("AmbientLightDeferredPS", ZShadeSandboxShader::EShaderTypes::ST_PIXEL);
	}
	else
	{
		SwitchTo("AmbientLightDeferredWireframePS", ZShadeSandboxShader::EShaderTypes::ST_PIXEL);
	}
	
	m_pD3DSystem->TurnOnAdditiveBlending();
	//m_pD3DSystem->TurnOnAlphaBlending();
	
	SetVertexShader();
	SetPixelShader();
	
	//Perform Drawing onto a fullscreen quad with a NULL Input Layout
	RenderDraw11(4);
	
	//m_pD3DSystem->TurnOffAlphaBlending();
	m_pD3DSystem->TurnOffAdditiveBlending();
	
	// Unbind
	if (!m_Wireframe)
	{
		ps_samp[0] = NULL;
		ps_samp[1] = NULL;
		m_pD3DSystem->GetDeviceContext()->PSSetSamplers(0, 2, ps_samp);
		ps_srvs[0] = NULL;
		ps_srvs[1] = NULL;
		ps_srvs[2] = NULL;
		m_pD3DSystem->GetDeviceContext()->PSSetShaderResources(0, 3, ps_srvs);
	}
	
	return true;
}
Пример #19
0
//==============================================================================================================================
bool OBJMeshShader::Render(int startIndex, int indexCount, Camera* camera, XMMATRIX wvp, XMFLOAT4 clipplane, XMFLOAT4 difColor, bool hasTexture,
	ID3D11ShaderResourceView* texture)
{
	cbOBJShadingConst cSC;
	cbMatrixBuffer cMB;
	
	cMB.g_WVPMatrix = ZShadeSandboxMath::ZMath::GMathMF(XMMatrixTranspose(wvp));
	
	//if (m_UseCustomWorld)
	//	cMB.g_WorldMatrix = ZShadeSandboxMath::ZMath::GMathMF(XMMatrixTranspose(mWorld.Get()));
	//else
	//	cMB.g_WorldMatrix = camera->World4x4();
	
	cSC.g_ClipPlane = clipplane;
	cSC.g_DifColor = difColor;
	cSC.padding = XMFLOAT2(0, 0);
	cSC.g_FarPlane = fFarPlane;
	cSC.g_hasTexture = (hasTexture == true) ? 1 : 0;
	
	// Map shading constants
	{
		D3D11_MAPPED_SUBRESOURCE mapped_res;
		m_pD3DSystem->GetDeviceContext()->Map(m_pOBJShadingCB, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped_res);
		{
			assert(mapped_res.pData);
			*(cbOBJShadingConst*)mapped_res.pData = cSC;
		}
		m_pD3DSystem->GetDeviceContext()->Unmap(m_pOBJShadingCB, 0);
	}
	
	// Map matrix constants
	{
		D3D11_MAPPED_SUBRESOURCE mapped_res;
		m_pD3DSystem->GetDeviceContext()->Map(m_pMatrixBufferCB, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped_res);
		{
			assert(mapped_res.pData);
			*(cbMatrixBuffer*)mapped_res.pData = cMB;
		}
		m_pD3DSystem->GetDeviceContext()->Unmap(m_pMatrixBufferCB, 0);
	}
	
	// Set the shading constant buffer and matrix constant buffer into the Vertex ZShadeSandboxShader::Shader
	ID3D11Buffer* vs_cbs[2] = { m_pOBJShadingCB, m_pMatrixBufferCB };
	m_pD3DSystem->GetDeviceContext()->VSSetConstantBuffers(0, 2, vs_cbs);
	
	// Set the shading constant buffer into the Pixel Shader
	ID3D11Buffer* ps_cbs[1] = { m_pOBJShadingCB };
	m_pD3DSystem->GetDeviceContext()->PSSetConstantBuffers(0, 1, ps_cbs);
	
	ID3D11ShaderResourceView* ps_srvs[1] = { texture };
	ID3D11SamplerState* ps_samp[1] = { m_pD3DSystem->Linear() };
	
	if (!m_Wireframe)
	{
		m_pD3DSystem->TurnOffCulling();

		// Set the texture into the Pixel Shader
		if (hasTexture)
		{
			m_pD3DSystem->GetDeviceContext()->PSSetShaderResources(0, 1, ps_srvs);
			m_pD3DSystem->GetDeviceContext()->PSSetSamplers(0, 1, ps_samp);
		}

		SwitchTo("OBJMeshPS", ZShadeSandboxShader::EShaderTypes::ST_PIXEL);
	}
	else
	{
		SwitchTo("OBJMeshWireframePS", ZShadeSandboxShader::EShaderTypes::ST_PIXEL);
	}

	// Tell the shader what input layout to use
	SetInputLayout("OBJMeshShader");
	
	// Assign the shaders to render the mesh
	SetVertexShader();
	SetPixelShader();
	
	//Perform Drawing
	RenderIndex11(startIndex, indexCount);

	if (!m_Wireframe)
	{
		m_pD3DSystem->TurnOnCulling();
	}

	// Unbind
	if (!m_Wireframe && hasTexture)
	{
		ps_samp[0] = NULL;
		m_pD3DSystem->GetDeviceContext()->PSSetSamplers(0, 1, ps_samp);

		ps_srvs[0] = NULL;
		m_pD3DSystem->GetDeviceContext()->PSSetShaderResources(0, 1, ps_srvs);
	}
	
	return true;
}
Пример #20
0
//==============================================================================
// shader
//------------------------------------------------------------------------------
void Shader::setVtxShader(unsigned int id) {
  auto pDevice = App::instance().getRenderer()->getDevice();
  _nowVtxShader = _vtxShaderList[id];
  pDevice->SetVertexShader(_nowVtxShader->_shader);
}
//==============================================================================================================================
bool TerrainTessellationQuadShadowShader::Render(int indexCount, LightCamera* lightcamera,
	ZShadeSandboxTerrain::TerrainShadingConst terrainShadingConst, ID3D11ShaderResourceView* heightMapSRV)
{
	cTessellationBuffer cTB;
	cMatrixBuffer cMB;
	cDomainConstBuffer cDCB;
	
	m_pD3DSystem->SetRasterizerState(m_pD3DSystem->RSDepth());
	
	//if (m_UseCustomWorld)
	//	cMB.g_WorldMatrix = ZShadeSandboxMath::ZMath::GMathMF(XMMatrixTranspose(mWorld.Get()));
	//else
	//	cMB.g_WorldMatrix = ZShadeSandboxMath::ZMath::GMathMF(XMMatrixTranspose(XMMatrixIdentity()));
	
	cMB.g_ViewMatrix = lightcamera->LightView4x4();
	cMB.g_ProjMatrix = lightcamera->LightProj4x4();
	cMB.g_ShadowMatrix = lightcamera->ShadowTransform4x4();

	XMMATRIX toTexSpace = XMMatrixScaling(0.5f, -0.5f, 1.0f) * XMMatrixTranslation(0.5f, 0.5f, 0);
	cMB.g_TexSpaceMatrix = ZShadeSandboxMath::ZMath::GMathMF(XMMatrixTranspose(toTexSpace));
	
	cTB.g_EyePosW = terrainShadingConst.g_EyePosW;
	cTB.g_MinDist = terrainShadingConst.g_MinDist;
	cTB.g_MaxDist = terrainShadingConst.g_MaxDist;
	cTB.g_MinTess = terrainShadingConst.g_MinTess;
	cTB.g_MaxTess = terrainShadingConst.g_MaxTess;
	cTB.g_FrustumCull = terrainShadingConst.g_FrustumCull;
	cTB.padding = XMFLOAT2(0, 0);
	cTB.g_TerrSize = terrainShadingConst.g_MapSize;
	cTB.g_TerrScale = terrainShadingConst.g_TerrSize;

	cDCB.g_TexScale = XMFLOAT2(66.0f, 66.0f);
	cDCB.g_HeightScale = terrainShadingConst.g_HeightScale;
	cDCB.g_TerrainZScale = terrainShadingConst.g_TerrSize;
	cDCB.g_ClipPlane = terrainShadingConst.g_ClipPlane;
	cDCB.g_tpadding = XMFLOAT3(0, 0, 0);
	cDCB.g_FarPlane = terrainShadingConst.g_FarPlane;
	
	// Map tessellation constants
	{
		D3D11_MAPPED_SUBRESOURCE mapped_res;
		m_pD3DSystem->GetDeviceContext()->Map(m_pTessellationCB, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped_res);
		{
			assert(mapped_res.pData);
			*(cTessellationBuffer*)mapped_res.pData = cTB;
		}
		m_pD3DSystem->GetDeviceContext()->Unmap(m_pTessellationCB, 0);
	}
	
	// Map domain shader constants
	{
		D3D11_MAPPED_SUBRESOURCE mapped_res;
		m_pD3DSystem->GetDeviceContext()->Map(m_pDomainCB, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped_res);
		{
			assert(mapped_res.pData);
			*(cDomainConstBuffer*)mapped_res.pData = cDCB;
		}
		m_pD3DSystem->GetDeviceContext()->Unmap(m_pDomainCB, 0);
	}
	
	// Map matrix constants
	{
		D3D11_MAPPED_SUBRESOURCE mapped_res;
		m_pD3DSystem->GetDeviceContext()->Map(m_pMatrixBufferCB, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped_res);
		{
			assert(mapped_res.pData);
			*(cMatrixBuffer*)mapped_res.pData = cMB;
		}
		m_pD3DSystem->GetDeviceContext()->Unmap(m_pMatrixBufferCB, 0);
	}
	
	// Set the tessellation constant buffer into the Hull Shader
	ID3D11Buffer* hs_cbs[1] = { m_pTessellationCB };
	m_pD3DSystem->GetDeviceContext()->HSSetConstantBuffers(0, 1, hs_cbs);
	
	// Set the domain and matrix constant buffer into the Domain Shader
	ID3D11Buffer* ds_cbs[2] = { m_pDomainCB, m_pMatrixBufferCB };
	m_pD3DSystem->GetDeviceContext()->DSSetConstantBuffers(0, 2, ds_cbs);
	
	// Set the heightmap texture into the vertex shader
	ID3D11ShaderResourceView* vs_srvs[1] = { heightMapSRV };
	m_pD3DSystem->GetDeviceContext()->VSSetShaderResources(0, 1, vs_srvs);
	
	// Set the heightmap texture into the domain shader
	ID3D11ShaderResourceView* ds_srvs[1] = { heightMapSRV };
	m_pD3DSystem->GetDeviceContext()->DSSetShaderResources(0, 1, ds_srvs);
	
	// Tell the shader what input layout to use
	SetInputLayout("TerrainTessellationQuadShadowShader");
	
	// Assign the shaders to render the mesh
	SetVertexShader();
	SetHullShader();
	SetDomainShader();
	SetPixelShader();

	//m_pD3DSystem->GetDeviceContext()->PSSetShader(NULL, NULL, 0);
	
	//Perform Drawing
	RenderIndex11(indexCount);
	
	return true;
}
//==============================================================================================================================
bool TerrainTessellationQuadSSAOShader::Render(int indexCount, Camera* camera, LightCamera* lightcamera, ZShadeSandboxTerrain::TerrainShadingConst terrainShadingConst, ID3D11ShaderResourceView* heightMapSRV)
{
	cTessellationBuffer cTB;
	cMatrixBuffer cMB;
	cDomainConstBuffer cDCB;
	cShadingConstBuffer cSCB;

	//if (m_UseCustomWorld)
	//	cMB.g_WorldMatrix = ZShadeSandboxMath::ZMath::GMathMF(XMMatrixTranspose(mWorld.Get()));
	//else
	//	cMB.g_WorldMatrix = camera->World4x4();

	cMB.g_ViewMatrix = camera->View4x4();

	cMB.g_ProjMatrix = camera->Proj4x4();

	XMMATRIX toTexSpace = XMMatrixScaling(0.5f, -0.5f, 1.0f) * XMMatrixTranslation(0.5f, 0.5f, 0);
	cMB.g_TexSpaceMatrix = ZShadeSandboxMath::ZMath::GMathMF(XMMatrixTranspose(toTexSpace));

	// Need to create the shadow matrix
	cMB.g_ShadowMatrix = lightcamera->ShadowTransform4x4();

	cTB.g_EyePosW = terrainShadingConst.g_EyePosW;
	cTB.g_MinDist = terrainShadingConst.g_MinDist;
	cTB.g_MaxDist = terrainShadingConst.g_MaxDist;
	cTB.g_MinTess = terrainShadingConst.g_MinTess;
	cTB.g_MaxTess = terrainShadingConst.g_MaxTess;
	cTB.g_FrustumCull = terrainShadingConst.g_FrustumCull;
	cTB.padding = XMFLOAT2(0, 0);
	cTB.g_TerrSize = terrainShadingConst.g_MapSize;
	cTB.g_TerrScale = terrainShadingConst.g_TerrSize;

	cDCB.g_TexScale = XMFLOAT2(66.0f, 66.0f);
	cDCB.g_HeightScale = terrainShadingConst.g_HeightScale;
	cDCB.g_TerrainZScale = terrainShadingConst.g_TerrSize;
	cDCB.g_ClipPlane = terrainShadingConst.g_ClipPlane;
	cDCB.g_tpadding = XMFLOAT3(0, 0, 0);
	cDCB.g_FarPlane = terrainShadingConst.g_FarPlane;

	cSCB.g_EyePosW = terrainShadingConst.g_EyePosW;
	cSCB.g_DetailBrightness = terrainShadingConst.g_DetailBrightness;
	cSCB.g_fogThinning = terrainShadingConst.g_fogThinning;
	cSCB.g_fogAltitude = terrainShadingConst.g_fogAltitude;
	cSCB.g_fogNear = terrainShadingConst.g_fogNear;
	cSCB.g_fogFar = terrainShadingConst.g_fogFar;
	cSCB.g_fogColor = terrainShadingConst.g_fogColor;
	cSCB.g_TextureAmount = terrainShadingConst.g_TextureAmount;
	cSCB.g_TextureWidth = terrainShadingConst.g_TextureWidth;
	cSCB.g_TextureHeight = terrainShadingConst.g_TextureHeight;
	cSCB.g_seaLevel = terrainShadingConst.g_seaLevel;
	cSCB.g_waterBodyColor = terrainShadingConst.g_waterBodyColor;
	//cSCB.g_SunDir = terrainShadingConst.g_SunDir;
	//cSCB.g_EnableSun = terrainShadingConst.g_EnableSun;
	//cSCB.g_SunDiffuseColor = terrainShadingConst.g_SunDiffuseColor;
	cSCB.g_MaterialDiffuseColor = terrainShadingConst.g_MaterialDiffuseColor;
	cSCB.g_MaterialAmbientColor = terrainShadingConst.g_MaterialAmbientColor;
	cSCB.g_TexelCellSpaceU = terrainShadingConst.g_TexelCellSpaceU;
	cSCB.g_TexelCellSpaceV = terrainShadingConst.g_TexelCellSpaceV;
	cSCB.g_MaterialSpecularPower = terrainShadingConst.g_MaterialSpecularPower;
	cSCB.g_MaterialSpecularIntensity = terrainShadingConst.g_MaterialSpecularIntensity;
	cSCB.g_useClippingPlane = terrainShadingConst.g_useClippingPlane;
	cSCB.g_useNormalMap = terrainShadingConst.g_useNormalMap;
	cSCB.g_UseSobelFilter = terrainShadingConst.g_UseSobelFilter;
	cSCB.g_useShadowMap = terrainShadingConst.g_useShadowMap;
	cSCB.tpadding = XMFLOAT3(0, 0, 0);
	cSCB.g_useSSAO = terrainShadingConst.g_useSSAO;
	cSCB.g_ViewMatrix = cMB.g_ViewMatrix;

	ZShadeSandboxLighting::LightManager::Instance()->BuildFinalLightBuffers(m_pLightCB, m_pSunCB);

	// Map tessellation constants
	{
		D3D11_MAPPED_SUBRESOURCE mapped_res;
		m_pD3DSystem->GetDeviceContext()->Map(m_pTessellationCB, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped_res);
		{
			assert(mapped_res.pData);
			*(cTessellationBuffer*)mapped_res.pData = cTB;
		}
		m_pD3DSystem->GetDeviceContext()->Unmap(m_pTessellationCB, 0);
	}

	// Map domain shader constants
	{
		D3D11_MAPPED_SUBRESOURCE mapped_res;
		m_pD3DSystem->GetDeviceContext()->Map(m_pDomainCB, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped_res);
		{
			assert(mapped_res.pData);
			*(cDomainConstBuffer*)mapped_res.pData = cDCB;
		}
		m_pD3DSystem->GetDeviceContext()->Unmap(m_pDomainCB, 0);
	}

	// Map matrix constants
	{
		D3D11_MAPPED_SUBRESOURCE mapped_res;
		m_pD3DSystem->GetDeviceContext()->Map(m_pMatrixBufferCB, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped_res);
		{
			assert(mapped_res.pData);
			*(cMatrixBuffer*)mapped_res.pData = cMB;
		}
		m_pD3DSystem->GetDeviceContext()->Unmap(m_pMatrixBufferCB, 0);
	}

	// Map pixel shading constants
	{
		D3D11_MAPPED_SUBRESOURCE mapped_res;
		m_pD3DSystem->GetDeviceContext()->Map(m_pShadingCB, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped_res);
		{
			assert(mapped_res.pData);
			*(cShadingConstBuffer*)mapped_res.pData = cSCB;
		}
		m_pD3DSystem->GetDeviceContext()->Unmap(m_pShadingCB, 0);
	}

	// Set the tessellation constant buffer into the Hull ZShadeSandboxShader::Shader
	ID3D11Buffer* hs_cbs[1] = { m_pTessellationCB };
	m_pD3DSystem->GetDeviceContext()->HSSetConstantBuffers(0, 1, hs_cbs);

	// Set the domain constant buffer into the Domain ZShadeSandboxShader::Shader
	// Set the matrix constant buffer into the Domain ZShadeSandboxShader::Shader
	ID3D11Buffer* ds_cbs[2] = { m_pDomainCB, m_pMatrixBufferCB };
	m_pD3DSystem->GetDeviceContext()->DSSetConstantBuffers(0, 2, ds_cbs);

	// Set the shading constant buffer into the Pixel ZShadeSandboxShader::Shader
	ID3D11Buffer* ps_cbs[3] = { m_pShadingCB, m_pLightCB, m_pSunCB };
	m_pD3DSystem->GetDeviceContext()->PSSetConstantBuffers(0, 3, ps_cbs);

	// Set the heightmap texture into the vertex shader
	ID3D11ShaderResourceView* vs_srvs[1] = { heightMapSRV };
	m_pD3DSystem->GetDeviceContext()->VSSetShaderResources(0, 1, vs_srvs);

	// Set the heightmap texture into the domain shader
	ID3D11ShaderResourceView* ds_srvs[1] = { heightMapSRV };
	m_pD3DSystem->GetDeviceContext()->DSSetShaderResources(0, 1, ds_srvs);

	// Set the textures into the Pixel Shader
	ID3D11ShaderResourceView* ps_srvs[1] = { heightMapSRV };
	m_pD3DSystem->GetDeviceContext()->PSSetShaderResources(0, 1, ps_srvs);

	// Tell the shader what input layout to use
	SetInputLayout("TerrainTessellationQuadSSAOShader");

	// Assign the shaders to render the mesh
	SetVertexShader();
	SetHullShader();
	SetDomainShader();
	SetPixelShader();

	//Perform Drawing
	RenderIndex11(indexCount);

	return true;
}
//==============================================================================================================================
bool TriMaterialTessellationShader::Render11(int indexCount, ZShadeSandboxMath::XMMath4 clipplane, Camera* camera, float tessFactor, ZShadeSandboxLighting::ShaderMaterial* material)
{
	int useDiffuseArrayTexture = 0;
	int useDiffuseTexture = 0;
	int useNormalMapTexture = 0;
	int useBlendMapTexture = 0;
	int useDetailMapTexture = 0;
	int useAlphaMapTexture = 0;
	
	ID3D11ShaderResourceView* diffuseArrayTexture = 0;
	ID3D11ShaderResourceView* diffuseTexture = 0;
	ID3D11ShaderResourceView* normalMapTexture = 0;
	ID3D11ShaderResourceView* blendMapTexture = 0;
	ID3D11ShaderResourceView* detailMapTexture = 0;
	ID3D11ShaderResourceView* alphaMapTexture = 0;
	
	for (int i = 0; i < material->TextureCount(); i++)
	{
		switch (material->GetMaterialTextureType(i))
		{
			case ZShadeSandboxLighting::EMaterialTextureType::eDiffuseArray:
				useDiffuseArrayTexture = 1;
				diffuseArrayTexture = material->GetTexture(i)->getTexture11();
			break;
			case ZShadeSandboxLighting::EMaterialTextureType::eDiffuse:
				useDiffuseTexture = 1;
				diffuseTexture = material->GetTexture(i)->getTexture11();
			break;
			case ZShadeSandboxLighting::EMaterialTextureType::eNormal:
				useNormalMapTexture = 1;
				normalMapTexture = material->GetTexture(i)->getTexture11();
			break;
			case ZShadeSandboxLighting::EMaterialTextureType::eBlend:
				useBlendMapTexture = 1;
				blendMapTexture = material->GetTexture(i)->getTexture11();
			break;
			case ZShadeSandboxLighting::EMaterialTextureType::eDetail:
				useDetailMapTexture = 1;
				detailMapTexture = material->GetTexture(i)->getTexture11();
			break;
			case ZShadeSandboxLighting::EMaterialTextureType::eAlpha:
				useAlphaMapTexture = 1;
				alphaMapTexture = material->GetTexture(i)->getTexture11();
			break;
		}
	}
	
	Const_Per_Frame per_frame;
	per_frame.g_EyePosW = camera->Position();
	per_frame.g_ClipPlane = XMFLOAT4(clipplane.x, clipplane.y, clipplane.z, clipplane.w);
	per_frame.g_MaterialDiffuseColor = material->DiffuseColor();
	per_frame.g_MaterialAmbientColor = material->AmbientColor();
	per_frame.g_MaterialSpecularPower = material->SpecularPower();
	per_frame.g_MaterialSpecularIntensity = material->SpecularIntensity();
	per_frame.g_UsingDiffuseArrayTexture = useDiffuseArrayTexture;
	per_frame.g_UsingDiffuseTexture = useDiffuseArrayTexture;
	per_frame.g_UsingNormalMapTexture = useNormalMapTexture;
	per_frame.g_UsingBlendMapTexture = useBlendMapTexture;
	per_frame.g_UsingDetailMapTexture = useDetailMapTexture;
	per_frame.g_UseAlphaMapTexture = useAlphaMapTexture;
	per_frame.g_EnableTransparency = material->EnableTransparency();
	per_frame.g_EnableLighting = material->EnableLighting();
	per_frame.g_DetailBrightness = material->DetailBrightness();
	per_frame.g_AlphaToCoverageValue = material->AlphaToCoverageValue(); // Value that clips pixel during alpha blending
	per_frame.g_FlipTextureH = (bFlipHorizontally == true) ? 1 : 0;
	per_frame.g_FlipTextureV = (bFlipVertically == true) ? 1 : 0;
	per_frame.padding = 0;
	
	Const_Per_Object per_object;
	
	if (m_UseCustomWorld)
	{
		XMFLOAT4X4 world = ZShadeSandboxMath::ZMath::GMathMF(XMMatrixTranspose(mWorld.Get()));
		per_object.g_matWorld = world;
	}
	else
		per_object.g_matWorld = camera->World4x4();

	if (m_UseCustomView)
	{
		per_object.g_matView = mView;
	}
	else
		per_object.g_matView = camera->View4x4();

	if (m_pD3DSystem->GetEngineOptions()->m_DimType == DimType::ZSHADE_2D)
		per_object.g_matProj = camera->Ortho4x4();
	else if (m_pD3DSystem->GetEngineOptions()->m_DimType == DimType::ZSHADE_3D)
		per_object.g_matProj = camera->Proj4x4();

	if (m_UseOrtho)
	{
		per_object.g_matProj = camera->Ortho4x4();
	}
	
	ZShadeSandboxLighting::cbLightBuffer cLB;
	ZShadeSandboxLighting::cbAmbientLightBuffer alb;
	ZShadeSandboxLighting::cbDirectionalLightBuffer dlb;
	ZShadeSandboxLighting::cbSpotLightBuffer slb;
	ZShadeSandboxLighting::cbPointLightBuffer plb;
	ZShadeSandboxLighting::cbCapsuleLightBuffer clb;

	for (int i = 0; i < material->GetLightBuffer()->g_AmbientLightCount; i++)
	{
		alb.g_AmbientColor = material->GetLightBuffer()->g_AmbientLight[i].g_AmbientColor;
		cLB.g_AmbientLight[i] = alb;
	}
	for (int i = 0; i < material->GetLightBuffer()->g_DirectionalLightCount; i++)
	{
		dlb.g_Direction = material->GetLightBuffer()->g_DirectionalLight[i].g_LightDirection;
		dlb.padding = 0;
		dlb.g_Ambient = material->GetLightBuffer()->g_DirectionalLight[i].g_AmbientColor;
		dlb.g_Diffuse = material->GetLightBuffer()->g_DirectionalLight[i].g_DiffuseColor;
		cLB.g_DirectionalLight[i] = dlb;
	}
	for (int i = 0; i < material->GetLightBuffer()->g_SpotLightCount; i++)
	{
		slb.g_AmbientColor = material->GetLightBuffer()->g_SpotLight[i].g_AmbientColor;
		slb.g_DiffuseColor = material->GetLightBuffer()->g_SpotLight[i].g_DiffuseColor;
		slb.g_LightPosition = material->GetLightBuffer()->g_SpotLight[i].g_LightPosition;
		slb.padding = 0;
		slb.g_LightRange = material->GetLightBuffer()->g_SpotLight[i].g_LightRange;
		slb.g_SpotCosOuterCone = material->GetLightBuffer()->g_SpotLight[i].g_SpotCosOuterCone;
		slb.g_SpotInnerConeReciprocal = material->GetLightBuffer()->g_SpotLight[i].g_SpotInnerConeReciprocal;
		slb.g_CosineAngle = material->GetLightBuffer()->g_SpotLight[i].g_CosineAngle;
		cLB.g_SpotLight[i] = slb;
	}
	for (int i = 0; i < material->GetLightBuffer()->g_PointLightCount; i++)
	{
		plb.g_LightPosition = material->GetLightBuffer()->g_PointLight[i].g_LightPosition;
		plb.g_LightRange = material->GetLightBuffer()->g_PointLight[i].g_LightRange;
		plb.g_Attenuation = material->GetLightBuffer()->g_PointLight[i].g_Attenuation;
		plb.padding = 0;
		plb.g_AmbientColor = material->GetLightBuffer()->g_PointLight[i].g_AmbientColor;
		plb.g_DiffuseColor = material->GetLightBuffer()->g_PointLight[i].g_DiffuseColor;
		cLB.g_PointLight[i] = plb;
	}
	for (int i = 0; i < material->GetLightBuffer()->g_CapsuleLightCount; i++)
	{
		clb.g_LightPosition = material->GetLightBuffer()->g_CapsuleLight[i].g_LightPosition;
		clb.g_LightRange = material->GetLightBuffer()->g_CapsuleLight[i].g_LightRange;
		clb.g_LightDirection = material->GetLightBuffer()->g_CapsuleLight[i].g_LightDirection;
		clb.g_DiffuseColor = material->GetLightBuffer()->g_CapsuleLight[i].g_DiffuseColor;
		clb.g_LightLength = material->GetLightBuffer()->g_CapsuleLight[i].g_LightLength;
		clb.g_CapsuleDirectionLength = material->GetLightBuffer()->g_CapsuleLight[i].g_CapsuleDirectionLength;
		clb.g_CapsuleIntensity = material->GetLightBuffer()->g_CapsuleLight[i].g_CapsuleIntensity;
		cLB.g_CapsuleLight[i] = clb;
	}
	cLB.g_AmbientLightCount = material->GetLightBuffer()->g_AmbientLightCount;
	cLB.g_DirectionalLightCount = material->GetLightBuffer()->g_DirectionalLightCount;
	cLB.g_SpotLightCount = material->GetLightBuffer()->g_SpotLightCount;
	cLB.g_PointLightCount = material->GetLightBuffer()->g_PointLightCount;
	cLB.g_CapsuleLightCount = material->GetLightBuffer()->g_CapsuleLightCount;
	cLB.g_AmbientDown = material->GetLightBuffer()->g_AmbientDown;
	cLB.g_AmbientUp = material->GetLightBuffer()->g_AmbientUp;
	cLB.padding = 0;
	
	ZShadeSandboxLighting::cbSunLightBuffer cSLB;
	cSLB.g_SunDir = material->GetSunLightBuffer()->g_SunDir;
	cSLB.g_EnableSun = material->GetSunLightBuffer()->g_EnableSun;
	cSLB.g_SunDiffuseColor = material->GetSunLightBuffer()->g_SunDiffuseColor;
	cSLB.padding = XMFLOAT3(0, 0, 0);
	cSLB.g_SunShineness = material->GetSunLightBuffer()->g_SunShineness;
	
	cTessellationBuffer cTB;
	cTB.g_TessellationFactor = tessFactor;
	cTB.padding = XMFLOAT3(0, 0, 0);
	
	// Map tessellation constants
	{
		D3D11_MAPPED_SUBRESOURCE mapped_res;
		m_pD3DSystem->GetDeviceContext()->Map(m_pTessellationCB, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped_res);
		{
			assert(mapped_res.pData);
			*(cTessellationBuffer*)mapped_res.pData = cTB;
		}
		m_pD3DSystem->GetDeviceContext()->Unmap(m_pTessellationCB, 0);
	}
	
	// Map the per frame constants
	{
	D3D11_MAPPED_SUBRESOURCE mapped_res;
		m_pD3DSystem->GetDeviceContext()->Map(m_pPerFrameCB, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped_res);
		{
			assert(mapped_res.pData);
			*(Const_Per_Frame*)mapped_res.pData = per_frame;
		}
		m_pD3DSystem->GetDeviceContext()->Unmap(m_pPerFrameCB, 0);
	}
	
	// Map the matrix constants
	{
		D3D11_MAPPED_SUBRESOURCE mapped_res2;
		m_pD3DSystem->GetDeviceContext()->Map(m_pPerObjectCB, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped_res2);
		{
			assert(mapped_res2.pData);
			*(Const_Per_Object*)mapped_res2.pData = per_object;
		}
		m_pD3DSystem->GetDeviceContext()->Unmap(m_pPerObjectCB, 0);
	}
	
	// Map light shading constants
	{
		D3D11_MAPPED_SUBRESOURCE mapped_res;
		m_pD3DSystem->GetDeviceContext()->Map(m_pLightCB, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped_res);
		{
			assert(mapped_res.pData);
			*(ZShadeSandboxLighting::cbLightBuffer*)mapped_res.pData = cLB;
		}
		m_pD3DSystem->GetDeviceContext()->Unmap(m_pLightCB, 0);
	}
	
	// Map sun light shading constants
	{
		D3D11_MAPPED_SUBRESOURCE mapped_res;
		m_pD3DSystem->GetDeviceContext()->Map(m_pSunCB, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped_res);
		{
			assert(mapped_res.pData);
			*(ZShadeSandboxLighting::cbSunLightBuffer*)mapped_res.pData = cSLB;
		}
		m_pD3DSystem->GetDeviceContext()->Unmap(m_pSunCB, 0);
	}
	
	// Set the tessellation constant buffer into the Hull Shader
	ID3D11Buffer* hs_cbs[1] = { m_pTessellationCB };
	m_pD3DSystem->GetDeviceContext()->HSSetConstantBuffers(0, 1, hs_cbs);
	
	// Set the matrix constant buffer into the Domain Shader
	ID3D11Buffer* ds_cbs[2] = { m_pPerFrameCB, m_pPerObjectCB };
	m_pD3DSystem->GetDeviceContext()->DSSetConstantBuffers(0, 2, ds_cbs);
	
	//ID3D11Buffer* vs_cbs[2] = { m_pPerFrameCB, m_pPerObjectCB };
	//m_pD3DSystem->GetDeviceContext()->VSSetConstantBuffers(0, 2, vs_cbs);
	
	ID3D11Buffer* ps_cbs[3] = { m_pPerFrameCB, m_pLightCB, m_pSunCB };
	m_pD3DSystem->GetDeviceContext()->PSSetConstantBuffers(0, 3, ps_cbs);

	ID3D11ShaderResourceView* ps_srvs[6] = { diffuseArrayTexture, diffuseTexture, normalMapTexture, blendMapTexture, detailMapTexture, alphaMapTexture };
	
	if (!m_Wireframe)
	{
		// Assign Texture
		m_pD3DSystem->GetDeviceContext()->PSSetShaderResources(0, 6, ps_srvs);

		SwitchTo("MaterialTessellationShaderPS", ZShadeSandboxShader::EShaderTypes::ST_PIXEL);
	}
	else
	{
		SwitchTo("MaterialTessellationShaderWireframePS", ZShadeSandboxShader::EShaderTypes::ST_PIXEL);
	}
	
	SetVertexShader();
	SetHullShader();
	SetDomainShader();
	SetPixelShader();

	SetInputLayout("TriMaterialTessellationShader");

	//Perform Drawing
	RenderIndex11(indexCount);

	// Unbind
	if (!m_Wireframe)
	{
		for (int i = 0; i < 6; i++) ps_srvs[i] = NULL;
		m_pD3DSystem->GetDeviceContext()->PSSetShaderResources(0, 6, ps_srvs);
	}
	
	// Set Hull, Domain and Geometry Shaders to null in case they are not needed
	m_pD3DSystem->GetDeviceContext()->HSSetShader(NULL, NULL, 0);
	m_pD3DSystem->GetDeviceContext()->DSSetShader(NULL, NULL, 0);
	m_pD3DSystem->GetDeviceContext()->GSSetShader(NULL, NULL, 0);

	return true;
}
Пример #24
0
//=============================================================================
// draw
//=============================================================================
void Title::Draw()
{
	auto graphic_device = GET_GRAPHIC_DEVICE();
	auto gb_vs = graphic_device->LoadVertexShader("resources/shader/graphics_buffer.vsc");
	auto gb_ps = graphic_device->LoadPixelShader("resources/shader/graphics_buffer.psc");
	auto d_vs = graphic_device->LoadVertexShader("resources/shader/deferred.vsc");
	auto d_ps = graphic_device->LoadPixelShader("resources/shader/deferred.psc");

	auto basic_vs = graphic_device->LoadVertexShader("resources/shader/basic.vsc");
	auto basic_ps = graphic_device->LoadPixelShader("resources/shader/basic.psc");

	//画面クリア
	graphic_device->Clear(float4(1.0f, 1.0f, 1.0f, 1.0f), 1.0f);

	//デバッグワイヤーフレーム
//	graphic_device->GetDevice()->SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME);
	
	float4 color(1.0f, 1.0f, 1.0f, 1.0f);
	//シェーダ設定
	graphic_device->SetVertexShader(basic_vs);
	graphic_device->SetPixelShader(basic_ps);

	basic_vs->SetValue("_view_matrix", (f32*)&observer_2d_->GetViewMatrix(), 16);
	basic_vs->SetValue("_projection_matrix", (f32*)&observer_2d_->GetProjectionMatrix(), 16);
	basic_vs->SetValue("_world_matrix", (f32*)&background_->GetMatrix(), 16);
	basic_vs->SetValue("_color", (f32*)&color,4);

	basic_ps->SetTexture("_texture_sampler", background_->GetTexture(0)->GetTexture());
	//背景
	background_->Draw();

	//パーティクル
	for (u32 i = 0; i < PARTICUL_MAX; ++i)
	{
		basic_vs->SetValue("_world_matrix", (f32*)&particul_[i].particul_->GetMatrix(), 16);
		basic_vs->SetValue("_color", (f32*)&color, 4);

		basic_ps->SetTexture("_texture_sampler", particul_[i].particul_->GetTexture(0)->GetTexture());
		//ロゴ
		particul_[i].particul_->Draw();
	}
	basic_vs->SetValue("_world_matrix", (f32*)&logo_->GetMatrix(), 16);
	basic_vs->SetValue("_color", (f32*)&color, 4);

	basic_ps->SetTexture("_texture_sampler", logo_->GetTexture(0)->GetTexture());
	//ロゴ
	logo_->Draw();


	draw_cnt_++;
	if (draw_cnt_ > 100)
	{
		use_flag_ = true;
	}
	if (draw_cnt_ > 200)
	{
		draw_cnt_ = 0;
		use_flag_ = false;
	}
	if (use_flag_)
	{
		//ボタン背景
		basic_vs->SetValue("_world_matrix", (f32*)&button_interface_->GetMatrix(), 16);
		basic_vs->SetValue("_color", (f32*)&color, 4);

		basic_ps->SetTexture("_texture_sampler", button_interface_->GetTexture(0)->GetTexture());
		//ボタン背景
		button_interface_->Draw();

		basic_vs->SetValue("_world_matrix", (f32*)&button_->GetMatrix(), 16);
		basic_vs->SetValue("_color", (f32*)&color, 4);

		basic_ps->SetTexture("_texture_sampler", button_->GetTexture(0)->GetTexture());
		//ボタン
		button_->Draw();
	}

}
Пример #25
0
    //-----------------------------------------------------------------------------
    //  Render
    //  Performs rendering
    //-----------------------------------------------------------------------------
    void CRenderer::Render( CTerrain* pTerrain )
    {
        //////////////////////////////////////////
        // Just render the text
        if( !gnRenderOn )
        {   // Don't render if we shouldn't
            m_nPrevNumCommands  = 0;
            m_nPrevNumBoxes     = 0;

            m_pDevice->Clear();
            UI::Draw( m_pDevice );
            m_pDevice->Present();
            return;
        }

        //////////////////////////////////////////
        // Sort the list
        Sort();

        //////////////////////////////////////////
        // Restore solid fill mode
        if( gnRenderWireframe )
            m_pDevice->SetFillMode( GFX_FILL_WIREFRAME );
        else
            m_pDevice->SetFillMode( GFX_FILL_SOLID );

        //////////////////////////////////////////
        // Update lighting
        m_pDevice->UpdateBuffer( m_pLightCB, m_pPrevLights );
        m_pDevice->SetPSConstantBuffer( 0, m_pLightCB );

        //////////////////////////////////////////
        // Clear
        m_pDevice->Clear();
        m_pDevice->SetDepthTest( true, true );


        //////////////////////////////////////////
        // Render
        ASSERT( m_pCurrentView );

        SetViewProj( m_pCurrentView->GetViewMatrix(), m_pCurrentView->GetProjMatrix() );


//        if( m_pTestRT )
//        {
//            m_pDevice->ClearRenderTarget( m_pTestRT );
//            m_pDevice->SetRenderTarget( m_pTestRT );
//        }

//        //////////////////////////////////////////
//        //  Z pre-pass
//        {
//            m_pDevice->SetColorWrite( true );
//            m_pDevice->SetDepthTest( true, true );
//
//            //////////////////////////////////////////
//            // Render the terrain
//            SetVertexShader( eVS3DPosNorTexNoTransform );
//            SetPixelShader( ePS3DStd );
//            pTerrain->Render();
//            SetVertexShader( eVS3DPosNorTexStd );
//
//            //////////////////////////////////////////
//            // Perform basic object rendering
//            for( sint i = 0; i < m_nPrevNumCommands; ++i )
//            {
//                ProcessCommand( m_pPrevCommands[i], m_pPrevTransforms[i] );
//            }
//        }

        //////////////////////////////////////////
        //  Actual rendering
        {
            m_pDevice->SetColorWrite( true );
//            m_pDevice->SetDepthTest( true, false );
            // TEMP!
            m_pDevice->SetDepthTest( true, true );
            
            //////////////////////////////////////////
            // Render the terrain
            SetVertexShader( eVS3DPosNorTexNoTransform );
            SetPixelShader( ePS3DStd );
            pTerrain->Render();
            SetVertexShader( eVS3DPosNorTexStd );

            /*
            //////////////////////////////////////////
            // Perform basic object rendering
            for( sint i = 0; i < m_nPrevNumCommands; ++i )
            {
                ProcessCommand( m_pPrevCommands[i], m_pPrevTransforms[i] );
            }
            */
        }

//        //////////////////////////////////////////
//        // Draw the debug volumes
//        if( gnShowBoundingVolumes )
//        {
//            m_pDevice->SetFillMode( GFX_FILL_WIREFRAME );
//            SetVertexShader( eVS3DPosColStd );
//            SetPixelShader( ePS3DColor );
//
//            // Draw the debug boxes
//            for( sint i = 0; i < m_nPrevNumBoxes; ++i )
//            {
//                RVector3 vMin = m_pPrevDebugBoxes[i].box.min;
//                RVector3 vMax = m_pPrevDebugBoxes[i].box.max;
//                RVector3 vColor = m_pPrevDebugBoxes[i].color;
//
//                RMatrix4 mWorld = RMatrix4Identity();
//                SetWorldMatrix( mWorld );
//
//                VPosColor vertices[] =
//                {
//                    { RVector3(  vMin.x,  vMax.y,  vMin.z ), Homogonize( vColor ) },
//                    { RVector3(  vMax.x,  vMax.y,  vMin.z ), Homogonize( vColor ) },
//                    { RVector3(  vMax.x,  vMax.y,  vMax.z ), Homogonize( vColor ) },
//                    { RVector3(  vMin.x,  vMax.y,  vMax.z ), Homogonize( vColor ) },
//
//                    { RVector3(  vMin.x,  vMin.y,  vMin.z ), Homogonize( vColor ) },
//                    { RVector3(  vMax.x,  vMin.y,  vMin.z ), Homogonize( vColor ) },
//                    { RVector3(  vMax.x,  vMin.y,  vMax.z ), Homogonize( vColor ) },
//                    { RVector3(  vMin.x,  vMin.y,  vMax.z ), Homogonize( vColor ) },
//
//                    { RVector3(  vMin.x,  vMin.y,  vMax.z ), Homogonize( vColor ) },
//                    { RVector3(  vMin.x,  vMin.y,  vMin.z ), Homogonize( vColor ) },
//                    { RVector3(  vMin.x,  vMax.y,  vMin.z ), Homogonize( vColor ) },
//                    { RVector3(  vMin.x,  vMax.y,  vMax.z ), Homogonize( vColor ) },
//
//                    { RVector3(  vMax.x,  vMin.y,  vMax.z ), Homogonize( vColor ) },
//                    { RVector3(  vMax.x,  vMin.y,  vMin.z ), Homogonize( vColor ) },
//                    { RVector3(  vMax.x,  vMax.y,  vMin.z ), Homogonize( vColor ) },
//                    { RVector3(  vMax.x,  vMax.y,  vMax.z ), Homogonize( vColor ) },
//
//                    { RVector3(  vMin.x,  vMin.y,  vMin.z ), Homogonize( vColor ) },
//                    { RVector3(  vMax.x,  vMin.y,  vMin.z ), Homogonize( vColor ) },
//                    { RVector3(  vMax.x,  vMax.y,  vMin.z ), Homogonize( vColor ) },
//                    { RVector3(  vMin.x,  vMax.y,  vMin.z ), Homogonize( vColor ) },
//
//                    { RVector3(  vMin.x,  vMin.y,  vMax.z ), Homogonize( vColor ) },
//                    { RVector3(  vMax.x,  vMin.y,  vMax.z ), Homogonize( vColor ) },
//                    { RVector3(  vMax.x,  vMax.y,  vMax.z ), Homogonize( vColor ) },
//                    { RVector3(  vMin.x,  vMax.y,  vMax.z ), Homogonize( vColor ) },
//                };
//
//                m_pDevice->UpdateBuffer( m_ppMeshes[m_nDebugBox]->m_pVertexBuffer, vertices );
//
//                m_ppMeshes[m_nDebugBox]->DrawMesh();
//            }
//
//            // Draw the rays
//            m_pDevice->SetPrimitiveType( GFX_PRIMITIVE_LINELIST );
//            for( sint i = 0; i < m_nPrevNumRays; ++i )
//            {
//                RVector3 vStart = m_pPrevDebugRays[i].start;
//                RVector3 vEnd = m_pPrevDebugRays[i].end;
//
//                RVector4 vWhite( 1.0f, 1.0f, 1.0f, 1.0f );
//                RVector4 vBlack( 0.0f, 0.0f, 0.0f, 0.0f );
//                VPosColor vertices[] =
//                {
//                    { vStart, vBlack },
//                    { vEnd, vWhite },
//                };
//
//                m_pDevice->UpdateBuffer( m_pLineBuffer, vertices );
//
//                m_pDevice->SetVertexBuffer( 0, m_pLineBuffer, VPosColor::VertexStride );
//                m_pDevice->DrawPrimitive( 2 );
//            }
//
//            m_pDevice->SetFillMode( GFX_FILL_SOLID );
//            m_pDevice->SetPrimitiveType( GFX_PRIMITIVE_TRIANGLELIST );
//            SetVertexShader( eVS3DPosNorTexStd );
//            SetPixelShader( ePS3DStd );
//        }

//        m_pDevice->SetDefaultRenderDepthTarget();
//        m_pDevice->SetDepthTest( false, false );
//
//        SetVertexShader( eVS2DPos );
//        SetPixelShader( ePS2DFS );
//        SetSamplerState( eSamplerNearest );
//
//        if( m_pTestRT )
//        m_pDevice->SetPSRenderTarget( 0, m_pTestRT );
//
//        m_pDevice->SetVertexBuffer( 0, m_pFSRectVB, VPos::VertexStride );
//        m_pDevice->SetIndexBuffer( m_pFSRectIB, 2 );
//
//        m_pDevice->DrawIndexedPrimitive( 6 );
        
        //////////////////////////////////////////
        // Draw the UI
//        UI::Draw( m_pDevice );

        // Present
        m_pDevice->Present();
    }
Пример #26
0
//==============================================================================================================================
bool DeferredShader::Render11
(	int indexCount
,	Camera* camera
,	XMMATRIX world
,	XMFLOAT2 specularPowerRange
,	float specularIntensity
,	float specularPower
,	ID3D11ShaderResourceView* texture
)
{
	cbPackBuffer cPB;
	cPB.g_SpecularPowerRange = specularPowerRange;
	cPB.g_SpecularIntensity = specularIntensity;
	cPB.g_SpecularPower = specularPower;
	// Map the pack buffer
	{
		D3D11_MAPPED_SUBRESOURCE mapped_res2;
		m_pD3DSystem->GetDeviceContext()->Map(m_pPackCB, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped_res2);
		{
			assert(mapped_res2.pData);
			*(cbPackBuffer*)mapped_res2.pData = cPB;
		}
		m_pD3DSystem->GetDeviceContext()->Unmap(m_pPackCB, 0);
	}
	
	cbMatrixBuffer cMB;
	cMB.g_matWorld = ZShadeSandboxMath::ZMath::GMathMF(XMMatrixTranspose(world));
	cMB.g_matView = camera->View4x4();
	cMB.g_matProj = camera->Proj4x4();
	// Map the matrix buffer
	{
		D3D11_MAPPED_SUBRESOURCE mapped_res2;
		m_pD3DSystem->GetDeviceContext()->Map(m_pMatrixCB, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped_res2);
		{
			assert(mapped_res2.pData);
			*(cbMatrixBuffer*)mapped_res2.pData = cMB;
		}
		m_pD3DSystem->GetDeviceContext()->Unmap(m_pMatrixCB, 0);
	}
	
	ID3D11Buffer* vs_cbs[1] = { m_pMatrixCB };
	m_pD3DSystem->GetDeviceContext()->VSSetConstantBuffers(1, 1, vs_cbs);
	
	ID3D11Buffer* ps_cbs[1] = { m_pPackCB };
	m_pD3DSystem->GetDeviceContext()->PSSetConstantBuffers(0, 1, ps_cbs);
	
	// Assign Texture
	ID3D11ShaderResourceView* ps_srvs[1] = { texture };
	ID3D11SamplerState* ps_samp[1] = { m_pD3DSystem->Linear() };
	
	if (!m_Wireframe)
	{
		m_pD3DSystem->GetDeviceContext()->PSSetShaderResources(0, 1, ps_srvs);
		m_pD3DSystem->GetDeviceContext()->PSSetSamplers(0, 1, ps_samp);

		SwitchTo("DeferredShaderPS", ZShadeSandboxShader::EShaderTypes::ST_PIXEL);
	}
	else
	{
		SwitchTo("DeferredShaderWireframePS", ZShadeSandboxShader::EShaderTypes::ST_PIXEL);
	}

	SetInputLayout("DeferredShader");
	
	SetVertexShader();
	SetPixelShader();
	
	//Perform Drawing
	RenderIndex11(indexCount);

	// Unbind
	if (!m_Wireframe)
	{
		m_pD3DSystem->TurnOnCulling();

		ps_samp[0] = NULL;
		m_pD3DSystem->GetDeviceContext()->PSSetSamplers(0, 1, ps_samp);
		ps_srvs[0] = NULL;
		m_pD3DSystem->GetDeviceContext()->PSSetShaderResources(0, 1, ps_srvs);
	}

	return true;
}
Пример #27
0
//==============================================================================================================================
bool OBJMeshShader::Render
(	int startIndex
,	int indexCount
,	ZShadeSandboxMesh::MeshRenderParameters mrp
,	ZShadeSandboxLighting::ShaderMaterial* material
)
{
	ID3D11ShaderResourceView* diffuseArrayTexture = 0;
	ID3D11ShaderResourceView* diffuseTexture = 0;
	ID3D11ShaderResourceView* ambientTexture = 0;
	ID3D11ShaderResourceView* specularTexture = 0;
	ID3D11ShaderResourceView* emissiveTexture = 0;
	ID3D11ShaderResourceView* normalMapTexture = 0;
	ID3D11ShaderResourceView* blendMapTexture = 0;
	ID3D11ShaderResourceView* detailMapTexture = 0;
	ID3D11ShaderResourceView* alphaMapTexture = 0;
	ID3D11ShaderResourceView* shadowMapTexture = 0;
	ID3D11ShaderResourceView* ssaoTexture = 0;
	ID3D11ShaderResourceView* displacementMapTexture = 0;

	material->GetTextures(
		diffuseArrayTexture,
		diffuseTexture,
		ambientTexture,
		specularTexture,
		emissiveTexture,
		normalMapTexture,
		blendMapTexture,
		detailMapTexture,
		alphaMapTexture,
		shadowMapTexture,
		ssaoTexture,
		displacementMapTexture
	);

	material->BuildMaterialConstantBuffer(m_pShadingCB, mrp.camera->Position(), mrp.clipplane);
	
	mrp.camera->BuildCameraConstantBuffer(m_pD3DSystem, m_pMatrixCB, mrp.world, mrp.reflection);
	
	ZShadeSandboxLighting::LightManager::Instance()->BuildFinalLightBuffers(m_pLightCB, m_pSunCB);

	// Set the shading constant buffer and matrix constant buffer into the Vertex Shader
	ID3D11Buffer* vs_cbs[2] = { m_pShadingCB, m_pMatrixCB };
	m_pD3DSystem->GetDeviceContext()->VSSetConstantBuffers(2, 2, vs_cbs);
	
	// Set the shading constant buffer into the Pixel Shader
	ID3D11Buffer* ps_cbs[3] = { m_pLightCB, m_pSunCB, m_pShadingCB };
	m_pD3DSystem->GetDeviceContext()->PSSetConstantBuffers(0, 3, ps_cbs);
	
	ID3D11ShaderResourceView* ps_srvs[11] = { diffuseArrayTexture, diffuseTexture, ambientTexture, specularTexture, emissiveTexture, normalMapTexture, blendMapTexture, detailMapTexture, alphaMapTexture, shadowMapTexture, ssaoTexture };
	ID3D11SamplerState* ps_samp[1] = { m_pD3DSystem->Linear() };
	
	if (!m_Wireframe)
	{
		m_pD3DSystem->TurnOffCulling();

		// Set the texture into the Pixel Shader
		m_pD3DSystem->GetDeviceContext()->PSSetShaderResources(0, 11, ps_srvs);
		m_pD3DSystem->GetDeviceContext()->PSSetSamplers(0, 1, ps_samp);

		SwitchTo("OBJMeshPS", ZShadeSandboxShader::EShaderTypes::ST_PIXEL);
	}
	else
	{
		SwitchTo("OBJMeshWireframePS", ZShadeSandboxShader::EShaderTypes::ST_PIXEL);
	}

	// Tell the shader what input layout to use
	SetInputLayout("OBJMeshShader");
	
	// Assign the shaders to render the mesh
	SetVertexShader();
	SetPixelShader();
	
	//Perform Drawing
	RenderIndex11(startIndex, indexCount);

	// Unbind
	if (!m_Wireframe)
	{
		m_pD3DSystem->TurnOnCulling();

		ps_samp[0] = NULL;
		m_pD3DSystem->GetDeviceContext()->PSSetSamplers(0, 1, ps_samp);

		for (int i = 0; i < 11; i++) ps_srvs[i] = NULL;
		m_pD3DSystem->GetDeviceContext()->PSSetShaderResources(0, 11, ps_srvs);
	}
	
	return true;
}
Пример #28
0
ShaderProgram::~ShaderProgram()
{
    DeleteProgram();
    SetFragmentShader(0);
    SetVertexShader(0);
}