Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 20 May 2009
Offline Last Active Aug 09 2014 12:02 PM

Topics I've Started

Framebuffer Artifacts

30 August 2012 - 08:27 PM

I am getting odd artifacts when displaying scaled-up textured quads, see attached for screenshot. The vertical bars are good, the small horizontal "ticks" are the artifacts.

What you are looking at is just a single 8x8 textured quad drawn multiple times on a non-overlapping grid, the original texture source is a 2 pixel wide vertical line. The artifacts only appear when scaling up (resizing the render target), and each time I resize the ticks sort of randomly appear and disappear. Perhaps significant, the artifacts seem to always appear at where the quads adjoin each other.

Multisampling is off, not using depth or alpha blending. Vertices in the Pre-vs mesh look correct.

The strangeness starts when I debug one of the culprit pixels with PIX - it reports the pixel shader ouput and framebuffer as 1,1,1,1 which is what I am seeing on the screen. But, when I debug pixel & step through the actual shader, the output shows 0,0,0,1 (which would be what I want to see on the screen). I do not understand what could happen between the pixel shader output and the framebuffer that can change the color of the pixel.

To add to the strangeness, I cannot reproduce the issue on a different computer. I've updated my drivers on my development machine to the latest, no change. My best guess at this point is that I am doing something a bit off that is compounded by a particular quirk of my GPU (Nvidia, btw).

Here is some code (using SharpDX, Direct3D11):

Swapchain and Rasterizer options:
swapDesc = new SwapChainDescription()
				ModeDescription = new ModeDescription(ParentForm.ClientSize.Width,
					new Rational(60, 1), Format.R8G8B8A8_UNorm),
				SampleDescription = MultiSampling,
				Usage = Usage.RenderTargetOutput,
				BufferCount = 1,
				OutputHandle = ParentForm.Handle,
				IsWindowed = true,
				SwapEffect = SwapEffect.Discard,
				Flags = SwapChainFlags.None

var rasterDesc = new RasterizerStateDescription()
				IsAntialiasedLineEnabled = false,
				CullMode = CullMode.None,
				DepthBias = 0,
				DepthBiasClamp = 0.0f,
				IsDepthClipEnabled = false,
				FillMode = FillMode.Solid,
				IsFrontCounterClockwise = false,
				IsMultisampleEnabled = enableMultiSample,
				IsScissorEnabled = false,
				SlopeScaledDepthBias = 0.0f

This gets called when the window is resized, width and height are directly from Form.ClientSize:

swapChain.ResizeBuffers(1, width,
				Format.R8G8B8A8_UNorm, SwapChainFlags.None);
using (Texture2D backBuffer = swapChain.GetBackBuffer<Texture2D>(0))
				renderTargetView = ToDispose(new RenderTargetView(device, backBuffer));
device.ImmediateContext.Rasterizer.SetViewport(0, 0, width, height, 0, 1);

The sampler state used by the pixel shader, (which btw I have tried randomly tweaking settings out of desperation):
SamplerStateDescription samplerDesc = new SamplerStateDescription()
				AddressU = TextureAddressMode.Border,
				AddressV = TextureAddressMode.Border,
				AddressW = TextureAddressMode.Border,
				MipLodBias = 0,
				MaximumAnisotropy = 1,
				Filter = Filter.MinMagMipPoint,
				ComparisonFunction = Comparison.NotEqual,
				BorderColor = new Color4(0,0,0,0),
				MinimumLod = 0,
				MaximumLod = float.MaxValue

Finally, here is the pixel shader. This is maybe a bit unusual, but basically it is just using the alpha from a texture to lerp between 2 colors:

Texture2D shaderTexture;
SamplerState sampleType;
struct PixelIn
	float4 PosH : SV_POSITION;
	float3 BColor : COLOR0;
	float3 FColor : COLOR1;
	float2 Tex : TEXCOORD;
float4 PS(PixelIn pin) : SV_TARGET
	float4 textureColor;
	float3 finalColor;
	textureColor = shaderTexture.Sample(sampleType, pin.Tex);
	finalColor = lerp(pin.BColor, pin.FColor, textureColor.a);
	return float4(finalColor, 1.0f);

