Jump to content
  • Advertisement
Sign in to follow this  
ankhd

Need Some Help Convertting HLSL shader 2 code to shader 4

This topic is 3568 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all. I'm trying to convert my directx9 terrain class to a Directx10 Terrain class. so far I cant see any thing on the screen .. the camera slows down when I draw it, so some thing is going on but nothing gets rendered Pix says there is mesh data but no image may be depth/stencil thing cant find any thing on it. Could some one look through this code Please, thanks.... I keep getting this message.... the debug out puts this. D3D10: ERROR: : Rasterization Unit is enabled (PixelShader is not NULL or Depth/Stencil test is enabled) but position is not provided by the last shader before the Rasterization Unit. [ EXECUTION ERROR #362: DEVICE_DRAW_POSITION_NOT_PRESENT ] using Microsoft DirectX SDK (November 2008) vc++8 express HLSL 4 geforce 8400 512mb vista , Q6600 2.4mhz here is my d3dx10 set up and the shader 2 and my attemp at converting it to shader 4 init d3d stuff


//--------------------------------------------------------------------------------------
// Create Direct3D device and swap chain
//--------------------------------------------------------------------------------------
HRESULT c3DDevice::InitDevice(AppWin *window)
{
		if(m_ValidDevice)
			return S_OK;//error we are allready set up

		HRESULT hr = S_OK;

		RECT rc;
		GetClientRect( window->Hwnd, &rc );
		UINT width = rc.right - rc.left;
		UINT height = rc.bottom - rc.top;

		UINT createDeviceFlags = 0;
#ifdef _DEBUG
	createDeviceFlags |= D3D10_CREATE_DEVICE_DEBUG;
#endif

		D3D10_DRIVER_TYPE driverTypes[] =
		{
			D3D10_DRIVER_TYPE_HARDWARE,
			D3D10_DRIVER_TYPE_REFERENCE,
		};
		UINT numDriverTypes = sizeof( driverTypes ) / sizeof( driverTypes[0] );

		DXGI_SWAP_CHAIN_DESC sd;
		ZeroMemory( &sd, sizeof( sd ) );
		sd.BufferCount = 1;
		sd.BufferDesc.Width = width;
		sd.BufferDesc.Height = height;
		sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
		sd.BufferDesc.RefreshRate.Numerator = 60;
		sd.BufferDesc.RefreshRate.Denominator = 1;
		sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
		sd.OutputWindow = window->Hwnd;
		sd.SampleDesc.Count = 1;
		sd.SampleDesc.Quality = 0;
		sd.Windowed = m_Windowed;

		for( UINT driverTypeIndex = 0; driverTypeIndex < numDriverTypes; driverTypeIndex++ )
		{
			m_driverType = driverTypes[driverTypeIndex];
			hr = D3D10CreateDeviceAndSwapChain( NULL, m_driverType, NULL, createDeviceFlags,
												D3D10_SDK_VERSION, &sd, &m_pSwapChain, &m_pd3dDevice );
			if( SUCCEEDED( hr ) )
				break;
		}
		if( FAILED( hr ) )
			return hr;

		// Create a render target view
		ID3D10Texture2D* pBackBuffer;
		hr = m_pSwapChain->GetBuffer( 0, __uuidof( ID3D10Texture2D ), ( LPVOID* )&pBackBuffer );
		if( FAILED( hr ) )
			return hr;

		hr = m_pd3dDevice->CreateRenderTargetView( pBackBuffer, NULL, &m_pRenderTargetView );
		pBackBuffer->Release();
		if( FAILED( hr ) )
			return hr;

		m_pd3dDevice->OMSetRenderTargets( 1, &m_pRenderTargetView, NULL );


		 // Create depth stencil texture
    		D3D10_TEXTURE2D_DESC descDepth;
    		descDepth.Width = width;
    		descDepth.Height = height;
    		descDepth.MipLevels = 1;
    		descDepth.ArraySize = 1;
    		descDepth.Format = DXGI_FORMAT_D32_FLOAT;
    		descDepth.SampleDesc.Count = 1;
    		descDepth.SampleDesc.Quality = 0;
    		descDepth.Usage = D3D10_USAGE_DEFAULT;
    		descDepth.BindFlags = D3D10_BIND_DEPTH_STENCIL;
    		descDepth.CPUAccessFlags = 0;
    		descDepth.MiscFlags = 0;
    		hr = m_pd3dDevice->CreateTexture2D( &descDepth, NULL, &m_pDepthStencil );
    		if( FAILED( hr ) )
        		return hr;

    		// Create the depth stencil view
    		D3D10_DEPTH_STENCIL_VIEW_DESC descDSV;
    		descDSV.Format = descDepth.Format;
    		descDSV.ViewDimension = D3D10_DSV_DIMENSION_TEXTURE2D;
    		descDSV.Texture2D.MipSlice = 0;
    		hr = m_pd3dDevice->CreateDepthStencilView( m_pDepthStencil, &descDSV, &m_pDepthStencilView );
    		if( FAILED( hr ) )
        		return hr;

    		m_pd3dDevice->OMSetRenderTargets( 1, &m_pRenderTargetView, m_pDepthStencilView );



		// Setup the viewport
		D3D10_VIEWPORT vp;
		vp.Width = width;
		vp.Height = height;
		vp.MinDepth = 0.0f;
		vp.MaxDepth = 1.0f;
		vp.TopLeftX = 0;
		vp.TopLeftY = 0;
		m_pd3dDevice->RSSetViewports( 1, &vp );

		m_ValidDevice	= true;//we are good to go

		return S_OK;
}//end InitDevice
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Vertex type using for the terrain

