pixel shader program, hardware not compatible?

Started by
7 comments, last by ET3D 16 years, 10 months ago
hi, I used pixel shader to make a texture transparent,(VISUAL C++ 6.0/DirectX 9.0) but when i call :
Quote: HRESULT ht = g_pd3dDevice->CreatePixelShader( (DWORD*)pCode->GetBufferPointer(), &m_pPixelShader );
it returned D3DERR_INVALIDCALL. so my shader code could not work. I check the adapter campatabilities:
Quote: D3DCAPS9 d3dCaps; if (FAILED(g_pd3dDevice->GetDeviceCaps(&d3dCaps))) { AfxMessageBox("error: GetDeviceCaps() in CheckAdapterShader() failed"); return E_FAIL; } if (d3dCaps.PixelShaderVersion < D3DPS_VERSION(1,1) ) { AfxMessageBox("error: Pixel Shader Version < 1.1 ps_1_1 no support"); return E_FAIL; }
I got: error: Pixel Shader Version < 1.1 ps_1_1 no support. so, that means I cannot use pixel shader? since the ps_1_1 is the lowest version, i believe. is there any way I can use pixel shader? a driver software or something? because this piece of code for transparent texture with pixelshader just works fine in my other computer, but not this target one (VIA, EPIA-CN). I can't believe it can not support ps_1_1, since ps_2_2 is now popular now. any one know how can i get it around, so I can still use the pixel shader? or I can only give it up? I want use it to make a texture transparent on the screen cover, so I can draw graphics. thanks.
Advertisement
Integrated solution uh? Bad trouble!

Unluckly, I read VIA EPIA CN is a chipset for those small and economic PCs running the Via (Centaur) chip. I really don't know if they accept a external vid card... I guess not since this would come with a price. I wonder how you managed to get one really.

On the VIA page I read "the 128-bit 3D graphics engines features dual pixel rendering pipes for advanced 3D rendering, and is capable of two textures per pass with a triangle rate up to 4.5 million triangles per second, a pixel rate up to 200 million pixels per second, and a texel bilinear fill rate up to 400 million texels per second."

The GeForce2 was called "GTS" because it could produce (theorically) more than 1024 million pixels per second... Hi-end chips for portable devices now feature similar (possibly higher) performance and consistently extended features!
No, I guess you really have no support for PS.

Using a software solution is a real pain. You can try with the reference rasterizer but it's not something I suggest you to do. Besides requiring some work to get going, it will give you less than 1fps easily. I had this awful experience and I can tell this is not going to take you anywhere.
Considering the power of the VIA processor, you'll be lucky when getting .1 fps.
Just as a reference, my previous system (XP1800+) ranged about 0.3 fps for a "simple" scene taking 500x500 pixels...

Previously "Krohm"

You can use alpha without pixel shaders. Pixel shader 1.1 is pretty much a more compact way of using texture stage states. Each stage has a colorop and an alphaop. Each op may have 1, 2, or 3 arguments. These pretty much directly reflect instructions in ps.1.1 assembly, with minimal features missing.

so instead of
mul r0.rgb, t0, v0
+mov r0.a, t0.a

you'd have: (All are SetTextureStageState calls)
0, D3DTSS_COLOROP, D3DTOP_MODULATE
0, D3DTSS_COLORARG1, D3DTA_TEXTURE
0, D3DTSS_COLORARG2, D3DTA_DIFFUSE
0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1
0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE

1, D3DTSS_COLOROP, D3DTOP_DISABLE
1, D3DTSS_ALPHAOP, D3DTOP_DISABLE

just translate whatever shader you have, usually it's pretty simple.
If the hardware supports eight texture stages and the 'temp' register then you can translate pretty much any ps_1_1 shader to the fixed-function pipeline.

For a software solution you might want to try SwiftShader...
Thank you guys for your replies.

Krohm : yes, we use this VIA EPIA-CN because we want to lower down our product cost. but at same time, we have to realize the functionalities, so i have no choice but to go ahead with it. my application is not a game, but directx can significantly make display faster, so i adopted. (the pity is i am a newbie to this directx)


Namethatnobodyelsetook and C0D1F1ED:

i am not fully familiar what you told, but indeed i am using alpha test to do it. now my problem is I can sucessifully make the cover texture transparent, but without the pixel shader, I can not make the graphics I draw on the texture to show, all things, including the graphics on the texture, are totally transparent, I can not draw, that is not what I wanted.

I am here include some code snippet to explain:

code piece 1:
Quote:
// omitted are d3d creations and first 3d scene creation

// create a m_pTransTexture, it will become transparent, so I
// can draw graphics using mouse

if(FAILED(D3DXCreateTexture(m_pIDirect3DDevice,800,600,1,0, D3DFMT_X8R8G8B8,D3DPOOL_MANAGED,&m_pGunTexture) )) {
AfxMessageBox("Create cover texture failed.");
return false;
}

// filled the texture with color 0xffffff00;
// lock the surface, filled the data, unlock it. codes omitted



then I draw graphics on the m_pTransTexture, some lines and ellipse

code piece 2:
Quote:
D3DSURFACE_DESC desc;
ZeroMemory( &desc , sizeof( D3DSURFACE_DESC ) );

