Jump to content
  • Advertisement
Sign in to follow this  
Winegums

CG Shader Fragment

This topic is 4230 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I've recently looked at the Nehe CG Shader tutorial and am really keen on using them in my terrain i'm currently programming. I'm hopeing to be able to blend textures and calculate and apply normals using the shader. So I'm looking through the documentation that came with the Cg toolkit...the word 'fragment' keeps turning up, as it did in the nehe tutorial. Can anyone tell me what a fragment shader is? As far as i knew you had pixel and vertex and that was your lot (well, i hear murmours about 'primitive' shaders...). EDIT: i've done a bit more work now. from what i can see are fragment shaders basically pixel shaders? also...how do you know if you're using a shader or not? i mean, from what i see you sorta enable them around your draw code, but how do you know if they're actually doing anything or just looking pretty? i suppose when you're doing more complex operations it might be more obvious, but just drawing lines and texturing it's hard to tell. thanks for your time. [Edited by - Winegums on March 24, 2007 8:20:29 PM]

Share this post


Link to post
Share on other sites
Advertisement
A fragment shader is analogous to a pixel shader. A fragment can sometimes mean more than just a pixel color. For example, other pixel attributes such as depth or something. There's no inherent difference between a pixel and fragment shader though.

Have you started using shaders to replace the fixed function pipeline yet? If so, all you need to do is return some random color for the final pixel value in the shader to see if it's working. I like to use pink (float4(1,0,1,1)) but that's just me. Since you probably didn't put in any non-shader code that draws things pink, it has to be the shader doing it.

Share this post


Link to post
Share on other sites
Quote:
Original post by Winegums
also...how do you know if you're using a shader or not? i mean, from what i see you sorta enable them around your draw code, but how do you know if they're actually doing anything or just looking pretty?

Usually, it's very obvious if the shader programs are executed and actually do something, because if they are executed and don't do anything (only pass on the vertices/normals/colors that are sent from OpenGL), the scene will probably not be visible. That's because the model and view transformations of the vertices/normals have to be made in the vertex program, as well as the projection to the clip space. If that's not done very few vertices/triangles will end up in clip space and be rasterized to the display.

Quote:
Original post by stanlo
Have you started using shaders to replace the fixed function pipeline yet? If so, all you need to do is return some random color for the final pixel value in the shader to see if it's working. I like to use pink (float4(1,0,1,1)) but that's just me. Since you probably didn't put in any non-shader code that draws things pink, it has to be the shader doing it.

I agree, usually any color that's mean to the eyes is good for checking if the shader works [grin], also normals are often visualized by using the (x, y, z)-vector as the (r, g, b) output color.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!