GLSL equivalent of Cg bool4

I’m hand-converting some CG shaders to GLSL for a project I’m doing, and the XBR shaders have a construct that’s giving me a bit of trouble.

bool4 value = a < b;
if (!value)

I assume that the GLSL equivalent is one of the following, but I’m not sure which one it is, and I was hoping someone here could tell me.

Is it is?

bvec4 value = lessThan(a, b);
if (!any(value))

Or is it this?

bvec4 value = lessThan(a, b);
if (!all(value))

Thanks.

Could you paste the specific shader you’re trying to port and the lines where that cosntruction is?

Thats because It depends on the IF construction you are trying to port.

‘if (!value)’ isn’t the same as ‘x = (!value) ? y : z;’. So I can’t answer exactly what you’re asking.

It’s xbr-lv2.

One line (condensed a bit for this post) is:

bool4 interp_restriction_lv0 = // snip
bool4 edri = (wd1 <= wd2) && interp_restriction_lv0;

Another line is long, so I’ll summarize:

It calls eq, which is returns a 4-component boolean vector:

bool4 eq(float4 A, float4 B)
{
	return (df(A, B) < float4(XBR_EQ_THRESHOLD));
}

And then that line has tests AND’d together, such as:

if (!eq(f,b) && !eq(h,d) || eq(e,i) &&

‘if (!value)’ isn’t the same as ‘x = (!value) ? y : z;’.

Thanks. I didn’t know that.

Ok, I ported exactly this xbr-lv2 to glsl to be used by ePSXe. So I think you can grab the code from it.

I converted all bools and bvecs to float and vecs because glsl is an annoying language, almost non-intuitive. Cg is so straight forward… Shame that it is abandoned now.

Get it in attachment.

Wow, thanks. That helps a lot. Going through that, one thing I realized pretty quickly is that I’m nowhere near the level where I could have done that on my own.

Here are two attempts. The vertex shader is the same between each attempt:

https://github.com/duganchen/dosbox_shaders/blob/master/xbr-lv2.vert

The first attempt at the fragment shader is a straight adaptation of the epsxe shader, and it works well:

The second is an attempt at porting the one in the common-shaders repo, using what I learned from the epsxe shader, and… it really doesn’t work (there’s no noticeable effect at all).

I’m curious as to where I went wrong in my second attempt. One thing I noticed from the epsxe shader is that when you replaced the “mul” commands, you didn’t simply swap the order of the operands like I’d usually seen recommended. Did I mess up by simply swapping the operand order when I should have done what you did, or did I also mess up elsewhere? Do mat4x3(A, B, C, D) and float4x3(A, B, C, D) not actually create the same matrix?

Maybe you should invert this:

(XBR_Y_WEIGHT*Y) * mat4x3(B, D, H, F);

by this?

mat4x3(B, D, H, F) * (XBR_Y_WEIGHT*Y) ;

Well, I really don’t like how glsl treat matrix multiplications. It’s completely non-intuitive.

I made a thread a looong time ago about converting GLSL to Cg (back before we had ALL TEH SHADERS) that could be helpful going the other direction: http://libretro.com/forums/showthread.php?t=402

You indeed have to swap columns with rows as one language is column-major (Cg, I think?) and the other is row-major (GLSL, I think?)

It seems to me that even inverting it wouldn’t work. You have to transpose the color matrix I think. In Cg there’s a transpose function: http://http.developer.nvidia.com/Cg/transpose.html. Maybe it’s the same for glsl.