Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!

1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Member Since 07 Mar 2005
Offline Last Active Today, 05:31 AM

#5226083 sfml health bar

Posted by marcjulian on 28 April 2015 - 09:20 AM

What you're hitting is that you (very likely) hit the classic first time problem of integer division.

The SFML setScale() method accepts a floating point value - but if your m_playerHealth and maxHealth values are of integral type this will basically only return 0 if m_playerHealth < maxHealth and 1 otherwise.


To fix this you can simply cast one of the values (or both) before doing the division to a floating point value.

healthBarSprite.setScale(static_cast<float>(m_playerHealth) / maxHealth, 1);

This should fix it - beware that of course the floating point values may not be 100% exactly the same as your integer values but for your UI it should totally be fine ;)

#5174293 Compute shader values

Posted by marcjulian on 17 August 2014 - 11:46 AM

Once you've written your computation results to a buffer (or texture) you can Map() the buffer/texture and read back the results.

Note that for some resource types (depending on the creation flags) you may first need to copy your results to a staging resource and then Map() this intermediate resource.


This link (even though for DX10) contains some pointers to related topics: http://msdn.microsoft.com/en-us/library/windows/desktop/bb205132(v=vs.85).aspx


One thing to keep in mind: If you read back the results in the same frame as the computation happens you will probably introduce stalls in your CPU-GPU communication which can lead to performance problems. So wait at least a frame before reading back data. Even better would be to issue a query after your Dispatch() call and then asynchronously ask DirectX if the query is finished so you know your computation you did before is finished as well.

#5167765 Vertex Shader responsabilities if I have Tessellation Shader

Posted by marcjulian on 19 July 2014 - 05:41 AM

It helps to think of the shader pipeline as a set of refinement steps in my experience.


The earlier you can calculate something in the pipeline the cheaper it usually is (barring interpolator costs etc. so caveat empor).


If you have a calculation you can do in the vertex shader because it affects all triangle emitted by the tesselation the same then do it there instead of in the tesselation stage.

One example would be shader based skinning. Usually your vertices are affected by the bones and all tesselation generated triangles move the same based on the "basis" triangle coming from the vertex shader stage. This would speak for performing the skinning calculations in the vertex shader as it is called less often (and you benefit from the vertex reuse cache as well).


It always depends on what exactly you want to achieve. For example your vertex shader can transform all vertices to world space and then your tesselation stuff can do it's operation in world space. If on the other hand you have some calculation which needs to happen in object space (in the tesselation stage) you need to move the transform step further back.


The usual implementations I have seen have used world space for most operations after the vertex shader so it was safe to have TBN calculations etc. in the vertex shader stage. Often you can also find transformations to move your problem between the stages even if it doesn't look like that first.