Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 03 Dec 2012
Offline Last Active Aug 01 2014 04:39 AM

Topics I've Started

Computer Graphics: Question about viewing frustum

03 May 2014 - 05:58 PM

A viewing frustum is the region in the modeled world that you can see at different distances away from your eye. In other words, it tells what direction a light ray comes in will contribute the image.


Does it mean that if a light travels at a direction that doesn't fit the viewing frustum, the light won't contribute to the image? Will the light refract at the viewport of the viewing frustum just like light refracts at the surface of our eyes?


Thank you very much!

DirectX: Questions about Alpha blending !Help !

01 January 2014 - 04:39 AM

I have already post a topic in Game Programming plate and I don't think I can repeat a same topic. But I really need some help!!

Come here and help me!


 Thank you very much!

DirectX: Questions about Alpha blending !Help !

01 January 2014 - 04:30 AM

Device->SetRenderState(D3DRS_ALPHABLENDENABLE, true);  //Open alpha blending
Device->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);  //Source factor
Device->SetRenderState(D3DRS_DESTBLEND,D3DBLEND_INVSRCALPHA);  //Destination factor
Device->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE); //blending parameter 1
Device->SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE); //blending parameter 2
Device->SetTextureStageState(0, D3DTSS_ALPHAARG0, D3DTA_CONSTANT); //blending parameter 3
Device->SetTextureStageState(0, D3DTSS_ALPHAOP,D3DTOP_MODULATE);  //parameter 1 times blending parameter 2
1. The factor D3DBLEND_SRCALPHA is (as, as, as, as). I don't understand why isn't it (rs, gs, bs, as). What does it mean by (as, as, as, as)? Does it use alpha value to displace other colors' values? I don't think it does. So what does it mean?
2. The factor D3DBLEND_SRCALPHA is (as, as, as, as). Does it blend any color channel or it just blend alpha channel?
3. What is separate blending?
4. Can I set my own blending factor for D3DRS_DESTBLEND and D3DRS_SRCBLEND?
5. I don't understand the calculation about D3DTOP_MODULATE. MSDN said arg1 multiply arg2 but how? My texture(D3DTA_TEXTURE) has a 255 value of alpha and the alpha in vertex(D3DTA_DIFFUSE) has a value of 255. How does it multiply to get 255 (cause the result is opaque)? Also, how do they multiply 64 by 255 to get 64? Any full calculation?
6. I want to multiply arg1, arg2 and arg3 together. I want to blend the alpha of my texture with the vertex alpha and the constant alpha. Can I do that?
Also, thank you !!!!!!

DirectX problem:DrawIndexedPrimitive not working with more than 2 triangle

31 December 2013 - 04:15 AM

So. The situation is that I am using OrthoGraphics and I am trying to call DrawIndexedPrimitive() in order to draw 4 triangles. The 4 triangles are actually 2 rectangles. The 2 rectangles have different coordinate. 


Part of codes:


Vertex* vertices;
VB->Lock(0, 0, (void**)&vertices, 0);  //VB is the vertex buffer
int x=-40,y=-40,w=287,h=324;
vertices[0] = Vertex(x-0.5f, -y-h+0.5f, 0.0f,0.0f,1.0f,D3DCOLOR_ARGB(255,255,255,255)); //bL
vertices[1] = Vertex(x-0.5f,-y+0.5f, 0.0f,0.0f,0.0f,D3DCOLOR_ARGB(255,255,255,255));  //tL
vertices[2] = Vertex(x+w-0.5f,-y-h+0.5f, 0.0f,1.0f,1.0f,D3DCOLOR_ARGB(255,255,255,255));  //bR
vertices[3] = Vertex(x+w-0.5f, -y+0.5f, 0.0f,1.0f,0.0f,D3DCOLOR_ARGB(255,255,255,255));   //tR
vertices[4] = Vertex(x-0.5f, -y-h+0.5f, 0.0f,0.0f,1.0f,D3DCOLOR_ARGB(255,255,255,255)); //bL
vertices[5] = Vertex(x-0.5f,-y+0.5f, 0.0f,0.0f,0.0f,D3DCOLOR_ARGB(255,255,255,255));  //tL
vertices[6] = Vertex(x+w-0.5f,-y-h+0.5f, 0.0f,1.0f,1.0f,D3DCOLOR_ARGB(255,255,255,255));  //bR
vertices[7] = Vertex(x+w-0.5f, -y+0.5f, 0.0f,1.0f,0.0f,D3DCOLOR_ARGB(255,255,255,255));   //tR
WORD* indices = 0;
IB->Lock(0, 0, (void**)&indices, 0);  //IB is the index buffer
indices[0]  = 0; indices[1]  = 1; indices[2]  = 2;
indices[3]  = 3; indices[4]  = 2; indices[5]  = 0;
indices[6]  = 4; indices[7]  = 5; indices[8]  = 6;
indices[9]  = 7; indices[10]  = 6; indices[11]  = 4;


//////////////Render part///////////////

Device->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 1.0f, 0);
Device->Present(0, 0, 0, 0);

//////////////Render part///////////////



Result: It only drew the first 6 indices. (I did an experiment to prove this statement. I set the alpha to 128 so if it drew the same object at the same position twice, it will not be transparent. But it is still transparent which means it only drew it once, which means it only drew the first 6 indices.)


I can use two calls to achieve it. Like this:

or this:
But not this (one call):
Is there any method to do that with one call? I want to make it into a batch.


DirectX 9 performance : batch matrix

26 December 2013 - 06:28 PM

Currently I decide to use batching render in order to improve performance. I found texture atlas, a method to batch a lot of textures. But what about different object have different matrix? Can we do that in a batch? I think we can transform all the matrix into vertex. But I don't think it has a good performance. Any ideas?