I'm trying to write a shader to target Auto-stereoscopic displays.. I've used ARB assembly and GLSL to do it in other applications before but I'm not very familiar with the one used here (HLSL I believe?) I haven't done any DirectX programming before so I'm not familiar with the settings/API control and whatnot.
I've been testing it on Unreal.. and I can't seem to wrap my head about why sometimes it crashes and sometimes it doesn't. Sometimes I just take remove a simple operation like - 1.0 and all the sudden it works again, but when I add it back it crashes. Maybe I'm doing something terribly wrong.
Another thing is, how do I enable per-pixel calculation? Because for auto-stereoscopic displays the final output out of this shader cannot be scaled or anything or else it won't align with the attenuator (lenticular in this case). In Unreal when it goes into full screen the pixels seem scaled. When I go into window mode it looks a bit better but it's still not right as the pixels scale according to the viewport size. So how do I make sure that the pixel that is being processed in the shader is the one that's going to be in the exact same spot on the screen? Is there something similar to gl_FragCoord from GLSL in HLSL?
Code is below .. basically it finds the view this particular fragment's R component should be based on the coordinate of the pixel, then figures out the G and B, then samples. My auto-stereoscopic TV is 8 views, but for test case I just used the right view to fill in for views 1-4 and left view to fill in for views 5-8 which should still work just for testing purposes.
Code: Select all
float2 fragCoord;
fragCoord.x = Tex.x * viewWidth;
fragCoord.y = Tex.y * viewHeight;
int r_view;
int g_view;
int b_view;
r_view = int(t_view);
g_view = r_view + 1;
b_view = g_view + 1;
if (r_view > 7)
{
r_view = r_view - 8;
}
if (g_view > 7)
{
g_view = g_view - 8;
}
if (b_view > 7)
{
b_view = b_view - 8;
}
float4 r;
float4 g;
float4 b;
if (r_view < 4)
{
r = tex2D(TexMap0, Tex);
else
{
r = tex2D(TexMap1, Tex);
}
if (g_view < 4)
{
g = tex2D(TexMap0, Tex);
else
{
g = tex2D(TexMap1, Tex);
}
if (b_view < 4)
{
b = tex2D(TexMap0, Tex);
else
{
b = tex2D(TexMap1, Tex);
}
float4 tColor = float4(r[0], g[1], b[2], r[3]);
return tColor;