Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Full sampler state defined in shader is applied, not only set properties #6393

Open
vchelaru opened this issue Jul 29, 2018 · 10 comments
Open
Labels
MGFX Shader compilation tool
Milestone

Comments

@vchelaru
Copy link
Contributor

vchelaru commented Jul 29, 2018

Setting GraphicsDevice.SamplerStates[0] = SamplerState.PointClamp; results in point filtering applied in XNA 4.0 PC, but the same code/shader result in linear filtering in Desktop GL.

To reproduce the bug:

  1. Download https://drive.google.com/file/d/1U-JU5iEKw-fEAXOLDuqDxcjxIDhvTKkU/view?usp=sharing
  2. Unzip the file to a Windows 10 machine (XNA will be required to compare XNA behavior)
  3. Open XnaCompare.sln (located in the root of the unzipped folder)
  4. Run the project
  5. Observe that the rendered quad has point filtering (hard edges between pixels) image
  6. Open DesktopGlShaderTest/DesktopGlShaderTest.sln
  7. Run the project
  8. Observe that the rendered quad has linear filtering (smoothed pixels) image

Note: Both projects use the same shader file, but the shader file is added directly as an XNB file to the DesktopGL project (due to a missing feature of linked files in the content builder). I did try building the shader with the latest dev build of the content pipeline tool - I don't know if the bug is caused by the pipeline tool or MonoGame runtime.

This was tested on a Windows 10 machine with the following hardware:

  • i7-8550U CPU @ 1.80GHz
  • 16.0 GB ram
  • 64 bit OS
  • NVIDIA GeForce 940MX

What version of MonoGame does the bug occur on:

  • MonoGame 3.7.0.1657

What operating system are you using:

  • Windows

What MonoGame platform are you using:

  • DesktopGL, compared against Microsoft XNA 4.0
@harry-cpp
Copy link
Member

I came across something that is probably related to this bug, calling:

_spriteBatch.Begin(samplerState:SamplerState.PointClamp);
_spriteBatch.End();

has an effect on how all future shaders get rendered..

@tomspilman tomspilman added this to the 3.7 Release milestone Jul 29, 2018
@harry-cpp
Copy link
Member

Turns out, some other stuff leak from SpriteBatch besides PointClamp, yikes.

@vchelaru
Copy link
Contributor Author

For what it's worth, in this case I'm not using SpriteBatch anywhere in the project, so...maybe not the same bug?

@Jjagg
Copy link
Contributor

Jjagg commented Jul 30, 2018

@cra0zy SpriteBatch is not supposed to reset graphics state after ending a batch. It doesn't do that in XNA either.

@harry-cpp
Copy link
Member

@cra0zy SpriteBatch is not supposed to reset graphics state after ending a batch. It doesn't do that in XNA either.

Interesting, I never realized that... well at least that explains why the "workaround" is working.

@tomspilman tomspilman modified the milestones: 3.7 Release, 3.8 Release Sep 24, 2018
@Jjagg
Copy link
Contributor

Jjagg commented Oct 8, 2018

I couldn't reproduce the issue. What's likely happening here is the sampler is assigned to another slot than what's expected.

That said the order of samplers sometimes gets messed up when you have multiple of them in an effect. I don't think that issue is actually logged so I'll open a new one.

@Jjagg Jjagg closed this as completed Oct 8, 2018
@Jjagg Jjagg reopened this Oct 8, 2018
@Jjagg
Copy link
Contributor

Jjagg commented Oct 8, 2018

Nope, I was wrong. The issue is actually that we override the sampler state with whatever sampler state is set in the effect file (if any). While XNA only overrides the properties that are set from the effect file, we also override the others with default values. Note that this issue occurs on both DX and DesktopGL.

@vchelaru
Copy link
Contributor Author

vchelaru commented Oct 8, 2018

Thanks for looking into that @Jjagg . I was concerned when you said you couldn't reproduce it, as I have a linked project that reproduces it for me.

@Jjagg
Copy link
Contributor

Jjagg commented Oct 8, 2018

I tested first with a new project which did not set a sampler state in the effect file.

@Jjagg Jjagg changed the title MonoGame DesktopGL does not respect SamplerState.PointClamp in custom shader Full sampler state defined in shader is applied, not only set properties Oct 16, 2018
@Jjagg Jjagg added the MGFX Shader compilation tool label Dec 8, 2018
@harry-cpp harry-cpp modified the milestones: 3.8 Release, 3.9 Release Jun 14, 2020
@mattj1
Copy link

mattj1 commented Apr 4, 2021

I know this is late, but I had a similar issue and I seemed to fix it by rendering everything to a separate target first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
MGFX Shader compilation tool
Projects
None yet
Development

No branches or pull requests

5 participants