• 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
Plerion

Pixel shader executing wrong

3 posts in this topic

Hi everyone

Im coming here with a very strange problem. When im drawing rectangles i get strange artifacts along the adjacent edge of the two triangles im rendering.

As an example:
If im using a triangle fan with the following vertices:
0 1

3 2

I get artifacts at 0 and 2 as the edge of the two triangles is between 0 and 2, if im using a trianglelist with:
0 1 2
0 2 3

i get the same result (as expected).

If i make the triangle list the following:
0 1 3
1 2 3

i get artifacts at 1 and 3.

So what do i mean with artifacts? I have a little picture which shows them pretty well (its for triangle fan):
[img]http://imagr.eu/up/509458b04c4de7_fragment.png[/img]

The pink makes it more clear.

Now i was using PIX to debug my shader. There i found several very odd behaviours.

My shader was looking like that:
[source lang="cpp"]void PixelMain(in PixelShaderInput input, out float4 color : COLOR0)
{
float strokeX = strokeWidth.x / elementSize.x;
float strokeY = strokeWidth.x / elementSize.y;
float2 tex = input.texCoord;

if(tex.x <= strokeX || tex.y <= strokeY || (tex.x + strokeX) >= 1 || (tex.y + strokeY) >= 1)
color = tex2D(brushSampler, tex);
else
color = float4(1.0f, 0.35f, 0.7f, 1.0f);
}[/source]
In PIX i used single step debugging one of the two pixels with the artifacts and it showed me that my if-condition is met and it reads from the texture the correct value [b]and then also executes the else-block[/b] writing the pink to the color. What the hell?

I thought it may be a source/asm mismatch and stepped through the bytecode which was like
[code]
if_ne r0.x, -r0.x
texld r1, v0, s0
else
mov r1, c2
endif
[/code]

There again, it checks the if, it executes the texld and then executes also the mov r1, c2. Graphics card, what r u doin? Graphics card... staph!! [img]http://public.gamedev.net//public/style_emoticons/default/biggrin.png[/img]

No matter to what i change my shader it also finds a way to bypass it so that for that pixel the pink is written. For example i did this:
[source lang="cpp"]void PixelMain(in PixelShaderInput input, out float4 color : COLOR0)
{
float strokeX = strokeWidth.x / elementSize.x;
float strokeY = strokeWidth.x / elementSize.y;
float2 tex = input.texCoord;
float2 pos = tex * elementSize.xy;
float2 posEnd = (float2(1, 1) - tex) * elementSize.xy;

color = float4(1.0f, 0.35f, 0.7f, 1);

if(tex.x <= strokeX)
color = tex2D(brushSampler, tex);
if(tex.y <= strokeY)
color = tex2D(brushSampler, tex);
if((tex.x + strokeX) >= 1)
color = tex2D(brushSampler, tex);
if((tex.y + strokeY) >= 1)
color = tex2D(brushSampler, tex);
}[/source]
I checked the values and saw that the first if must fail but the second is true while the rest is false. So far so good, first if failed, second if didnt, it executed the following byte code:
texld r1, v0, s0

Before the call r1 was: 1.0f, 0.35f, 0.7f, 1 (as expected)
After the call r1 was: 1.0f, 0.35f, 0.7f, 1 (NOT as expected, there is absolutely no pink in my brush!

What am i doing wrong? Is my graphics card fooling around with my? Why does this happen only at the edges where two triangles are adjacent?

/EDIT:
[b]And to make things even more interesting: This error ONLY occurs on ATI cards, NVIDIA is all fine (except that not all 4 strokes have the same thickness).[/b]

Thanks in advance
Plerion Edited by Plerion
0

Share this post


Link to post
Share on other sites
[quote name='Plerion' timestamp='1351899834' post='4996703']
In PIX i used single step debugging one of the two pixels with the artifacts and it showed me that my if-condition is met and it reads from the texture the correct value and then also executes the else-block writing the pink to the color. What the hell?
[/quote]

That's normal. Generally branches are implemented by executing both branches and lerping the results. This is because several pixels are processed in parallel, and they all need to run in lock-step and execute the same code.

You can explicitly specify dynamic branching by using the branch attribute like MikeBMcL said (and you can't use tex2D, ddx or ddy intrinsics inside the branch)

As for your artifact, it looks like you're using XNA or DX9? If so, are you taking into account the [url="http://drilian.com/2008/11/25/understanding-half-pixel-and-half-texel-offsets/"]half texel offset[/url]when sampling from your texture? Forgetting to do that is often the cause of artifacts along triangle edges. Edited by phil_t
2

Share this post


Link to post
Share on other sites
Thanks you two, i had branching in mind but thought of it in a wrong way, but actually that wasnt the main cause of the artifacts. The problem was indeed the half texel offset and i changed my vertex shader to subtract a half pixel for my screen quads. Artifacts are gone.
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