struct MultiTextureTerrainVertex//this is the sames as this one old code NMapVertex
{
	D3DXVECTOR3 pos;
	D3DXVECTOR3 normal;
	D3DXVECTOR2 tex0;
	
	
	static const D3D10_INPUT_ELEMENT_DESC TerrainLayout[3];// =
  
	static UINT GetNumElements(void){return 3;}}
};



//cpp file
const D3D10_INPUT_ELEMENT_DESC MultiTextureTerrainVertex::TerrainLayout[3] =
 {
	{ "POSITION",    0, DXGI_FORMAT_R32G32B32_FLOAT,        0, 0,  D3D10_INPUT_PER_VERTEX_DATA, 0 },
	{ "NORMAL",       0, DXGI_FORMAT_R32G32B32_FLOAT,       0, 12, D3D10_INPUT_PER_VERTEX_DATA, 0 },
	{ "TEXCOORD",    0,  DXGI_FORMAT_R32G32_FLOAT,		0, 24, D3D10_INPUT_PER_VERTEX_DATA, 0 },

		
  };



Seteup for the fx files loads and creates images all ok.
//---------------------------------------------------------------------------------------
//this will set all the handles for the fx file
//----------------------------------------------------------------------------------------
void Terrain::buildEffect(void)
{

	 // Load our FX and technique, and create layout variable
    //WCHAR str[MAX_PATH];
	std::string str = "FXFiles\\Terrain.fx";
	DWORD dwShaderFlags = D3D10_SHADER_ENABLE_BACKWARDS_COMPATIBILITY;//D3D10_SHADER_ENABLE_STRICTNESS;
#if defined( DEBUG ) || defined( _DEBUG )
    // Set the D3D10_SHADER_DEBUG flag to embed debug information in the shaders.
    // Setting this flag improves the shader debugging experience, but still allows 
    // the shaders to be optimized and to run exactly the way they will run in 
    // the release configuration of this program.
    dwShaderFlags |= D3D10_SHADER_DEBUG;
#endif
	ID3D10Blob *pErrors = NULL;

    
	HRESULT hr = D3DX10CreateEffectFromFile( str.c_str(), NULL, NULL, "fx_4_0", dwShaderFlags, 0, c3DDevice::m_pd3dDevice, NULL, NULL, &m_pEffect, &pErrors, &hr );
	if(FAILED(hr))
	{
		if(pErrors)
		{
			MessageBox( NULL,
                    (TCHAR *)pErrors->GetBufferPointer(), "Error", MB_OK );
			pErrors->Release();

			//return false;
			
		}

        MessageBox( NULL,
                    "The Terrain() FX file cannot be located .  Please run this executable from the directory that contains the FX file.", "Error", MB_OK );
     

		return;
	}

	// Our vars
    m_hTechnique = m_pEffect->GetTechniqueByName("TerrainTech");
	m_hViewProjVar = m_pEffect->GetVariableByName("gViewProj")->AsMatrix();
	m_hDirToSunWVar	= m_pEffect->GetVariableByName("gDirToSunW")->AsVector();
	m_hEyePosWVar	= m_pEffect->GetVariableByName("gEyePosW")->AsVector();
	


	m_pTerrainTextureVar[0] = m_pEffect->GetVariableByName("gTex0")->AsShaderResource();
	m_pTerrainTextureVar[1] = m_pEffect->GetVariableByName("gTex1")->AsShaderResource();
	m_pTerrainTextureVar[2] = m_pEffect->GetVariableByName("gTex2")->AsShaderResource();

	m_pBlendMapVar = m_pEffect->GetVariableByName("gBlendMap")->AsShaderResource();

    




    D3D10_PASS_DESC PassDesc;
   hr = m_hTechnique->GetPassByIndex( 0 )->GetDesc( &PassDesc );
   c3DDevice::m_pd3dDevice->CreateInputLayout( &MultiTextureTerrainVertex::TerrainLayout[0], 
		MultiTextureTerrainVertex::GetNumElements(), PassDesc.pIAInputSignature, PassDesc.IAInputSignatureSize, &m_pInputLayout );

  
//moved to render
   //c3DDevice::m_pd3dDevice->IASetInputLayout(m_pInputLayout);
    //c3DDevice::m_pd3dDevice->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST);


	
}//end buildEffect
//////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////