if( pTex )
{
LPDIRECT3DSURFACE9 pSur;
pTex->GetSurfaceLevel ( 0 , &pSur );
pSur->GetDesc ( &desc );

HDC hDC;

TCHAR* str = "Try to write on the screen ";

pSur->GetDC(&hDC);

CDC *pDC = CDC::FromHandle(hDC);

pDC->SetTextColor(0x00FF0000); // blue text
pDC->SetBkMode(TRANSPARENT);
pDC->TextOut(50, 100, str, strlen(str));

CPen Pen;
Pen.CreatePen(PS_SOLID, 1, RGB(255,255,255));
CPen* Poldpen=pDC->SelectObject(&Pen);

pDC->MoveTo(0,280);
pDC->LineTo(180,280); // horizontal line

CBrush BKBrush,*pOldBrush;
pOldBrush = (CBrush *)pDC->SelectStockObject(HOLLOW_BRUSH);
pDC->Ellipse(200,200,500,500);

pDC->SelectObject(pOldBrush);

pDC->SelectObject(Poldpen);
Pen.DeleteObject();

pSur->ReleaseDC(hDC);

pSur->Release();
}



Why I still use GDI, it's that my software use have to use mouse to draw on screen, some random line, curves, or tracing line, etc. GDI is comvienent thought slow...

in Render():

code piece 3:
Quote:
m_pIDirect3DDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);
m_pIDirect3DDevice->BeginScene();

// the scene to be see trough the covered m_pTransTexture
m_pIDirect3DDevice->SetStreamSource(0,m_pTigerVertexBuffer,0,sizeof(CUSTOMVERTEX));
m_pIDirect3DDevice->SetFVF(CUSTOMVERTEX_FVF);
m_pIDirect3DDevice->SetTexture(0,m_pTigerTexture);
m_pIDirect3DDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2); // (1)

m_pIDirect3DDevice->SetStreamSource(0,m_pGunVertexBuffer,0,sizeof(CUSTOMVERTEX));
m_pIDirect3DDevice->SetTexture(0,m_pGunTexture);
m_pIDirect3DDevice->SetRenderState(D3DRS_ALPHATESTENABLE,TRUE);
m_pIDirect3DDevice->SetRenderState(D3DRS_ALPHAREF,0xffffff00);
m_pIDirect3DDevice->SetRenderState(D3DRS_ALPHAFUNC,D3DCMP_NOTEQUAL);//(2)


m_pIDirect3DDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2); // (3)
m_pIDirect3DDevice->SetRenderState(D3DRS_ALPHATESTENABLE,FALSE);

m_pIDirect3DDevice->EndScene();

m_pIDirect3DDevice->Present(NULL, NULL, NULL, NULL);

}




Now the result is: because I filled the m_pTransTexure with color 0xffffff00;
if in code piece 3, sentence (2), i use D3DCMP_EQUAL, then I can make the cover m_pTransTexture transparent, see through the 3d scene undercovered. but the graphics( a text, a line and a ellipse ) drawn by code piece 2 are also gone!

if in code piece 3, sentence (2), I use D3DCMP_NOTEQUAL, then I can see the yellow m_pTransTexture not transparent,(thought all the graphics, line, ellipse on it to be seen ). the undercovered 3d scene is covered. which is not what i wanted.


is it possible that I can make the m_pTransparent transparent, so the undercovered 3d scene can be see, but also the graphics on the m_pTransparent can be seen?

with pixel shader, I can do it. but now the hardware don't support ps, can I do it?

Thank you very much..
To Namethatnobodyelsetook:

I used the following ps file .

Quote:
ps.1.1

def c1, 1.0f,1.0f,1.0f,1.0f

tex t0
dp3 r1, t0, c1
mov r1.rgb,t0
mov r0,r1



How can I translate them into Alpha op in stage render states? I am not familiar any of this. Thank you very much.

when I use the pixel shader code as above, integrating with the program i described in the upper post, i can make the m_pTransTexture transparent, so undercovered 3d scene can be see, at same time, the graphics(line,ellipse ) on the m_pTransTexture can also be seen on screen.

now without pixel shader, I don't know how to get the graphics(line, ellipse,etc) back...

Thank you very much..

Quote:Original post by coolscene
ps.1.1

def c1, 1.0f,1.0f,1.0f,1.0f

tex t0
dp3 r1, t0, c1
mov r1.rgb,t0
mov r0,r1

The equivalent of this in texture stages should be:

0, D3DTSS_COLOROP, D3DTOP_SELECTARG1
0, D3DTSS_COLORARG1, D3DTA_TEXTURE
0, D3DTSS_ALPHAOP, D3DTOP_DOTPRODUCT3
0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE
0, D3DTSS_ALPHAARG2, D3DTA_TFACTOR

1, D3DTSS_COLOROP, D3DTOP_DISABLE
1, D3DTSS_ALPHAOP, D3DTOP_DISABLE
I'm not sure ET3D's texture stages will work. I think in the fixed pipe dot3 is only available as a colorop, and when used it ignores the alphaop on that stage... it's a bit special. Plus it's an optional feature that your chipset may not support, introduced around the GeForce2 era.

Your shader isn't even needed. You're using 32-bit textures with X8R8G8B8. Change it to A8R8G8B8, and do the dp3 on the CPU, storing the result in the alpha bits of the texture. It takes no extra space, and makes everything a plain texture lookup. It's faster, and works on all hardware.
Quote:Original post by Namethatnobodyelsetook
I'm not sure ET3D's texture stages will work. I think in the fixed pipe dot3 is only available as a colorop, and when used it ignores the alphaop on that stage... it's a bit special. Plus it's an optional feature that your chipset may not support, introduced around the GeForce2 era.

According to the docs, it should be available as an alpha op. I agree it might replicate to colour, too, but that's possible to change in a further stage. As for being available, it's easy to check, considering that it's a very specific target hardware.

I agree that doing it in the original texture would be better supported, though the texture stages are meant to show that it's possible to convert many simple shaders to texture stages.

This topic is closed to new replies.

Advertisement