Welcome, Guest.
Username: Password: Remember me

TOPIC: Shader behaves differently in every API

Shader behaves differently in every API 2 months 1 week ago #1

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! [ Click to expand ]


Any ideas why that is?
Last Edit: 2 months 1 week ago by Daodan.
The administrator has disabled public write access.

Shader behaves differently in every API 2 months 1 week ago #2

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.
Cheers, crosire =)
The administrator has disabled public write access.
The following user(s) said Thank You: Daodan

Shader behaves differently in every API 2 months 1 week ago #3

Ah, ok. I totally forgot that with the power of two. Thanks.
But at least a bug got fixed!
The administrator has disabled public write access.