This is the mesh creation this is the same as my directx 9 version but converted to d3dx10 may be some thing ive done in here
//---------------------------------------------------------------------------------------------------------
//this will construct the terrain
//------------------------------------------------------------------------------------------------------------
void Terrain::buildGeometry(void)
{
	//----------------------------------------------------------------------
	// Create one large mesh for the grid in system memory.

	DWORD numTris  = (mVertRows-1)*(mVertCols-1)*2;
	DWORD numVerts = mVertRows*mVertCols;

	ID3DX10Mesh* mesh = 0;
	//D3DVERTEXELEMENT9 elems[MAX_FVF_DECL_SIZE];
	//UINT numElems = 0;
	//if(FAILED(VertexPNT::Decl->GetDeclaration(elems, &numElems)))
	//	MessageBox(NULL, "Terrain Failed To GetDeclaration", "Terrain Class buildGeometry()", MB_OK);


	// Use Scratch pool since we are using this mesh purely for some CPU work,
	// which will be used to create the sub-grids that the graphics card
	// will actually draw.
	HRESULT hr;

	//hr = D3DX10CreateMesh(numTris, numVerts, 
	//	D3DPOOL_SCRATCH|D3DXMESH_32BIT, elems, Device, &mesh);
	//if(FAILED(hr))
	//	MessageBox(NULL, "Terrain Failed To D3DXCreateMesh", "Terrain Class buildGeometry()", MB_OK);


	hr = D3DX10CreateMesh(c3DDevice::m_pd3dDevice,
							MultiTextureTerrainVertex::TerrainLayout,//CONST D3D10_INPUT_ELEMENT_DESC *pDeclaration,
							MultiTextureTerrainVertex::GetNumElements(),//UINT DeclCount,
							MultiTextureTerrainVertex::TerrainLayout[0].SemanticName,//LPCSTR pPositionSemantic,
						  numVerts,//UINT VertexCount,
						  numTris,//UINT FaceCount,
						  D3DX10_MESH_32_BIT,//  UINT Options,
						  &mesh);//ID3DX10Mesh **ppMesh
	if(FAILED(hr))
		MessageBox(NULL, "Terrain Failed To D3DXCreateMesh", "Terrain Class buildGeometry()", MB_OK);




	//-------------------------------------------------------------------------------------------------
	// Write the grid vertices and triangles to the mesh.

	
	//mesh->LockVertexBuffer(0, (void**)&v);
	SIZE_T loadingSize						= 0;
	MultiTextureTerrainVertex *pSourceVertices				= NULL;
	ID3DX10MeshBuffer *pSourceVertexBuffer = NULL;
	hr = mesh->GetVertexBuffer(0,&pSourceVertexBuffer);
	if(FAILED(hr))//D3D_OK
	{
		//return;
	}

    hr = pSourceVertexBuffer->Map((void**)&pSourceVertices,&loadingSize);
	if(FAILED(hr))//D3D_OK
	{
		//return;
	}


	
	std::vector<D3DXVECTOR3> verts;
	std::vector<DWORD> indices;
	GenTriGrid(mVertRows, mVertCols, mDX, mDZ, D3DXVECTOR3(0.0f, 0.0f, 0.0f), verts, indices);

	D3DXVECTOR3 norm;
	float w = mWidth;
	float d = mDepth;
	UINT b =0;
	UINT c = 0;
	UINT vertcount = numVerts;//mesh->GetVertexCount();
	for(UINT i = 0; i < vertcount; ++i)
	{
		// We store the grid vertices in a linear array, but we can
		// convert the linear array index to an (r, c) matrix index.
		int r = i / mVertCols;
		int c = i % mVertCols;

		pSourceVertices.pos		= verts;
		pSourceVertices.pos.y	= m_Heightmap->mHeightMap(r, c);

	
		pSourceVertices.normal	= D3DXVECTOR3(0,1,0);
		//pSourceVertices.tangent;
		//pSourceVertices.binorm;

		pSourceVertices.tex0.x = (pSourceVertices.pos.x + (0.5f*w)) / w;
		pSourceVertices.tex0.y = (pSourceVertices.pos.z - (0.5f*d)) / -d;
		//SetVetextInfo(pSourceVertices, i, D3DXVECTOR2((pSourceVertices.pos.x + (0.5f*w)) / w, (pSourceVertices.pos.z - (0.5f*d)) / -d));
	}



	// Write triangle data so we can compute normals.

	
	
	//===============================================================
	// Build Index and Attribute Buffer.
	ID3DX10MeshBuffer *pSourceIndexBuffer = NULL;
	DWORD* pSourceindices  = 0;
	//DWORD* attBuff = 0;

	
	hr = mesh->GetIndexBuffer(&pSourceIndexBuffer);
	if(FAILED(hr))
	{
		MessageBox(NULL, "Terrain Failed To Get Index buffer", "GameUtil Function", MB_OK);
		//return;
	}
	
	hr = pSourceIndexBuffer->Map((void**)&pSourceindices,&loadingSize);
	if(FAILED(hr))
	{
		MessageBox(NULL, "Terrain Failed To Map Index buffer", "GameUtil Function", MB_OK);
		//return;
	}


	//DWORD* indexBuffPtr = 0;
	//(mesh->LockIndexBuffer(0, (void**)&indexBuffPtr));
	for(UINT i = 0; i < mesh->GetVertexCount(); ++i)
	{
		pSourceindices[i*3+0] = indices[i*3+0];
		pSourceindices[i*3+1] = indices[i*3+1];
		pSourceindices[i*3+2] = indices[i*3+2];
	}
	//(mesh->UnlockIndexBuffer());
	pSourceIndexBuffer->Unmap();

	// Compute Vertex Normals.
//	hr = D3DX10ComputeNormals(mesh, 0);
//	if(FAILED(hr))
//		MessageBox(NULL, "Terrain Failed To D3DXComputeNormals", "Terrain Class buildGeometry()", MB_OK);



	
	//---------------------------------------------------------------------------------------------
	// Now break the grid up into subgrid meshes.

	// Find out the number of subgrids we'll have.  For example, if
	// m = 513, n = 257, SUBGRID_VERT_ROWS = SUBGRID_VERT_COLS = 33,
	// then subGridRows = 512/32 = 16 and sibGridCols = 256/32 = 8.
	int subGridRows = (mVertRows-1) / (SubGrid::NUM_ROWS-1);
	int subGridCols = (mVertCols-1) / (SubGrid::NUM_COLS-1);

	//TCHAR buff[MAX_PATH];
	//sprintf_s(buff, MAX_PATH, "Main Map SubGrid Rows = %d, Cols = %d",subGridRows, subGridCols);
	//MessageBox(NULL, buff, "Terrain Class buildGeometry()", MB_OK);

	//add a message to that dialogbox on the main window
//	ErrorReport.AddErrorMessage(buff, false);

	//add the number verts and tri for the whole map
//	sprintf_s(buff, MAX_PATH, "Main Map Total Number Triangles = %d, Number Verts = %d",numTris, numVerts);

//	ErrorReport.AddErrorMessage(buff, false);

	for(int r = 0; r < subGridRows; ++r)
	{
		for(int c = 0; c < subGridCols; ++c)
		{
			// Rectangle that indicates (via matrix indices ij) the
			// portion of grid vertices to use for this subgrid.
			RECT R = 
			{
					c * (SubGrid::NUM_COLS-1),
					r * (SubGrid::NUM_ROWS-1),
				(c+1) * (SubGrid::NUM_COLS-1),
				(r+1) * (SubGrid::NUM_ROWS-1)
			};

			buildSubGridMesh( R, pSourceVertices); 
		}
	}

	//(mesh->UnlockVertexBuffer());

	pSourceVertexBuffer->Unmap();

	//create big temp mesh
	hr = mesh->CloneMesh(D3DX10_MESH_32_BIT,
							MultiTextureTerrainVertex::TerrainLayout[0].SemanticName,
							MultiTextureTerrainVertex::TerrainLayout,//CONST D3D10_INPUT_ELEMENT_DESC *pDeclaration,
							MultiTextureTerrainVertex::GetNumElements(),
							&TestMesh);//

	if(TestMesh)
		TestMesh->CommitToDevice();

	SAFE_RELEASE(pSourceIndexBuffer);
	SAFE_RELEASE(pSourceVertexBuffer);
	SAFE_RELEASE(mesh); // Done with global mesh.



	
		

}//end buildGeometry
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////




