Effect pipeline broken?

Forum for plugin, effect and behavior programmers. Please use the Help & Support forum for help using Construct.

Post » Sun Jan 31, 2010 6:33 pm

Before posting to the tracker, I want to make sure that I am not doing anything wrong. I am currently testing for a few effects in mind, but the results are unexpected.

For example, this code:
[code:20hyqrqi]float4 EffectProcess( float2 Tex : TEXCOORD0 ) : COLOR0
{
float4 color = tex2D( foreground, Tex.xy );
float vpos = (Tex.y - boxTop) / pixelHeight;
int test = vpos % 2;
if(test == 0)
color.rgb *= float3(0.5, 0.5, 0.5);

return color;
}[/code:20hyqrqi]

leads to this result in the editor (better look at the original size):

exactly what I expected. Every second line darkened, beginning with the first line. However, when I run the layout or export to exe, I get this result:


How come? Any idea, or should I post to the tracker?
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Sun Jan 31, 2010 9:11 pm

Coordinates in the runtime go from 0 to 1, from top to bottom and from left to right of the screen.

In the Editor, though, this is from the edge of the EDITING WINDOW, not the layout, so effects get different coordinates.

That said, you are testing for an int result of a modulus

so if you were thinking integer pixels
[code:1wmitvxv]vpos=0 -> vpos%2 = 0, darken
vpos=1 -> vpos%2 = 1, ignore
vpos=2 -> vpos%2 = 0, darken
vpos=3 -> vpos%2 = 0, ignore[/code:1wmitvxv]

but the shader is fractional
[code:1wmitvxv]
vpos=0 -> vpos%2 = 0, darken
vpos=0.3 -> vpos%2 = 0.3, ignore
vpos=0.7-> vpos%2 = 0.7, ignore
vpos=1 -> vpos%2 = 1, ignore
vpos=1.2 -> vpos%2 = 1.2, ignore
vpos=1.7 -> vpos%2 = 1.7, ignore
vpos=2 -> vpos%2 = 0, darken[/code:1wmitvxv]

As you can see, depending on the size in pixels the effect will look very different.

I recommend the following test instead
[code:1wmitvxv]if(vpos%2 > 1)[/code:1wmitvxv]
ALL THAT SAID.... yeah, the diagonal line shouldn't be there at all, and the scanlining should be regular, so yeah it looks like a bug in effect coordinates.....

MORE TESTING REVEALS that this effect only happens when there's more scanlines than physically possible (half the vertical resolution). Why? no idea, but while testing, I ended up writing a full scanlines shader, so here it is.

EDIT: Posted as addon: [url:1wmitvxv]http://www.scirra.com/forum/viewtopic.php?f=29&t=5643[/url:1wmitvxv]
you may change number of shown scanlines, scanline width and intensity of the effect. No offset, because I didn't feel like it.
B
3
S
2
G
4
Posts: 1,445
Reputation: 4,665

Post » Mon Feb 01, 2010 12:36 pm

[quote="madster":35mxhfk7]Coordinates in the runtime go from 0 to 1, from top to bottom and from left to right of the screen.

In the Editor, though, this is from the edge of the EDITING WINDOW, not the layout, so effects get different coordinates.

That said, you are testing for an int result of a modulus

so if you were thinking integer pixels
[code:35mxhfk7]vpos=0 -> vpos%2 = 0, darken
vpos=1 -> vpos%2 = 1, ignore
vpos=2 -> vpos%2 = 0, darken
vpos=3 -> vpos%2 = 0, ignore[/code:35mxhfk7]

but the shader is fractional
[code:35mxhfk7]
vpos=0 -> vpos%2 = 0, darken
vpos=0.3 -> vpos%2 = 0.3, ignore
vpos=0.7-> vpos%2 = 0.7, ignore
vpos=1 -> vpos%2 = 1, ignore
vpos=1.2 -> vpos%2 = 1.2, ignore
vpos=1.7 -> vpos%2 = 1.7, ignore
vpos=2 -> vpos%2 = 0, darken[/code:35mxhfk7]

As you can see, depending on the size in pixels the effect will look very different.

I recommend the following test instead
[code:35mxhfk7]if(vpos%2 > 1)[/code:35mxhfk7]
ALL THAT SAID.... yeah, the diagonal line shouldn't be there at all, and the scanlining should be regular, so yeah it looks like a bug in effect coordinates.....

MORE TESTING REVEALS that this effect only happens when there's more scanlines than physically possible (half the vertical resolution). Why? no idea, but while testing, I ended up writing a full scanlines shader, so here it is.

EDIT: Posted as addon: [url:35mxhfk7]http://www.scirra.com/forum/viewtopic.php?f=29&t=5643[/url:35mxhfk7]
you may change number of shown scanlines, scanline width and intensity of the effect. No offset, because I didn't feel like it.[/quote:35mxhfk7]

Thank you very much, madster :)

I am mislead by "pixelHeight". I thought it was the factor, the height of one pixel in units and that coordinates would give results in units orienting at pixelHeights, so that dividing would lead to integer pixel values. Listened and learned.

I will post to the tracker, and hopefully find workarounds for the bug in transmitting the coordinates to the shader.
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Tue Feb 02, 2010 9:24 pm

[quote="tulamide":31a1kdwx]I am mislead by "pixelHeight". I thought it was the factor, the height of one pixel in units and that coordinates would give results in units orienting at pixelHeights, so that dividing would lead to integer pixel values. Listened and learned.[/quote:31a1kdwx]

Actually you could be right. I'm rather new at shaders. Anyway, turns out the artifacts only happen when scanlines are "packed in too tight", which is useless anyway =)
(my effect shows the same artifact if you increase the number of scanlines over half the vertical resolution)
B
3
S
2
G
4
Posts: 1,445
Reputation: 4,665


Return to Construct engineering

Who is online

Users browsing this forum: No registered users and 0 guests