Shader behaves differently in every API

  • Daodan
  • Topic Author
More
5 years 9 months ago - 5 years 9 months ago #1 by Daodan Shader behaves differently in every API was created by Daodan
I just wrote a shader that uses tex2Dfetch() in order to give the game a pixelated look.
Now the issue is that this shader behaves differently in every API (D3D9, D3D11, OGL).
  • D3D9: No issue
  • D3D11: Image shrinks to the top left screen corner with increasing mip level (while it is noticeable that it gets pixelated and not only smaller)
  • OGL: Values for the mip level greater than 0 equal to a black screen

Warning: Spoiler!


Any ideas why that is?
Last edit: 5 years 9 months ago by Daodan.

Please Log in or Create an account to join the conversation.

  • crosire
More
5 years 9 months ago #2 by crosire Replied by crosire on topic Shader behaves differently in every API
There is a logical error in your code. Every mipmaps is a power of two smaller than the previous one, not linearly so. To get the result you want the code should be:
return tex2Dfetch(samplerMipmap, int4(floor(vpos.xy / exp2(iUIMiplevel)), 0, iUIMiplevel)).rgb;

Funny enough I made the same mistake in the D3D9 implementation of tex2Dfetch. Which is why it "worked", when it should not have. It's fixed now: github.com/crosire/reshade/commit/e1ae7c...282b6d7319d307eab464 .
The OpenGL implementation is hard to fix. It needs to flip the Y coordinate, but that's only trivial if the input coordinates are guaranteed to go all the way from 0 to texture height. Which is not the case with your shader. Which is why it fails. Can't think of a good way to fix this unfortunately.
The following user(s) said Thank You: Daodan

Please Log in or Create an account to join the conversation.

  • Daodan
  • Topic Author
More
5 years 9 months ago #3 by Daodan Replied by Daodan on topic Shader behaves differently in every API
Ah, ok. I totally forgot that with the power of two. Thanks.
But at least a bug got fixed!

Please Log in or Create an account to join the conversation.

We use cookies
We use cookies on our website. Some of them are essential for the operation of the forum. You can decide for yourself whether you want to allow cookies or not. Please note that if you reject them, you may not be able to use all the functionalities of the site.