//this creates a lists of vertex and index values
void GenTriGrid(int numVertRows, int numVertCols,
				float dx, float dz, 
				const D3DXVECTOR3& center, 
				std::vector<D3DXVECTOR3>& verts,
				std::vector<DWORD>& indices)
{
	int numVertices = numVertRows*numVertCols;
	int numCellRows = numVertRows-1;
	int numCellCols = numVertCols-1;

	int numTris = numCellRows*numCellCols*2;

	float width = (float)numCellCols * dx;
	float depth = (float)numCellRows * dz;

	//===========================================
	// Build vertices.

	// We first build the grid geometry centered about the origin and on
	// the xz-plane, row-by-row and in a top-down fashion.  We then translate
	// the grid vertices so that they are centered about the specified 
	// parameter 'center'.

	verts.resize( numVertices );

	// Offsets to translate grid from quadrant 4 to center of 
	// coordinate system.
	float xOffset = -width * 0.5f; 
	float zOffset =  depth * 0.5f;

	int k = 0;
	for(float i = 0; i < numVertRows; ++i)
	{
		for(float j = 0; j < numVertCols; ++j)
		{
			// Negate the depth coordinate to put in quadrant four.  
			// Then offset to center about coordinate system.
			verts[k].x =  j * dx + xOffset;
			verts[k].z = -i * dz + zOffset;
			verts[k].y =  0.0f;

			// Translate so that the center of the grid is at the
			// specified 'center' parameter.
			D3DXMATRIX T;
			D3DXMatrixTranslation(&T, center.x, center.y, center.z);
			D3DXVec3TransformCoord(&verts[k], &verts[k], &T);
			
			++k; // Next vertex
		}
	}

	//===========================================
	// Build indices.

	indices.resize(numTris * 3);
	 
	// Generate indices for each quad.
	k = 0;
	for(DWORD i = 0; i < (DWORD)numCellRows; ++i)
	{
		for(DWORD j = 0; j < (DWORD)numCellCols; ++j)
		{
			indices[k]     =   i   * numVertCols + j;
			indices[k + 1] =   i   * numVertCols + j + 1;
			indices[k + 2] = (i+1) * numVertCols + j;
					
			indices[k + 3] = (i+1) * numVertCols + j;
			indices[k + 4] =   i   * numVertCols + j + 1;
			indices[k + 5] = (i+1) * numVertCols + j + 1;

			// next quad
			k += 6;
		}//end for j
	}//end for i

}//end GenTriGrid
/////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////



