Jump to content
  • Advertisement
Sign in to follow this  
swordyijian

problems of shader

This topic is 3917 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 have a problem. in my shader, i created a float Global variable, then after calculating, how can i get the variable value in my program. i found myEffect->GetFloat() is not working. it seems the global variable can not change value

Share this post


Link to post
Share on other sites
Advertisement
You can have your shader write the value to a texture which is set as the render target.

Share this post


Link to post
Share on other sites
The values of variables in a shader are not available to the main program. If you want to calculate something in your shader and feed those results back to the main program, you have to write your data to a texture (render target).

Locking a render target is an expensive operation. If you want to do this many times per frame, perhaps you should rethink your algorithm. If you explain what it is you are trying to accomplish, perhaps people can suggest more efficient ways of doing it.

neneboricua

Share this post


Link to post
Share on other sites
Thanks for replying. I just found a render target texture can not be locked. My purpose is to get a object's smallest depth value, then i can sort all objects by depth value.

Share this post


Link to post
Share on other sites
You're right. A render target cannot be locked. The way around it (and the reason why doing things this way can be expensive) is because you have to copy the contents of the render target to a system memory texture. You can lock the system memory texture and then read your data. Copying from video to system memory is not cheap and should not be done on any performance-critical path.

If you're trying to sort objects by depth, there are less expensive ways to do it. One way is to compute some sort of bounding volume on each object (like a sphere) and then figure out the intersection point on the sphere between your view position and the sphere center. Another way would be to just take the middle of each object as that objects position. Either way, you can use these points to sort the objects without reading data from video memory.

This wouldn't be 100% accurate but it might be close enough. That's what game programming is all about; as long as it looks good, it doesn't have to be TOTALLY accurate :)

neneboricua.

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!