Results 1 to 26 of 26

Thread: Vertex Shaders & Pixel Shaders -[RESOLVED]-

  1. #1

    Thread Starter
    Ex-Super Mod'rater Electroman's Avatar
    Join Date
    Sep 2000
    Location
    Newcastle, England
    Posts
    4,349

    Resolved Vertex Shaders & Pixel Shaders -[RESOLVED]-

    I have never had a chance to play with these my self yet but one thing I'm not sure about is: Whats the differance between the two of them?
    And if you don't mind whats the main idea behind them .
    Last edited by Electroman; Sep 20th, 2004 at 09:09 AM.
    When your thread has been resolved please edit the original post in the thread ()
    and amend "-[RESOLVED]-" to the end of the title and change the icon to , Thank you.

    When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

  2. #2
    Fanatic Member
    Join Date
    Jan 2003
    Posts
    1,004
    "Can't" and "shouldn't" are two totally separate things.

    All questions should be answered. All answers should be true. That is why I post.

  3. #3
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    And most importent of all. Never listen to NVIDIA. In the last race ATI kicked NVIDIA in the shader ass. As they implemented more then NVIDIA. Might turn around soon. But untill then, listen to me..

    Shaders:
    Shaders are intended to replace the fixed matte-plastic look that has been a part of consumer level graphics and games for the past few years. Shades are intended to give greater freedom to artists and programmers so they may vreate a unique look and style for their application. Shaders are designed to run on the hardware in real time, with control over just how involved and complicated the shader is in the hands of the programmer and artist.

    What you can do with shaders:

    • Perform basic geometry transformations
    • Warp the geometry
    • Blend or sjin geometry
    • Generate color information (specular and diffuse)
    • Tween vertices between transformation matrices
    • Generate textures coordinates
    • Transform texture coordinates
    • Size point sprites
    • Use a custom illumination model
    • Perform nonphotorealistic rendering (cartoon rendering, scatches (SP?))
    • Perform bump, environment, and specular mapping
    • Perform your own texture-blending operations
    • Clip pixels


    So in the end, this is just a taste. The only limitation is your imagination, and the instruction count on the GPU you are using. But this is getting better for every new version.

    You have diffrent versions of the language. I am not that into that part yet. But you have both PS and VS 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 2.0, 2.a, and 3.0 is comming. The shader language is a ASM look alike language. Then again you have the HLSL (high level shader language, that is a C look alike language, you can use to write your shaders wiht. It was introdused in DX9. It is easier to use, but not so easy to see what instructions that is realy beeing used.

    There is a lot more to it. But I have to write a new post for it. Will draw a picture too, so you can see where it fits into the DX pipeline. PS and VS are supposed to replace two diffrent areas in the DX pipeline.

    Just have to get off this shirt and tie first...

  4. #4
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    Here is an overview of the DX pipeline. As you can see Vertex Shaders are going to replace the TnL part of the pipeline in the future. I have never used a Pixel Shader before. But I think you have to use a Vertex Shaders first to use a Pixel Shader, and it looks like it is going to replace the multitexturing stage.



    Will be back with more info in a bit. Just have to eat some too..
    Attached Images Attached Images  

  5. #5
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    Vertex shader vs. Pixel Shaders:

    Vertex Shaders operates on vertices, or more precise, the output is assumed to be a vertex in homogenous clip space coordinates. A vertex shader produses one vertex as its output, from a set of vertices provided as input.

    A Pixel shader produces the color of the pixel as its sole output, from color and/or texture coordinates provided as input (BTW found out that you can choose to use a pixel shader, without vertex shader too).

    Vertex shader:
    Vertex shaders as I said are going to replace the TnL in the part in the D3D AND OGL pipeling. This pipelinge is called FFP (Fiexd function pipeline) since it is not programable as the shaders are. Hence all the games looks a bit the same in the end.

    A vertex shaders job is to is to take a set of of input input vertices and generate an output set of vertices. There is a one to one relationship between the input and output vertices. A vertex shader can not change the numbers of vertices since it's called once for each vertex in a primitive. So if you have a triangle and pass it to a vertex shader, I think (don't quote me on this) that the shader you write will be called 3 times, and takes one vertex as an input every time, and one vertex as an output for every time it is called. I might be wrong here.

    The input to a vertex shader can be one or more vertex streams, plus any other state information, (like current textures).

    The output is a new vertex position in clip coordinates, and any other information that the shader provides, like vertex color, texture coordinates, fog values and so on.


    Pixel Shaders: (had to look some of this up..)
    The pixel shaders are supposed to replace the pixel-blending section of the multitexture section of the pipeline.

    The Pixel shader is going to expect two color registers as input: one for diffuse, and one for specular. You can also pass it texture coordinates. The output is a singel rgba value. Not sure here either, bur for me it sounds like the pixel shader is run for every pixel. If that is so, it probably uses a lot of power to do so. I have heard rumours that the next Unreal 3 engine, is going to do that on everything. Might be pretty..



    This is what I got so far. Never written my own shader yet. But when I have finished my exams in 1,5 weeks, I will be all over it. So any questions or comments are accepted now. I know a lot more about it. But it would probably cover 20 more posts. So if there is some spesific questions then bring them on.

    ØØ

  6. #6

    Thread Starter
    Ex-Super Mod'rater Electroman's Avatar
    Join Date
    Sep 2000
    Location
    Newcastle, England
    Posts
    4,349
    Cool , lots of nice information here, I'll be sure to check it out over the summer and if I get time I'll probably buy a book about it .
    When your thread has been resolved please edit the original post in the thread ()
    and amend "-[RESOLVED]-" to the end of the title and change the icon to , Thank you.

    When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

  7. #7
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    Originally posted by Electroman
    Cool , lots of nice information here, I'll be sure to check it out over the summer and if I get time I'll probably buy a book about it .
    Yeah do that...it's realy the future. The only reason that it's not that usual in games yet is that it is only the DX9 cards, that can realy use it. And there is so few gamers that uses it, so no one wants to use it in big scales for game. But I think it is fun to finaly be in the pointing edge in the graphics community. I feel like I always have been some steps behind when it comes to DX, but now when DX is changing that much, it would be fun to be one of those that starts off using it.

  8. #8
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    Is bump mapping handled on a vertex/pixel level now too with these new technologies?
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  9. #9
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051
    Something that may be of interest:

    http://www.ati.com/developer/gdc/D3D...e2_Shading.pdf
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


  10. #10
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    Originally posted by Cander
    Is bump mapping handled on a vertex/pixel level now too with these new technologies?

    Yeah...

    And here I will try to make an example of Dot-3 Bump Mapping, since it is the most common one.


    Code:
    //Dot-3 Bump Mapping
    
    //Input:
    //v0: Vertex position
    //v3: The normal
    //v7: Texture coordinates
    
    //Texture wrapping set to TRUE
    
    
    vs.1.0             //Shader version 1.0
    
    //emit transformed position
    m4x4 pPos, v0, c[TRANS_MVP]
    
    //Transform normal and tangent
    m3x3 r7, v8, c0
    m3x3 r8, v3, c0
    
    //Cross product
    mul r0, -r7.zxyw, r8.yzxw
    mad r5, -r7.yzxw, r8.zxyw, -r0
    
    //Transform the light vector
    dp3 r6.x, r7, -c16
    dp3 r6.y, r5, -c16
    dp3 r6.z, r8, -c16
    
    //Multiply by a half to bias, then add half
    mad r6.xyz, r6.xyz, c20, c20
    
    mov oT0.xy, v7.xy
    mov oT1.xy, v7.xy
    mov oD0.xyz, r6.xyz
    And then the pixel shader.

    Code:
    ps.1.1    //Shader version 1.1
    
    tex t0    //Sample texture
    tex t1    //Sample normal
    
    mov r0, t1
    
    //Dot(light, normal)
    dp3 r0, t1_bx2, v0_bx2
    
    //Modulate against base color
    mul r0, t0, r0

    Think that should do it. HAvn't tested it.....:

  11. #11
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    All I can say is....***?

    ASM style syntax for shader creation?
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  12. #12
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    Originally posted by Cander
    All I can say is....***?

    ASM style syntax for shader creation?

    Yeah as I wrote in one of the posts furuther up. The Shader language was ASM look alike. When DX9 came, things chagnged, and you got the HLSL (High level shader language), it is a C look alike syntax.


    At the moment I know of about 3 high level shader languages.

    NVIDIA has Cg
    OpenGl has a Shading language
    And ATI is talking about some GLSH and some AHLSL, but I am not 100% into this yet. The whole thing is a bit messy at the moment. But it sure works tho'..... The only thing they agree to, is that making it difficult is the worst thing that can happen. So it will be easier for every day. And there is new versions of the shader tools comming out all the time. And the high level languages looks more or less the same. So I don't think it will be all that messy when you get down to it. But the first man that tries it out here, are welcome to have their say about it.

  13. #13

    Thread Starter
    Ex-Super Mod'rater Electroman's Avatar
    Join Date
    Sep 2000
    Location
    Newcastle, England
    Posts
    4,349
    Posted by Cander
    All I can say is....***?

    ASM style syntax for shader creation?
    There is also a HLSL (High Level Shader Language) which is meant to be C style but I've never seen any of this, only ever the ASM style .

    I think I definitly need to get a book to learn all this new stuff though .
    When your thread has been resolved please edit the original post in the thread ()
    and amend "-[RESOLVED]-" to the end of the title and change the icon to , Thank you.

    When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

  14. #14
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    Originally posted by Electroman
    There is also a HLSL (High Level Shader Language) which is meant to be C style but I've never seen any of this, only ever the ASM style .

    I think I definitly need to get a book to learn all this new stuff though .

    Now your posts looks dumb...

  15. #15

    Thread Starter
    Ex-Super Mod'rater Electroman's Avatar
    Join Date
    Sep 2000
    Location
    Newcastle, England
    Posts
    4,349
    Posted by NoteMe
    Now your posts looks dumb...
    Not if I delete yours .
    When your thread has been resolved please edit the original post in the thread ()
    and amend "-[RESOLVED]-" to the end of the title and change the icon to , Thank you.

    When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

  16. #16
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    Yeah.. I need books. Im just used to creating shaders graphically via Maya. Drag and drop...
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  17. #17
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    Originally posted by Cander
    Yeah.. I need books. Im just used to creating shaders graphically via Maya. Drag and drop...

    Hehe...don't go easy on it...this is supposed to be hard...if you ever buy a book I have heard that the ShaderX books are great. I don't have them yet, but I read the Real Time Shader Programming book from Ron Fosner (He is a great man), but I think that one is starting to get a bit outdated. Doesn't provide any HLSL code at all. But not sure how many books actualy have that.

    But there is a lot of math and physics to know to write shaders. Thats my biggest problem at the moment.

    Like Blin Phongs iluminations and so on...

  18. #18

    Thread Starter
    Ex-Super Mod'rater Electroman's Avatar
    Join Date
    Sep 2000
    Location
    Newcastle, England
    Posts
    4,349
    Sounds good but I think I would preffer to do it with just ASM, you get to know whats what that way. Plus it will be platform independant, you don't know if the HLSL's work on consoles do you? I would assume the ASM style bits are the same but I would only be guessing that the HLSL's will be compatible .
    When your thread has been resolved please edit the original post in the thread ()
    and amend "-[RESOLVED]-" to the end of the title and change the icon to , Thank you.

    When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

  19. #19
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    Are the DX shader languages graphic card brand specific. Or are they just made to interface directly to DX?
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  20. #20
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    Originally posted by Cander
    Are the DX shader languages graphic card brand specific. Or are they just made to interface directly to DX?
    If a card has VS 1.0 and PS 1.0 and you only use the instructions from that version, and the other limits the version have, then it will work.

    If you write it in a HLSL it will still be asembled to ASM code, so the GPU can read it. And the instructions used are of a certain version.

    Like I have a ATI Radeon 9800 PRO card, it is a Full DX9 supported card. Since DX9 is up to VS2.0 and VS1.0 then my card can handle that.

    When you buy a new card and it sais that supporst DX8 or DX9 then you probably have some PS and VS in the hardware, but as with all distributions of DX and the following cards, not all of them can handle it all. So some functions in DX might be missing on diffrent cards. Thats why you have the CAPS in DX, so you can test to see if a card has the specific instruction set.


    This was a reather messy post, so if you didn't get it, ask again..

  21. #21
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    No I got it. Im not totally retarded to this stuff. Just behind the times really.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  22. #22
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    Originally posted by Cander
    No I got it. Im not totally retarded to this stuff. Just behind the times really.

    I am a retard when it is comming to explaining things in English. You shouldn't think that I was a Java toughter in my spare time...


    I am just glad to help. Keep me posted if there was anything else I can teach away about shaders.

  23. #23
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    Thanks a bunch.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  24. #24
    Fanatic Member
    Join Date
    Jan 2003
    Posts
    1,004
    I think that OpenGL 2.0 has shader support to it.
    "Can't" and "shouldn't" are two totally separate things.

    All questions should be answered. All answers should be true. That is why I post.

  25. #25
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    Originally posted by Darkwraith
    I think that OpenGL 2.0 has shader support to it.
    Is OGL 2.0 out yet? I thought that 1.5 was the last release. But I am not that into OGL anyway.

    But yes, OGL will or all ready have Shader suport. And it hopefully will or is the same syntax.

  26. #26
    Fanatic Member
    Join Date
    Jan 2003
    Posts
    1,004
    OpenGL Shading Language

    OpenGL 2.0

    I think it is in the process of being created...
    "Can't" and "shouldn't" are two totally separate things.

    All questions should be answered. All answers should be true. That is why I post.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width