Render code the quadtree all works not there

void Terrain::draw(D3DXMATRIX *ViewProj)
{
	if(m_pEffect == NULL)
		return;//error

	// Frustum cull sub-grids.
	//std::list<SubGrid> visibleSubGrids;
	std::list<SubGrid> visibleSubGridsquad;
	
	static int once = 0;
	static TCHAR buff[MAX_PATH];
	D3DXMATRIX V1;
	//using quadtree to cull subgrids
	gpCamera->BuildWorldFrustumPlanes(&V1);
	mQuadTree.BuildRenderList(visibleSubGridsquad, &V1);



	//visibleSubGrids.sort();
	visibleSubGridsquad.sort();

HRESULT hr = S_OK;

	//c3DDevice::m_pd3dDevice->IASetInputLayout(m_pInputLayout);
    //c3DDevice::m_pd3dDevice->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
    //c3DDevice::m_pd3dDevice->IASetVertexBuffers(0,1,&m_pVertexBuffer,&uiVertexStride,&uOffset);
    //c3DDevice::m_pd3dDevice->IASetIndexBuffer(m_pIndexBuffer,DXGI_FORMAT_R32_UINT,0);


	//D3DXMatrixIdentity(ViewProj);
	static D3DXVECTOR3 cpos;
	gpCamera->getPosition(&cpos);

	// Set the effect variables for the rendering
	//D3DXMATRIX mWorld;
   // D3DXMATRIX mWorldIT;
    //D3DXMATRIX mWorldViewProj;
    //D3DXMatrixIdentity(&mWorld);
	//D3DXMatrixTranslation( &mWorld, 0.0f, 0.0f, 0.0f );
   
	//D3DXMatrixInverse(&mWorldIT,0,&mWorld);
    
	//D3DXMatrixTranspose(&mWorldIT,&mWorldIT);
    
	//mWorldViewProj = (*ViewProj);//mView * mProj;
   
	hr = m_hViewProjVar->SetMatrix((float*)&ViewProj);
   
	hr = m_hEyePosWVar->SetFloatVector((float*) cpos);
    
	c3DDevice::m_pd3dDevice->IASetInputLayout(m_pInputLayout);
    c3DDevice::m_pd3dDevice->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST);



    // Texture Arrays for diffuse colours
	hr = m_pTerrainTextureVar[0]->SetResource(m_pTerrainTextureSRV[0]);
	hr = m_pTerrainTextureVar[1]->SetResource(m_pTerrainTextureSRV[1]);
	hr = m_pTerrainTextureVar[2]->SetResource(m_pTerrainTextureSRV[2]);

	//set blendmap
	hr = m_pBlendMapVar->SetResource(m_pBlendMapSRV);
	
	
  
	//const D3D10_INPUT_ELEMENT_DESC *disc = NULL;
	//UINT discnum = 0;

	//ID3DX10MeshBuffer *meshbuffervb = NULL;
	//ID3DX10MeshBuffer *meshbufferib = NULL;
	//ID3D10Buffer *pVB = NULL;
	//UINT vbSize = sizeof(MultiTextureTerrainVertex);
	//UINT offset = 0;
	//ID3D10Buffer *pIB = NULL;
	//SIZE_T svb = 0;
	//SIZE_T sib = 0;

	// Render Z only first to engage Z cull on occluded surfaces.
    D3D10_TECHNIQUE_DESC techDesc;
    memset( &techDesc, 0, sizeof( D3D10_TECHNIQUE_DESC ) );
    m_hTechnique->GetDesc( &techDesc );
	for(std::list<SubGrid>::iterator iter = visibleSubGridsquad.begin(); iter != visibleSubGridsquad.end(); ++iter)
	{
		//iter->mesh->GetVertexDescription(&disc, &discnum);
		//iter->mesh->GetDeviceVertexBuffer(0,&pVB);//&meshbuffervb);
		//iter->mesh->GetDeviceIndexBuffer(&pIB);//&meshbufferib);
	
			
		//meshbuffervb->Map((void**)&pVB, &svb);
		//meshbufferib->Map((void**)&pIB, &sib);

		 //c3DDevice::m_pd3dDevice->IASetVertexBuffers( 0, 1, &pVB, &vbSize, &offset );
		// Set index buffer
		//c3DDevice::m_pd3dDevice->IASetIndexBuffer(pIB, DXGI_FORMAT_R32_UINT, 0 );

		//iter->mesh->CommitToDevice();
		//iter->mesh->CommitToDevice();
		for (UINT iPass = 0; iPass < techDesc.Passes; iPass++)
		{
			ID3D10EffectPass *pCurrentPass = m_hTechnique->GetPassByIndex( iPass );
			pCurrentPass->Apply( 0 );

	      
			//c3DDevice::m_pd3dDevice->DrawIndexed(6144, 0, 0 ); 
			(iter->mesh->DrawSubset(0));
				
			

			//pIB->Release();
			//pVB->Release();
	            
		}
		//iter->mesh->Discard(D3DX10_MESH_DISCARD_DEVICE_BUFFERS );

		//meshbuffervb->Unmap();
		//meshbufferib->Unmap();

	}//end all objs


