Jump to content
  • Advertisement
Sign in to follow this  
Lunpa

Cg Samplers

This topic is 2947 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

I want to synthesize a texture in the vertex shader, and then pass the resulting sampler to the fragment shader. Is it possible to modify a sampler it some fashion like a per-pixel modification; in a vertex shader? Or are samplers pretty much read-only?

Essentially, I want to stencil an outline onto a blank sampler in a loop; and then in a second loop, fill in the shape.


Also, I'm working in Cg, if that is important; but really the same question holds for GLSL, too.

Share this post


Link to post
Share on other sites
Advertisement
Unless I miss a feature, you can't. You can read pixels, but you can't write them back. Neither can you pass a sampler from a vertex shader towards a fragment shader. Textures are just set active in one of the (16?) working "slots" by OpenGL, Direct3D or another API.

The way to generate textures via shaders is usually by:
- create a "Render Target" / FBO. Like you can draw towards your screen, you can also draw onto textures.
- Activate the Render Target (instead of giving output to the screen buffer). Now everything you render will be "drawed" onto that texture.
- Example, render a screen filling quad. Let the fragment shader do the pixel math. Or just render a bunch of dots and let the CPU decide the colors. Colors can be interpretated as positions, normals, depth data, and so on.
- When you are done, disable the render target. The texture you just produced can be used like any other texture, and eventually be processed further in other fragment shaders.

Should be plenty of tutorials covering this stuff, as many effects are using render targets.

Rick

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!