Screen of first try at per-pixel diffuse

This is a discussion on Screen of first try at per-pixel diffuse within the Game Programming forums, part of the General Programming Boards category; This is my first running version of per-pixel diffuse lighting with texture blending. The texture ops are: Code: float4 PS(float3 ...

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

    Screen of first try at per-pixel diffuse

    This is my first running version of per-pixel diffuse lighting with texture blending.

    The texture ops are:

    Code:
    float4 PS(float3 Light : TEXCOORD0,float3 Norm : TEXCOORD1,
    		  float2 TerrainUV : TEXCOORD2,float2 DetailUV : TEXCOORD3) : COLOR
    {
    	//ambient
    	float4 A={0.1,0.1,0.1,0.1};
    	
    	//vDic=intensity * color
    	vector TerrainColor=tex2D(Terrain,TerrainUV);
    	vector DetailColor=tex2D(Detail,DetailUV);
    	vector MixColor=(TerrainColor+DetailColor);
    	
    	
    	return A*MixColor+vDic * saturate(dot(Light,Norm));
    }
    As you can see I'm just currently doing additive texture blending, but it looks great. The per-pixel lighting is sooooo much better than per-vertex.
    Now that I've got it working and understand a lot more about pixel and vertex shaders, look out for some razzle dazzle effects.
    Last edited by VirtualAce; 03-12-2011 at 10:42 AM.

  2. #2
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,586
    Another one with more subtle lighting and a bit of green ambient. I think this light looks more like natural sunlight.
    Last edited by VirtualAce; 03-12-2011 at 10:42 AM.

  3. #3
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    Nice screens Bub-wubs.
    What exactly are you working on - or are these just fiddlings ?
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  4. #4
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,586
    Fiddlings with shaders.

  5. #5
    Registered User linuxdude's Avatar
    Join Date
    Mar 2003
    Location
    Louisiana
    Posts
    926
    I'm sure that per pixel is much better but not faster Also I read that the ambient light should be 10%-40% of diffuse light. Are you doing that? I'd like to see some of this. Thanks Looks good

  6. #6
    The Right Honourable psychopath's Avatar
    Join Date
    Mar 2004
    Location
    Where circles begin.
    Posts
    1,070
    Quote Originally Posted by linuxdude
    I'm sure that per pixel is much better but not faster
    It's plenty fast if your graphics card supports dynamic branching.
    Memorial University of Newfoundland
    Computer Science

    Mac and OpenGL evangelist.

  7. #7
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,586
    There is no noticeable drop in frame rate with the diffuse shader. As you can see 424 is quite fast enough. No I'm not using those ratios for ambient/diffuse. That might work in life, but with graphics I use the light settings that I think look correct.

  8. #8
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,062
    Hmmm... how much trouble would it be for you to give a side by side of the same render, one with per-pixel lighting and one with per-vertex lighting?
    Sent from my iPadģ

  9. #9
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Bah, that's easy! I want to see it render it split in half down the middle two different ways! Come on Bubba, do your magic!


    Quzah.
    Hope is the first step on the road to disappointment.

  10. #10
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,586
    I'm working on per-pixel specular and bump mapping.

    Since you can only use 1 shader at a time, I'm trying to tie the general all purpose effects into one shader. That way I can apply my TSpecBump shader to all objects. The main problem is that not all my objects require 3 textures. So I have to use flow control to check for the number of textures, or I can set a constant from code in the shader to notify how many textures should be in the final blend.

    So when I render something like water which requires much more than TSpecBump, I can use a completely different shader. This comes down to rendering batches of similar shader objects at a time.

  11. #11

    Join Date
    May 2005
    Posts
    1,041
    >>As you can see 424 is quite fast enough

    Pfft, I optimzed my program to render at 5,000 FPS. It just doesn't draw anything.

    How long have you been spearheading this program (and shaders in general). I'm actually not sure what your familiarization is with shaders (is this really your first attempt? or...)

    Anyway, looks good man!

    Oh ........ i've gotta reply to your terrain thread! Almost forgot!
    I'm not immature, I'm refined in the opposite direction.

  12. #12
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,586
    This is a screenshot of per-pixel diffuse with per-pixel specular. This is pure Phong shading, not Blinn-Phong. The FPS dropped significantly.
    Last edited by VirtualAce; 03-12-2011 at 10:42 AM.

  13. #13
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,586
    Another screenie with some criss-cross trees.

    They are not being sorted at the moment so I'm getting all kinds of graphical errors.

    Specs for this screenie:
    • Brute-force regular 256x256 grid
    • Cellsize of 128
    • Height maginfication of 32
    • Near plane at 10.0f
    • Far plane at 100000.0f
    • HFOV of 85 degrees.
    • 2500 trees, each tree is 2 quads, 8 vertices, 12 indices, 4 tris
    • Per-pixel diffuse
    • Per-pixel specular
    • 2 textures for terrain render - colormap and detail texture
    • 1 texture for trees
    • 1 RAW heightmap texture for terrain heights
    • Alpha blends - Source=D3DBLEND_SRCALPHA Dest=D3DBLEND_INVSRCALPHA




    Trees are in a static vertex buffer and are rendered in one call. Sorting them is going to be a pain because I won't be able to render in one call.

    Plans are to stick trees and terrain into a quad tree and then sort the trees back to front. Hopefully this will minimize FPS issues.
    Last edited by VirtualAce; 03-12-2011 at 10:42 AM.

  14. #14
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,586
    Fixed the problem w/o sorting. I always wondered why Grand Theft Auto and some other games had weird things happening around the edges of the transparency.

    It is a driver problem with this code:

    Code:
    m_psDevice->SetRenderState( D3DRS_ALPHATESTENABLE, true ); 
      m_psDevice->SetRenderState( D3DRS_ALPHAREF, 0x01 ); 
      m_psDevice->SetRenderState( D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL );
    It seems to work well at low z angles (z values are not changing rapidly as you move 'into' the scene, but at high z angles it gives off a weird blueish tint to the textures.

    These 3 lines of code are leading me to believe that not every game is even sorting the polies. Using alpha testing you really don't need to.

    I'm sure I'll find some other issues, but I'm going to try this method with texture splatting for cloud generation. We will see how it works.

    Here is a screenie of the improved render.

    EDIT: It's not a driver error. It's caused by an imperfect alpha mask.
    Last edited by VirtualAce; 03-12-2011 at 10:42 AM.

  15. #15
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,586
    Ok and last screenie.

    This is just a sky plane. I'll do texture splatting tomorrow along with bump mapping for the terrain and then the sky scatter shader. I hope to add a sun and sun flare effect. Possibly looking into a water plane that is environment mapped (now that I know how NOT to do it), perturbed, and/or displaced using a displacement map vertex shader.

    Lots of fun.
    Last edited by VirtualAce; 03-12-2011 at 10:42 AM.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting Pixel Colour Screen
    By god_of_war in forum C++ Programming
    Replies: 3
    Last Post: 03-14-2006, 12:17 PM
  2. Feedback: Functional Specification Wording
    By Ragsdale85 in forum C++ Programming
    Replies: 0
    Last Post: 01-18-2006, 03:56 PM
  3. char copy
    By variable in forum C Programming
    Replies: 8
    Last Post: 02-06-2005, 09:18 PM
  4. i am not able to figure ot the starting point of this
    By youngashish in forum C++ Programming
    Replies: 7
    Last Post: 10-07-2004, 02:41 AM
  5. Green Pixel On My Screen???
    By (TNT) in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 01-21-2002, 07:09 AM

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