/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

   

    

    
	
}//end draw
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////



this is the old shader v2 I need to Convert to shader 4

uniform extern float4x4 gViewProj;
uniform extern float3  gDirToSunW;
uniform extern texture gTex0;
uniform extern texture gTex1;
uniform extern texture gTex2;
uniform extern texture gBlendMap;
uniform extern float3  gEyePosW;

static float3 gFogColor = {0.5f, 0.5f, 0.5f};
static float  gFogStart = 1.0f;
static float  gFogRange = 6250.0f;


static float gTexScale = 28.0f;

sampler Tex0S = sampler_state
{
	Texture = <gTex0>;
	MinFilter = ANISOTROPIC;
	MaxAnisotropy = 8;
	MagFilter = LINEAR;
	MipFilter = LINEAR;
	AddressU  = WRAP;
    	AddressV  = WRAP;
};

sampler Tex1S = sampler_state
{
	Texture = <gTex1>;
	MinFilter = ANISOTROPIC;
	MaxAnisotropy = 8;
	MagFilter = LINEAR;
	MipFilter = LINEAR;
	AddressU  = WRAP;
   	AddressV  = WRAP;
};

sampler Tex2S = sampler_state
{
	Texture = <gTex2>;
	MinFilter = ANISOTROPIC;
	MaxAnisotropy = 8;
	MagFilter = LINEAR;
	MipFilter = LINEAR;
	AddressU  = WRAP;
    	AddressV  =  WRAP;
};

sampler BlendMapS = sampler_state
{
	Texture = <gBlendMap>;
	MinFilter = LINEAR;
	MagFilter = LINEAR;
	MipFilter = POINT;
	AddressU  = WRAP;
    	AddressV  = WRAP;
};
 
struct OutputVS
{
    float4 posH         : POSITION0;
    float2 tiledTexC    : TEXCOORD0;
    float2 nonTiledTexC : TEXCOORD1;
    float  shade        : TEXCOORD2;
    float  fogLerpParam : TEXCOORD3;
};

OutputVS TerrainVS(float3 posW : POSITION0,  // We assume terrain geometry is specified
                   float3 normalW : NORMAL0, // directly in world space.
                   float2 tex0: TEXCOORD0)
{
    // Zero out our output.
	OutputVS outVS = (OutputVS)0;
	
	// Just compute a grayscale diffuse and ambient lighting 
	// term--terrain has no specular reflectance.  The color 
	// comes from the texture.
        outVS.shade = saturate(max(0.0f, dot(normalW, gDirToSunW)) + 0.3f);
    
	// Transform to homogeneous clip space.
	outVS.posH = mul(float4(posW, 1.0f), gViewProj);
	
	// Pass on texture coordinates to be interpolated in rasterization.
	outVS.tiledTexC 	= tex0 * gTexScale; // Scale tex-coord to tile.
	outVS.nonTiledTexC	= tex0 ; // Blend map not tiled.
	
	// Compute vertex distance from camera in world space for fog calculation.
	float dist = distance(posW, gEyePosW);
	outVS.fogLerpParam = saturate((dist - gFogStart) / gFogRange);


	// Done--return the output.
    return outVS;
}