Anyone have any ideas, even a longshot, or has anyone seen anything like this before?

Debugging (managed) DX11

14 August 2012 - 10:19 PM

Learning DX11 through SharpDX, but the process is made rather painful by the fact that Visual Express appearently does not support unmanaged debugging.

Are there any workarounds, 3rd party tools, hacks etc. that anyone knows of to get around this, or am I just out of luck unless I bite the bullet and throw down $$$ for a full version of VS?

Pattern/Idiom for Simplifying Interface

15 April 2012 - 02:48 PM

I'm doing some refactoring of a Winforms app, and a particular piece of code doesn't smell right to me. I have a custom control class (call it Canvas), on which a number of Tools can act on it (typical drawing tools such as paint, line, fill, etc.)

Since the Canvas class has grown rather heavy (both in size and public interface), I thought I'd seperate out each tool into a seperate class, which interacts with Canvas directly. Each Tool object is notified of relevent input messages, and communicates back to the Canvas in order to draw, save state for undo, query any necessary data, etc. To do this, each Tool stores a reference to Canvas, and vice versa.

Since Tool needs to communicate with Canvas (and vice versa), it can only do so through public methods on Canvas. Thus, the public Canvas interface isn't getting any smaller/simpler as I'd hoped, although it now has a manageable footprint at least.

To generalize, if I have a class A which the client (application) interacts with, and a class B which interacts only with A (to handle logic related to A), how do I provide an interface on A for B to use that is not exposed to the client?

The obvious answer is to seperate out A and B into its own assembly, make B an internal class, and add internal methods to A for B to call. I've also thought about hooking into events exposed by B, but I'm not sure this is the ideal use for events.

So I'm wondering if I'm missing something obvious here, a better way, or at least an alternative to seperate assemblies?

Then again, maybe I'm over-thinking things as I sometimes do...

Thanks for any suggestions.

Earley Parser

11 March 2012 - 10:20 PM

I'm trying to implement an Earley parser (in C#), as described here: http://en.wikipedia....i/Earley_parser.

Unfortunately, parser theory is far beyond my comfortable knowledge zone, so I'm wondering if anyone here has done something like this before.

I've managed to put together a working recognizer (which is basically what the linked algorithm describes), and it seems to produce the charts accurately. Where I'm coming up short is how to translate the chart into a parse tree (or forest, since I'll eventually be working with ambiguous grammars).

My searching has revealed mostly thesis papers and such, which are beyond my understanding. If anyone has a good link or other recommendation that would help, please share. Worse case, I suppose I can purchase a book on compiler/parser theory, and start self-teaching, but at the moment this looks rather daunting - I'd also certainly appreciate any book suggestions of the sort that can be considered "accessible".


Fitting Rectangles

07 February 2011 - 12:25 AM

I'm trying to find an algorithm to fit a predefined rectangle in a grid (2D array), where the rectangle does not intersect any cells marked as "blocked." For example, below is a grid of empty (white) and blocked (blue) cells. One solution for fitting a 3x3 rectangle is shown in red.

Posted Image

The following assumptions hold:
1. The grids can be various sizes, but are always rectangular with borders (no wrapping)
2. The grid may be filled with "blocked" cells randomly, and may be sparse or dense.
3. It only needs to be reasonably time efficient (will not be per-frame)
4. It does not need to be perfect (guaranteed to find a solution), but it should find most (with a time-out or other cheat to halt the algorithm)

I've come up with the following two methods (in concept, not in code):
1. Randomly choose (or enumerate through) empty cells and try and fit the rectangle there. Cells can be flagged as they are checked to reduce repeat checks. I'm not sure, however, how to do the fit-check step, except the naive way of trying every combination.
2. Some form of "falling block" process, where rectangles are moved inward from the edges until colliding with a blocked cell. Some sort of provision would have to be made to check interior voids in the grid.

Out of these, #1 seems the possible better solution (and it seems like it would even find all solutions?). However, I'm sure this is a solved problem, so I figured I should give it some research. Unfortunately, I don't really know what keywords to search for.

Can anyone point me in a direction, or other ideas to try?