Update screenie with billboards

This is a discussion on Update screenie with billboards within the Game Programming forums, part of the General Programming Boards category; I just put billboards into my game engine. Here is an implementation that allows me to add a very bright ...

  1. #1
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,590

    Update screenie with billboards

    I just put billboards into my game engine. Here is an implementation that allows me to add a very bright sun flare.

    I'm still not real happy with it yet, but I think I can tweak it a bit.

  2. #2
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,590
    Here is a shot looking toward the first planet in the system through the flare.

  3. #3
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    In the first picture, shouldn't the flare be closer to the camera than the planet, like in the second picture?
    Isn't flares optical phenomenon that happen inside the camera/eye? It's not like there is a huge glowing cloud around the sun.
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  4. #4
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,590
    Yes this is more of a sun corona effect rather than a flare. The flare class is ready to go, but is not implemented. My terminology was incorrect.

    The billboard is centered around the sun's center. Since Z buffering is turned off for the billboard it allows the planet - the sun to show through. I may eliminate the 3D planet model for the sun altogether and just use a combination of the corona and flares.

    Also I need to implement a quad that is superimposed over the screen that is alpha blended with the background based on the angle to the sun. This will allow me to white out the screen as needed as the camera faces the sun.

    Since the sun in my world is an actual D3DLIGHT9 any models or any surfaces that are contacted by the light will illuminate. This will help a lot when I get some 3D models of ships, cockpits, etc.

    And to answer the question of the corona being closer to the planet...no it should not. However more effects are needed to simulate the light hitting the planet and refracting into the camera.

  5. #5
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    OK, if it's a corona, then I see. The lines coming out from the sun suggested some sort of lens flare.
    The 'white out' effect will be nice, I'm sure. Had I had a decent computer, I'd be looking forward to try out your engine/game.
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  6. #6
    Registered User linuxdude's Avatar
    Join Date
    Mar 2003
    Location
    Louisiana
    Posts
    926
    is the sun an object. Why do you need to billboard it??

  7. #7
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,590
    Because it's impossible to get the corona w/o doing so. Unless I want to look into some special volume texture effects using pixel shaders. This will probably be a pixel shader later but right now the only way to get some kind of bright glow is to billboard it - and it's a an aligned billboard.

    Yes the sun is an object, no you won't be able to do anything there except get close, burn up, and die. Hence no need to waste triangles on the thing.

  8. #8
    Registered User
    Join Date
    Mar 2004
    Posts
    180
    Looks good!

  9. #9
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,590
    Ok, I've got 2 more pixel shader books on the way. I made a mistake and bought the tips and tricks ShaderX2 before the into and tutorials ShaderX2. And I also picked up another book from WordWare publishing on learning/implementing shaders in CG and HLSL.

    Should be good reads. And should improve my screenies.

    But thanks for the comments. Sometimes its hard to know what looks good and what doesn't.

  10. #10
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,590
    Here is a different corona. I'm not sure what I'm looking for exactly.

    Which one is better?

    This is w/o the 3D model of the sun in it.

  11. #11
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    University of Waterloo
    Posts
    1,903
    The first one looks better, but I'm wondering how you generate these flares? Are they pre-drawn or do you have some sort of algorithm that calculates 'em on the fly? I'd assume they're predrawn as most billboarded objects are predrawn and it would be just plain crazy to calculate 'em on the fly.

    As far as billboarding goes, how do you do your billboarding calculations? I want to see if my method can be improved at all....

    This is how i calculate billboards:

    Code:
    float modelview[16];
    glGetFloatv(GL_MODELVIEW_MATRIX,modelview);
    
    Vector right(modelview[0],modelview[4],modelview[8]);
    Vector up(modelview[1],modelview[5],modelview[9]);
    Vector rminu,rpluu;
    rminu=right-up;
    rpluu=right+up;
    
    Vector dl,dr,tr,tl;
    
    Vector pos=Vector(x,y,z);
    
    dl=pos-rpluu*size;
    dr=pos+rminu*size;
    tr=pos+rpluu*size;
    tl=pos-rminu*size;
    
    glBegin(GL_QUADS);
    	glTexCoord2f(0,0);	glVertex3f( dl.x, dl.y, dl.z);
    	glTexCoord2f(0,1);	glVertex3f( tl.x, tl.y, tl.z);
    	glTexCoord2f(1,1);	glVertex3f( tr.x, tr.y, tr.z);
    	glTexCoord2f(1,0);	glVertex3f( dr.x, dr.y, dr.z);
    glEnd();
    I'm not 100% sure as to how it works still.....though I do plan on figuring it out eventually *mrrk*

  12. #12
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    Quote Originally Posted by Bubba
    Here is a different corona. I'm not sure what I'm looking for exactly.
    The second one is much better as a corona, because coronas wouldn't have the flares that the first one has.
    I think it looks a little big and bright for a corona though, but nice.

    Try adding some lens flares to the second one.
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  13. #13
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,590
    Code:
    void CStaticBillboard::Render(D3DXMATRIX view)
    {
    D3DXMATRIX matScale,matTranslate,matTranspose,matBillboardRot,matWorld;
    D3DXMATRIX matRot;
    D3DXMatrixTranspose(&matTranspose,&view);
    D3DXMatrixIdentity(&matBillboardRot);
     
    matBillboardRot._11=matTranspose._11;
    matBillboardRot._12=matTranspose._12;
    matBillboardRot._13=matTranspose._13;
    matBillboardRot._21=matTranspose._21;
    matBillboardRot._22=matTranspose._22;
    matBillboardRot._23=matTranspose._23;
    matBillboardRot._31=matTranspose._31;
    matBillboardRot._32=matTranspose._32;
    matBillboardRot._33=matTranspose._33;
     
    D3DXMatrixTranslation(&matWorld,_pos.x,_pos.y,_pos.z);
    D3DXMatrixRotationYawPitchRoll(&matRot,_rot.x,_rot.y,_rot.z);
    D3DXMatrixScaling(&matScale,_scale,_scale,1.0f);
     
    D3DXMATRIX finalworld;
    finalworld=matScale*matBillboardRot*matWorld;
    _Device->SetTransform(D3DTS_WORLD,&finalworld);
     
     
    _Device->SetRenderState(D3DRS_LIGHTING, false);
    _Device->SetRenderState(D3DRS_ZWRITEENABLE,false);
    _Device->SetRenderState(D3DRS_CULLMODE,D3DCULL_NONE);
     
     
    _Device->SetStreamSource(0,_VB,0,sizeof(TexturedPlaneVertex));
    _Device->SetFVF(TexturedPlaneVertex::FVF);
    _Device->SetIndices(_IB);
    _Device->SetTexture(0,_Texture);
     
    _Device->SetRenderState(D3DRS_ALPHABLENDENABLE,true);
    _Device->SetRenderState(D3DRS_SRCBLEND,D3DBLEND_SRCALPHA);
    _Device->SetRenderState(D3DRS_DESTBLEND,D3DBLEND_INVSRCALPHA);
     
     
    _Device->SetTextureStageState(0,D3DTSS_ALPHAOP,D3DTOP_SELECTARG1);
     
    _Device->SetTexture(0,_Texture);
    _Device->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,
    		 0,0,4,0,2);
     
     
    _Device->SetRenderState(D3DRS_LIGHTING, true);
    _Device->SetRenderState(D3DRS_ZWRITEENABLE,true);
    _Device->SetRenderState(D3DRS_ALPHABLENDENABLE,false);
     
    _Device->SetRenderState(D3DRS_CULLMODE,D3DCULL_CCW);
    }
    I take advantage of the view matrix and use the altered transpose of it. The inverse of the view matrix is really the key to the whole thing. The example I pulled from for my class is found in Special Effects Game Programming with DirectX. It's available on amazon.com for a good price. Some of the articles are fairly dated and apply to DirectX 8, but they are easily portable. Another must have book is Real Time Rendering by Muller and Haines. It is also available on amazon.com, but it is a bit pricey because it is a hardback book.

    The math involved is very clever and you will probably have to tweak it to find out why it works. The concept is this:

    1. Transpose the view matrix
    2. Take the upper left 3x3 block from the transposed matrix and use that as a rotation matrix.
    3. Combine this matrix with your rotation, translation (position), and scaling matrices.
    4. The quad will always face the camera.

    No need for arctan or anything slow. No need for any complex math - just some fiddling with the view matrix. It works like a charm.
    Last edited by VirtualAce; 10-08-2004 at 10:19 AM.

  14. #14
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    I think if you combine a lens flare effect with a sort of volumetric glow for the sun, it would look amazing.

    What I mean is instead of having just a massive texture around your sun, have it so when another planet comes in between the sun and the camera the glowing kinda melts away as the planet enters it.

    Do you have any idea what I am saying?

    EDIT:
    Have you ever played halo? If you look at the sun in halo, if you position your self so an object is moving into your view of the sun you will see what I am trying to explain.
    What is C++?

  15. #15
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,590
    Yes I know what you mean and I think the effect is achieved by billboarding flares at just the right point. There are three things I will try to get working tonight.

    1. Stars that move when you do.
    2. Sun flares, not coronas.
    3. Flying cursors/targets.

    First things first. So that my setup function does not become proprietary to one system, I'm working on creating a star system editor. I'm not sure if I'm going to use MFC or go the easy way and use Visual Basic. I'll probably use Visual Basic since it provides much of the same functionality of MFC yet is a much faster dev process. I've got some MFC code up and running but I'm not familiar with it and it's taking too long to do simple stuff.

    MFC is not hard and it's much like Borland's OWL, but VB is easier. So shoot me...I'm gonna use VB. I want to concentrate on the task at hand, not re-inventing the wheel.
    Last edited by VirtualAce; 10-09-2004 at 05:38 AM.

Page 1 of 3 123 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Polymorphism; Update functions and accessibility
    By CaptainMaxxPow in forum C# Programming
    Replies: 2
    Last Post: 04-23-2009, 08:48 AM
  2. SQLite not performing update
    By OnionKnight in forum C Programming
    Replies: 0
    Last Post: 01-21-2009, 03:21 PM
  3. July 9 2008 MS XP Update
    By VirtualAce in forum A Brief History of Cprogramming.com
    Replies: 12
    Last Post: 07-18-2008, 05:14 AM
  4. ListView Refresh, Update
    By de4th in forum C++ Programming
    Replies: 1
    Last Post: 12-23-2006, 08:13 AM
  5. file index update error
    By daluu in forum C Programming
    Replies: 1
    Last Post: 04-28-2003, 02:47 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21