float4 TerrainPS(float2 tiledTexC : TEXCOORD0, 
                 float2 nonTiledTexC : TEXCOORD1,
                 float shade : TEXCOORD2,
                 float fogLerpParam : TEXCOORD3) : COLOR
{
	// Layer maps are tiled
    float3 c0 = tex2D(Tex0S, tiledTexC).rgb;
    float3 c1 = tex2D(Tex1S, tiledTexC).rgb;
    float3 c2 = tex2D(Tex2S, tiledTexC).rgb;
    
    // Blendmap is not tiled.
    float3 B = tex2D(BlendMapS, nonTiledTexC).rgb;

	// Find the inverse of all the blend weights so that we can
	// scale the total color to the range [0, 1].
    float totalInverse = 1.0f / (B.r + B.g + B.b);
    
    // Scale the colors by each layer by its corresponding weight
    // stored in the blendmap.  
    c0 *= B.r * totalInverse;
    c1 *= B.g * totalInverse;
    c2 *= B.b * totalInverse;
    
    // Sum the colors and modulate with the shade to brighten/darken.
    float3 texColor = (c0 + c1 + c2) * shade;
    
    // Add fog.
    float3 final = lerp(texColor, gFogColor, fogLerpParam);

    return float4(final, 1.0f);
}

technique TerrainTech
{
    pass P0
    {
        vertexShader = compile vs_2_0 TerrainVS();
        pixelShader  = compile ps_2_0 TerrainPS();

	// Set the samplers to the texture's we want sampled
	Sampler[0] = (Tex0S); 
	Sampler[1] = (Tex1S); 
	Sampler[2] = (Tex2S); 
	Sampler[3] = (BlendMapS );
    }
}



my attempt on shader 4 conversion this is what I have got so far but cant find any thing else to change or set


float4x4 gViewProj;
float3  gDirToSunW;

Texture2D gTex0;
Texture2D gTex1;
Texture2D gTex2;
Texture2D gBlendMap;

float3  gEyePosW;

static float3 gFogColor = {0.5f, 0.5f, 0.5f};
static float  gFogStart = 1.0f;
static float  gFogRange = 6250.0f;


static float gTexScale = 13.0f;

///
// Rendering States
//
RasterizerState DisableCulling
{
    CullMode = NONE;
};

RasterizerState EnableCulling
{
    CullMode = BACK;
};

DepthStencilState DisableDepthTestWrite
{
    DepthEnable = FALSE;
    DepthWriteMask = ZERO;
};

DepthStencilState EnableDepthTestWrite
{
DepthEnable = false;
//A Boolean value that enables depth testing. The default value is TRUE. 
DepthWriteMask = ALL ; 

//A member of the D3D10_DEPTH_WRITE_MASK enumerated type that identifies a portion of the depth-stencil buffer that can be modified by depth data. The default value is D3D10_DEPTH_WRITE_MASK_ALL. 
DepthFunc  = LESS;

///A member of the D3D10_COMPARISON_FUNC enumerated type that defines how depth data is compared against existing depth data. The default value is D3D10_COMPARISON_LESS 
StencilEnable  = TRUE;

//A Boolean value that enables stencil testing. The default value is FALSE. 
StencilReadMask  = 0xFF;

//A value that identifies a portion of the depth-stencil buffer for reading stencil data. The default value is D3D10_DEFAULT_STENCIL_READ_MASK. 
StencilWriteMask = 0x00; 

//A value that identifies a portion of the depth-stencil buffer for writing stencil data. The default value is D3D10_DEFAULT_STENCIL_WRITE_MASK. 
FrontFaceStencilFunc = Not_Equal;
FrontFaceStencilPass = Keep;
FrontFaceStencilFail = Zero;


BackFaceStencilFunc = Not_Equal;
BackFaceStencilPass = Keep;
BackFaceStencilFail = Zero;





};

DepthStencilState DisableDepth
{
    DepthEnable = FALSE;
    DepthWriteMask = 0;
};



BlendState NoBlending
{
	BlendEnable[0] = FALSE;
};


BlendState SrcAlphaBlendingAdd
{
        BlendEnable[0] = TRUE;
        SrcBlend = SRC_ALPHA;
        DestBlend = ONE;
        BlendOp = ADD;
        SrcBlendAlpha = ZERO;
        DestBlendAlpha = ZERO;
        BlendOpAlpha = ADD;
        RenderTargetWriteMask[0] = 0x0F;
};




///////////////////////////////////////////////////////////////////////////////////////
SamplerState Tex0S
{

	Filter = ANISOTROPIC;
	MaxAnisotropy = 8;
	
    	AddressU = Wrap;
    	AddressV = Wrap;
};

SamplerState Tex1S 
{
	
	Filter = ANISOTROPIC;
	MaxAnisotropy = 8;

    	AddressU = Wrap;
    	AddressV = Wrap;
};

SamplerState Tex2S 
{
	
	Filter = ANISOTROPIC;
	MaxAnisotropy = 8;

    	AddressU = Wrap;
    	AddressV = Wrap;
};

SamplerState BlendMapS 
{
	
	Filter = MIN_MAG_MIP_POINT;//MIN_MAG_MIP_LINEAR;
    	AddressU = Wrap;
    	AddressV = Wrap;
};
 



//--------------------------------------------------------------------------------------
// Vertex shader input structure
//--------------------------------------------------------------------------------------
struct VS_INPUT
{
   

    float3 posW : VS_POSITION;  // We assume terrain geometry is specified
    float3 normalW : NORMAL; // directly in world space.
    float2 tex0: TEXCOORD;

};

