Sign in to follow this  
LYH1

Some question on blending texture

Recommended Posts

LYH1    122
I want to write a routine that can read a 8bit qrayscale bitmap as alpha channel and blend to the current canvas, the problem is it take the 8bit qrayscale bitmap as color information with no alpha information. How to set the 8bit texture's color information to corroperate with alphaop arg1? (I dont mix them to RGBA first because I will use different texture as alpha channel in runtime) Here is the code that take the 8bit texture as alphachannel result is the black color surface alphablend with texture in texture stage1.
  DXDraw.D3DDevice7.SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, 1);
  DXDraw.D3DDevice7.SetRenderState(D3DRENDERSTATE_SRCBLEND, Integer(D3DBLEND_DestALPHA));
  DXDraw.D3DDevice7.SetRenderState(D3DRENDERSTATE_DESTBLEND, Integer(D3DBLEND_INVDestALPHA));

  DXDraw.D3DDevice7.SetTextureStageState(0,D3DTSS_ALPHAOP,Integer(D3DTOP_MODULATE));
  DXDraw.D3DDevice7.SetTextureStageState(0,D3DTSS_ALPHAARG1,Integer(D3DTA_TEXTURE));

  DXDraw.D3DDevice7.SetTextureStageState(1,D3DTSS_COLOROP,Integer(D3DTOP_MODULATE));
  DXDraw.D3DDevice7.SetTextureStageState(1,D3DTSS_COLORARG1,Integer(D3DTA_TEXTURE));
  DXDraw.D3DDevice7.SetTextureStageState(1,D3DTSS_TEXCOORDINDEX,0);

  C := RGBA_MAKE($ff,$ff,$ff,$ff);
  FVertex[0].Color:= C;
  FVertex[1].Color:= C;
  FVertex[2].Color:= C;
  FVertex[3].Color:= C;


  DXDraw.D3DDevice7.SetTexture(0,nil);
    If NOT CanFindTexture(mask) Then {when no texture in list try load it}
    If NOT LoadTextures(mask) Then Exit; {on error occurr out}
        I := FD2DTexture.Find(mask.Name);
  If I = -1 Then Exit;
  DXDraw.D3DDevice7.SetTexture(0, FD2DTexture.Texture[I].D2DTexture.Surface.IDDSurface7);

  DXDraw.D3DDevice7.SetTexture(1,nil);
    If NOT CanFindTexture(Image) Then {when no texture in list try load it}
    If NOT LoadTextures(Image) Then Exit; {on error occurr out}
        I := FD2DTexture.Find(Image.Name);
  If I = -1 Then Exit;

  DXDraw.D3DDevice7.SetTexture(1, FD2DTexture.Texture[I].D2DTexture.Surface.IDDSurface7);
  DXDraw.D3DDevice7.SetRenderState(D3DRENDERSTATE_COLORKEYENABLE, Ord(FD2DTexture.Texture[I].D2DTexture.Transparent));

  If (Image.PatternHeight <> 0) Or (Image.PatternWidth <> 0) Then Begin
    R := Image.PatternRects[Pattern];
    SrcX := 1 / FD2DTexture.Texture[I].D2DTexture.Surface.Width;
    SrcY := 1 / FD2DTexture.Texture[I].D2DTexture.Surface.Height;
    FD2DTexture.Texture[I].FloatX1 := SrcX * R.Left;
    FD2DTexture.Texture[I].FloatY1 := SrcY * R.Top;
    FD2DTexture.Texture[I].FloatX2 := SrcX * (R.Right-1);
    FD2DTexture.Texture[I].FloatY2 := SrcY * (R.Bottom-1);
  End;

  FVertex[0].tu:= FD2DTexture.Texture[I].FloatX1;
  FVertex[0].tv:= FD2DTexture.Texture[I].FloatY1;
  FVertex[1].tu:= FD2DTexture.Texture[I].FloatX2;
  FVertex[1].tv:= FD2DTexture.Texture[I].FloatY1;
  FVertex[2].tu:= FD2DTexture.Texture[I].FloatX1;
  FVertex[2].tv:= FD2DTexture.Texture[I].FloatY2;
  FVertex[3].tu:= FD2DTexture.Texture[I].FloatX2;
  FVertex[3].tv:= FD2DTexture.Texture[I].FloatY2;

  FVertex[0].sx:= R.Left-0.5;
  FVertex[0].sy:= R.Top-0.5;
  FVertex[1].sx:= R.Right-0.5;
  FVertex[1].sy:= R.Top-0.5;
  FVertex[2].sx:= R.Left-0.5;
  FVertex[2].sy:= R.Bottom-0.5;
  FVertex[3].sx:= R.Right-0.5;
  FVertex[3].sy:= R.Bottom-0.5;

  DXDraw.D3DDevice7.DrawPrimitive(D3DPT_TRIANGLESTRIP, D3DFVF_TLVERTEX, FVertex, 4, D3DDP_WAIT);


Share this post


Link to post
Share on other sites
ET3D    810
DX7 and VB? {ET faints}

Phew, just had a horrible nightmare. What, you mean it's real? Okay, okay. I don't have a good solution, but there are things you could try. But anything I say may not be applicable to this situation (DX7).

First, you're leaving partial stages, which you shouldn't do. You haven't specified a colour op for the first stage and and alpha op for the second. What do you expect them to do? I'm not saying that adding them will solve your problem, but leaving them out is a clear error.

I thought of suggesting trying D3DTOP_DOTPRODUCT3 to replicate into the alpha, but reading the docs, I'm not sure that'd work (DX9 docs, comment about DX7). It might still be worth trying.

Probably the best way to go about it would be to use an alpha texture. I didn't fully understand what you said there about the use of the textures. Are you using the same data for both colour and alpha? In that case, you might have to duplicate it.

I hope some of this would help.

Share this post


Link to post
Share on other sites
LYH1    122
THX for reply, I am using DelphiX .(Seems already outdated when everyone talking HLSL)
The problem resloved, just alphablend them one more time only and I got the result.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this