Skip to main content
GameDev.net gamedev.net
🔒 Locked

Shader problem

Started by Asheh Jan 22, 2005 at 3:47 PM 0 replies 650+ views
Original Post
Asheh
Asheh
I posted a few days ago about a shader problem, here i am again, same problem. The vertices dont change at all, i checked the values of offset they are correct.. heres the whole render function

bool CEnvironment::Render(CDevice *pDevice)
{
	if(!pDevice)
	{
		return false;
	}
	HRESULT hr;

    //set the vertex constants	
	float positionConstants[2];
	positionConstants[0] = 0.9f;
	positionConstants[1] = 0.9f;

	//update the position
	hr = pDevice->getDevicePtr()->SetVertexShaderConstantF(0, (float*)&positionConstants, 2);
	if(FAILED(hr)) 
	{
		return false;
	}
	hr = pDevice->getDevicePtr()->SetVertexShader( pEnvShader );
	if(FAILED(hr)) 
	{
		return false;
	}

	//render the world
	std::vector<CEnvQuad*>::iterator envQuadItor = this->mpEnvQuads.begin();
	for(envQuadItor; envQuadItor != mpEnvQuads.end(); envQuadItor++)
	{

		hr=pDevice->getDevicePtr()->SetStreamSource(0, (*envQuadItor)->mpLevelVertexBuffer, 0, sizeof(STexturedDiffuseVertex));
		if(FAILED(hr)) 
		{
			return false;
		}
		hr=pDevice->getDevicePtr()->SetFVF(FVF_TexturedDiffuseVertex);
			if(FAILED(hr)) 
		{
			return false;
		}
		hr=pDevice->getDevicePtr()->SetTexture(0,(*envQuadItor)->mpTexture);
			if(FAILED(hr)) 
		{
			return false;
		}
		hr=pDevice->getDevicePtr()->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2); 
			if(FAILED(hr)) 
		{
			return false;
		}
	}
	return true;

}

Im not sure if i should also be setting FVF too.. if i remove it i see nothing which makes sense since my vertex shader only copies over some vertex positions... so its gotta be there. Here is how i create the vshader (im confused at where the shader declaration goes, unless thats abandoned in dx9?)

	//assemble the vertex shader
	HRESULT hr = D3DXAssembleShader( env_shader_transform , sizeof(env_shader_transform), 0,
                         0 , NULL , &mpShaderBuff , &pBuff );

	if(FAILED(hr))
	{
		DisplayError(DXGetErrorString9(hr));
		DisplayError((char*)pBuff->GetBufferPointer());
	}
	//create the vertex shader from the assembled buffer
	pDevice->getDevicePtr()->CreateVertexShader( (DWORD*)mpShaderBuff->GetBufferPointer(),
                                                               &pEnvShader);

Any help appreciated!! Thanks!
Muhammad Haggag
Muhammad Haggag
You're passing an array of 2 elements to SetVertexShaderConstantF. This means garbage goes into the w and z components of c0. Do you account for that in the shader? (i.e. do you set z and w to reasonable values?)
Just post the shader, I promise I ain't stealing it (honest!) [smile]

Quote:
Im not sure if i should also be setting FVF too

What is needed is a vertex declaration, that defines how your vertex data is layed out. FVF internally creates and sets a vertex declaration - so if your vertex structure layout corresponds to the order defined by FVF (i.e. position first, then diffuse, ...etc) it should be equivalent to creating a declaration.

Quote:
Here is how i create the vshader (im confused at where the shader declaration goes, unless thats abandoned in dx9?)

If by shader declaration you mean the dcl_usage things, it goes into asm shaders. Like this:
dcl_position v0
dcl_color v1
...(rest of shader goes here)

Their purpose is to provide a way to map the data from the vertex to registers in the shader, so that the shader isn't bound to a specific vertex layout (i.e. it doesn't matter if position comes first or color, as long as both are in the vertex).

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.