//--------------------------------------------------------------------------------------
// Pixel shader input structure
//--------------------------------------------------------------------------------------
struct PS_INPUT
{
    
    float4 posH         : VS_POSITION;
    float2 tiledTexC    : TEXCOORD0;
    float2 nonTiledTexC : TEXCOORD1;
    float  shade        : TEXCOORD2;
    float  fogLerpParam : TEXCOORD3;
};



PS_INPUT TerrainVS(VS_INPUT In) // We assume terrain geometry is specified
                    		// directly in world space.
                  
{
    // Zero out our output.
	PS_INPUT outVS ;// = (PS_INPUT)0;
	
	// Just compute a grayscale diffuse and ambient lighting 
	// term--terrain has no specular reflectance.  The color 
	// comes from the texture.
        outVS.shade = saturate(max(0.0f, dot(In.normalW, gDirToSunW)) + 0.3f);
    
	// Transform to homogeneous clip space.
	outVS.posH = mul(float4(In.posW, 1.0f), gViewProj);
	
	// Pass on texture coordinates to be interpolated in rasterization.
	outVS.tiledTexC 	= In.tex0 * gTexScale; // Scale tex-coord to tile.
	outVS.nonTiledTexC	= In.tex0 ; // Blend map not tiled.
	
	// Compute vertex distance from camera in world space for fog calculation.
	float dist = distance(In.posW, gEyePosW);
	outVS.fogLerpParam = saturate((dist - gFogStart) / gFogRange);


	// Done--return the output.
    return outVS;
}


//--------------------------------------------------------------------------------------
// Pixel shader output structure
//--------------------------------------------------------------------------------------
struct PS_OUTPUT
{
    float4 RGBColor : SV_Target;  // Pixel color
};

PS_OUTPUT TerrainPS(PS_INPUT In)
		 
{
				
	PS_OUTPUT Out;// = (PS_OUTPUT)0;
	// Layer maps are tiled
    float3 c0 = gTex0.Sample(Tex0S, In.tiledTexC).rgb;//tex2D(Tex0S, tiledTexC).rgb;
    float3 c1 = gTex1.Sample(Tex1S, In.tiledTexC).rgb;//tex2D(Tex1S, tiledTexC).rgb;
    float3 c2 = gTex2.Sample(Tex2S, In.tiledTexC).rgb;//tex2D(Tex2S, tiledTexC).rgb;
    
    // Blendmap is not tiled.
    float3 B = gBlendMap.Sample(BlendMapS,In.nonTiledTexC).rgb;//tex2D(BlendMapS, nonTiledTexC).rgb;

	// Find the inverse of all the blend weights so that we can
	// scale the total color to the range [0, 1].
    float totalInverse = 1.0f / (B.r + B.g + B.b);
    
    // Scale the colors by each layer by its corresponding weight
    // stored in the blendmap.  
    c0 *= B.r * totalInverse;
    c1 *= B.g * totalInverse;
    c2 *= B.b * totalInverse;
    
    // Sum the colors and modulate with the shade to brighten/darken.
    float3 texColor = (c0 + c1 + c2) * In.shade;
    
    // Add fog.
    float3 final = lerp(texColor, gFogColor, In.fogLerpParam);

    Out.RGBColor = float4(final, 1.0f);
    return Out;
}



//--------------------------------------------------------------------------------------
// Pixel shader input structure
//--------------------------------------------------------------------------------------
struct OutputGS
{
    
    float4 posH         : VS_POSITION;
    
};



OutputGS TerrainGS(VS_INPUT In)
{
	OutputGS gsout;
	gsout.posH = In.posW;
	return gsout;
}




//RasterizerState SolidRS
//{
 //   FillMode = Solid;
//	MultisampleEnable = TRUE;
//};






technique10 TerrainTech
{
    pass P0
    {
 	SetVertexShader( CompileShader( vs_4_0, TerrainVS() ) );
        SetGeometryShader(NULL);// CompileShader( gs_4_0, TerrainGS() )  );
        SetPixelShader( CompileShader( ps_4_0, TerrainPS() ) );

        SetDepthStencilState( EnableDepthTestWrite,0);//DisableDepthTestWrite, 0 );
	SetRasterizerState(EnableCulling );

	//SetBlendState( NoBlending, float4( 0.0f, 0.0f, 0.0f, 0.0f ), 0xFFFFFFFF );

	SetBlendState( SrcAlphaBlendingAdd, float4( 0.0f, 0.0f, 0.0f, 0.0f ), 0xFFFFFFFF );


        //vertexShader = compile vs_4_0 TerrainVS();
        //pixelShader  = compile ps_4_0 TerrainPS();

	// Set the samplers to the texture's we want sampled
	//Sampler[0] = (Tex0S); 
	//Sampler[1] = (Tex1S); 
	//Sampler[2] = (Tex2S); 
	//Sampler[3] = (BlendMapS );
    }
}






I have know Idea of what to do some links or any info Thanks all.

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!