Jump to content
  • Advertisement
Sign in to follow this  

DX8, Bumpmapping, distort a texture dont work

This topic is 3971 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

Hey, my aim is create a "distoring mirror". This is an tipical bump mapping example. But I only get a dark screen. Init the things: Device.CreateTexture(256,256, 1, 0, D3DFMT_V8U8, D3DPOOL_MANAGED, BumpMapTexture); BumpMapTexture.LockRect(0, LR, nil, 0); for y0:= 0 to Height-1 do begin pDst:= LR.pBits; Inc(pDst, y0*LR.Pitch); for x0:= 0 to Width-1 do begin iDu:= random(100); iDv:= random(100); pDst^:= Round(iDu); Inc(pDst); pDst^:= Round(iDv); Inc(pDst); end; end; BumpMapTexture.UnlockRect(0); Device.CreateVertexBuffer(4*SizeOf(TBumpVertex), D3DUSAGE_WRITEONLY, D3DFVF_XYZ or D3DFVF_TEX2, D3DPOOL_MANAGED, BumpVertex); BumpVertex.Lock(0, 0, PByte(vLens), 0); vLens[0].p := D3DXVector3(-256.0,-256.0, 0.0); vLens[1].p := D3DXVector3(-256.0, 256.0, 0.0); vLens[2].p := D3DXVector3( 256.0,-256.0, 0.0); vLens[3].p := D3DXVector3( 256.0, 256.0, 0.0); vLens[0].tu1 := 0.0; vLens[0].tv1 := 1.0; vLens[1].tu1 := 0.0; vLens[1].tv1 := 0.0; vLens[2].tu1 := 1.0; vLens[2].tv1 := 1.0; vLens[3].tu1 := 1.0; vLens[3].tv1 := 0.0; BumpVertex.Unlock; ------------ AND DRAWING: ------------ // Render the background Device.SetTexture(0, BackText); Device.SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE); Device.SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1); Device.SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE); // Render the lens Device.SetTexture(0, BumpMapTexture); Device.SetTexture(1, BackText); Device.SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_BUMPENVMAP); Device.SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE); Device.SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_CURRENT); Device.SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_DISABLE); Device.SetTextureStageState(0, D3DTSS_BUMPENVMAT00, F2DW(0.2)); Device.SetTextureStageState(0, D3DTSS_BUMPENVMAT01, F2DW(0.0)); Device.SetTextureStageState(0, D3DTSS_BUMPENVMAT10, F2DW(0.0)); Device.SetTextureStageState(0, D3DTSS_BUMPENVMAT11, F2DW(0.2)); Device.SetTextureStageState(0, D3DTSS_BUMPENVLSCALE, F2DW(1.0)); Device.SetTextureStageState(0, D3DTSS_BUMPENVLOFFSET, F2DW(0.0)); Device.SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_SELECTARG1); Device.SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_TEXTURE); Device.SetTextureStageState(1, D3DTSS_COLORARG2, D3DTA_CURRENT); Device.SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_DISABLE); // Generate texture coords depending on objects camera space position mat._11 := 0.5; mat._12 := 0.0; mat._21 := 0.0; mat._22 :=-0.5; mat._31 := 0.0; mat._32 := 0.0; mat._41 := 0.5; mat._42 := 0.5; // Scale-by-z here Device.GetTransform(D3DTS_VIEW, matView); Device.GetTransform(D3DTS_PROJECTION, matProj); vEyePt:= D3DXVector3(matView._41, matView._42, matView._43); z := D3DXVec3Length(vEyePt); mat._11:= mat._11 * ( matProj._11 / ( matProj._33 * z + matProj._34 )); mat._22:= mat._22 * ( matProj._22 / ( matProj._33 * z + matProj._34 )); Device.SetTransform(D3DTS_TEXTURE1, mat); Device.SetTextureStageState(1, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2); Device.SetTextureStageState(1, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_CAMERASPACEPOSITION or 1); // Position the lens D3DXMatrixTranslation(matWorld, 0,0, 0); Device.SetTransform(D3DTS_WORLD, matWorld); Device.SetVertexShader(D3DFVF_BUMPVERTEX); Device.SetStreamSource(0, BumpVertex, SizeOf(TBumpVertex)); // Render the lens Device.DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2); and so I get wrong picture, doesnt work. I think the problem is with camera settings. What do I do? And how to set up that the position would be pixel-by-pixel, not with a single variable.

Share this post

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

  • Advertisement

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!