• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Alex-DE-74

DirectX11/SharpDX: How to disable mip-mapping (and scalig) for (multipass) pixel shaders to access exact bitmap pixel values?

6 posts in this topic

Dear DirectX11/SharpDX developer, dear community members,
 
first of all many thanks for this very impressive project.
 
Because of many troubles with WPF Shader Model (no vertex shader, no multipass, etc, etc) I've switched to use DirectX and SharpDX is only a managed wrapper of my choose.
 
For a first exercise I've tried to draw a simple (unscaled) image which is succeeded with DrawBitmap. The image was drawn exactly same as used bitmap. Only if I resize the window, the image also will be resized. Need to resize swap chain?
 
For the next I've tried to do exactly the same, but switch in a little Pixel Shader and after a day I've understand that is only possible only if I have Vertex Shader too. Maybe some enhancement can be made?
 
A get two possibilities: use triangle list / triangle strip OR use quad vertex shader as described here [1]
 
PS_IN VSQuad(uint VertexID: SV_VertexID)
{
 // ouputs a full screen quad with tex coords
 PS_IN Out;
 Out.tex = float2( (VertexID << 1) & 2, VertexID & 2 );
 Out.pos = float4( Out.tex * float2( 2.0f, -2.0f ) + float2( -1.0f, 1.0f), 0.0f, 1.0f );
 return Out;
}
and setup the bitmap as texture in pixel shader resource.
 
Test pixel shader looks like:
 
Texture2D picture;
SamplerState pictureSampler;

float4 PS( PS_IN input ) : SV_Target
{
  // Simple invert each color channel value
  float4 color = picture.Sample(pictureSampler, input.tex);
  float4 ret;
  ret.xyz=1-color.xyz;
  ret.a=1.0;
  return ret;
}
 
But for now I've two problems:
the first one the texture is (of course) not drawn in original size but in window size and resizes with window. I hope, I only need to update swap chain size to prevent resizing. But how to generate a quad of correctly size whis is exactly of my bitmap (texture size)?
 
The next problem: all interpolation between pixels must be prevented in pixel shader because of exactly pixel values (and neighbor pixels) must be accessed. Accordingly to MS the Mip-Mapping must be disabled, but there are not "NONE" (DISABLED) value of Filter enumeration. So it looks to be impossible to get exactly pixel values or I've missed something?
 
What I try to do in the end:
this should be two pass pixel shader:
1st stage zoom (with own algorithm) (in or out) a particular 2D-region of smaller/bigger image
2nd stage does some kernel filtering of zoomed region
 
P.S. The images to rasterize will be continuosly (and at high frame rate) updated from an observation camera.
 
Here [2] is a little bit more explanation, which I try to achieve.
 
This sounds very easy, but I've don't found an example (neither SharpDX nor WPF) how to do this correctly, mainly because all examples does only filter and not rescale an input image and does not need an access to exactly pixel values. My problem is, there are some artifacts, if not exactly pixel values will be used by zoom algorithms.
 
It will be really very helpful for me, if somebody can explain, how to do this "simple" thing or enhance SharpDX Sample library.
 
Many, many thanks in advice.
 
Alexander Landa
 
 
0

Share this post


Link to post
Share on other sites

Exactly - I don't want any mipmapping, any interpolation, no other "magic" transformation.

What I want is access to my original pixel (and surrounding) pixels inside my pixel shader(s).

 

Hereis what I doing in my C# code (with SharpDX):

 

            texture = Texture2D.FromFile<Texture2D>(Device, "sharpdx.png");
            textureView = new ShaderResourceView(Device, texture);
            sampler = new SamplerState(Device, new SamplerStateDescription()
           {
               Filter = Filter.MinMagMipLinear,
               AddressU = TextureAddressMode.Wrap,
               AddressV = TextureAddressMode.Wrap,
               AddressW = TextureAddressMode.Wrap,
               BorderColor = Color.Black,
               ComparisonFunction = Comparison.Never,
               MaximumAnisotropy = 16,
               MipLodBias = 0,
               MinimumLod = 0,
               MaximumLod = 16,         
           });


            // Compile Vertex and Pixel shaders
            vertexShaderByteCode = ShaderBytecode.CompileFromFile("ColorInvert.fx", "VSQuad", "vs_4_0", ShaderFlags.None, EffectFlags.None);
            vertexShader = new VertexShader(Device, vertexShaderByteCode);
            
            pixelShaderByteCode = ShaderBytecode.CompileFromFile("ColorInvert.fx", "PS", "ps_4_0");
            pixelShader = new PixelShader(Device, pixelShaderByteCode);


            // Prepare All the stages
            Context.InputAssembler.InputLayout = null;
            Context.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;
            Context.VertexShader.Set(vertexShader);
            


            Context.Rasterizer.SetViewport(new Viewport(0, 0, 800, 600, 0.0f, 1.0f)); // This seems does not change anything, can be removed
            
            Context.PixelShader.Set(pixelShader);
            Context.PixelShader.SetSampler(0, sampler);
            Context.PixelShader.SetShaderResource(0, textureView);
            Context.OutputMerger.SetTargets(BackBufferView);

Where to set mipmaps to 1?

And how to address a not interpolated value in pixel shader?

 

Many thanks,

Alex

Edited by Alex-DE-74
0

Share this post


Link to post
Share on other sites

If you just want to load pixels directly, with no sampling, no interpolation, no mipmapping, etc then instead of this:

 

float4 color = picture.Sample(pictureSampler, input.tex);

 

Use this:

 

float4 color = picture.Load(input.tex);

 

Note that for this to work, input.tex should be an int3 instead of a float2, and be in the range 0...texturesize, not 0...1.

1

Share this post


Link to post
Share on other sites

mhagain, many thanks! I will try to use this route.

Now I must see, how to generate tex-coordinates in other type domain.

By the way, linked MS page say it's int2 for Texture2D (which I use) and int3 for Texture2DArray. My texture is simple 2D texture, so why and how to use int3 coordinates?

 

And it's only supported by HLSL Shader Model 4, which is now usable within SharpDX but not WPF, also moving froWPF to SharpDX seems to be the right direction :)

0

Share this post


Link to post
Share on other sites
By the way, linked MS page say it's int2 for Texture2D (which I use) and int3 for Texture2DArray. My texture is simple 2D texture, so why and how to use int3 coordinates?

 

You're right; my mistake.

0

Share this post


Link to post
Share on other sites

 

By the way, linked MS page say it's int2 for Texture2D (which I use) and int3 for Texture2DArray. My texture is simple 2D texture, so why and how to use int3 coordinates?

 

You're right; my mistake.

 

 

You're correct, it's int3 for Location and Int2 for offset, I've overlooked this. But maybe I can use int2 Offset paramter as X/Y texture offset. So in the sum it maybe equivalent.

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0