Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undefined variable "gl_Position1" #4

Closed
kg opened this issue Feb 3, 2019 · 11 comments
Closed

Undefined variable "gl_Position1" #4

kg opened this issue Feb 3, 2019 · 11 comments

Comments

@kg
Copy link
Contributor

kg commented Feb 3, 2019

When loading all my lighting shaders with latest FNA, I get a compile error.

Here's the shader source mojoshader is feeding to the driver:

#version 120
uniform vec4 vs_uniforms_vec4[11];
uniform float vpFlip;
const vec4 vs_c13 = vec4(0.857142865, 0.0, 0.0, 0.5);
const vec4 vs_c12 = vec4(0.142857147, 0.0, 0.0, 1.0);
const vec4 vs_c14 = vec4(0.857142865, 1.0, 0.0, 0.0);
const vec4 vs_c15 = vec4(0.142857147, 1.0, 0.0, 0.0);
const vec4 vs_c16 = vec4(0.857142865, 0.142857147, 0.0, 0.0);
const vec4 vs_c17 = vec4(1.0, 0.142857147, 0.0, 0.0);
const vec4 vs_c18 = vec4(1.0, 0.857142865, 0.0, 0.0);
const vec4 vs_c19 = vec4(0.857142865, 0.857142865, 0.0, 0.0);
const vec4 vs_c20 = vec4(0.0, 0.142857147, 0.0, 0.0);
const vec4 vs_c21 = vec4(0.142857147, 0.142857147, 0.0, 0.0);
const vec4 vs_c22 = vec4(0.142857147, 0.857142865, 0.0, 0.0);
const vec4 vs_c23 = vec4(0.0, 0.857142865, 0.0, 0.0);
const vec4 vs_c24 = vec4(0.0, 0.0, 0.0, 0.0);
vec4 vs_r0;
vec4 vs_r1;
vec4 vs_r2;
vec4 vs_r3;
ivec4 vs_a0;
uniform vec4 vs_const_array_12_13[13];
#define vs_c0 vs_uniforms_vec4[0]
#define vs_c1 vs_uniforms_vec4[1]
#define vs_c3 vs_uniforms_vec4[2]
#define vs_c4 vs_uniforms_vec4[3]
#define vs_c5 vs_uniforms_vec4[4]
#define vs_c6 vs_uniforms_vec4[5]
#define vs_c7 vs_uniforms_vec4[6]
#define vs_c8 vs_uniforms_vec4[7]
#define vs_c9 vs_uniforms_vec4[8]
#define vs_c10 vs_uniforms_vec4[9]
#define vs_c11 vs_uniforms_vec4[10]
attribute vec4 vs_v0;
attribute vec4 vs_v1;
attribute vec4 vs_v2;
attribute vec4 vs_v3;
attribute vec4 vs_v4;
#define vs_o0 gl_TexCoord[0]
#define vs_o1 gl_TexCoord[2]
#define vs_o2 gl_TexCoord[3]
#define vs_o3 gl_TexCoord[4]
#define vs_o4 gl_Position1
#define vs_o5 gl_Position

void main()
{
	vs_r0.x = vs_v0.x * vs_c12.w;
	vs_a0.x = int(floor(abs(vs_r0.x) + 0.5) * sign(vs_r0.x));
	vs_r0.xyz = vs_const_array_12_13[vs_a0.x].xyz;
	vs_r0.w = vs_v2.y + vs_v2.x;
	vs_r1.x = vs_r0.w + vs_c12.w;
	vs_r0.w = 1.0 / vs_v3.z;
	vs_r0.w = vs_r0.w * vs_r1.x;
	vs_r0.w = -vs_r0.w;
	vs_r0.w = vs_r0.w + vs_r1.x;
	vs_r0.w = vs_r0.w * vs_c13.w;
	vs_r0.w = -vs_r0.w;
	vs_r1.y = vs_r0.w + vs_r1.x;
	vs_r1.z = vs_c12.y;
	vs_r1.xyz = vs_r1.xyz;
	vs_r2.xyz = -vs_r1.xyz;
	vs_r2.xyz = vs_r2.xyz + vs_v1.xyz;
	vs_r1.yzw = vs_r1.xyz + vs_v1.xyz;
	vs_r0.w = vs_c10.z;
	vs_r0.w = vs_r0.w * vs_r1.x;
	vs_r1.x = vs_c10.y;
	vs_r1.x = vs_r1.x * vs_v1.z;
	vs_r3.xyz = -vs_r2.xyz;
	vs_r1.yzw = vs_r1.yzw + vs_r3.xyz;
	vs_r1.yzw = vs_r0.xyz * vs_r1.yzw;
	vs_r2.xyz = vs_r1.yzw + vs_r2.xyz;
	vs_r0.x = float(vs_r0.y < vs_c13.w);
	if (vs_r0.x != -vs_r0.x) {
		vs_r0.x = -vs_r0.w;
		vs_r0.x = vs_r0.x + vs_r2.y;
		vs_r0.y = -vs_r1.x;
		vs_r2.w = vs_r0.y + vs_r0.x;
	} else {
		vs_r2.w = vs_r2.y;
	}
	vs_r0.xy = -vs_c9.xy;
	vs_r0.z = -vs_c12.y;
	vs_r0.xyz = vs_r0.xyz + vs_r2.xwz;
	vs_r1.xy = vs_c8.xy;
	vs_r1.xy = vs_r1.xy * vs_c11.xy;
	vs_r1.xy = vs_r0.xy * vs_r1.xy;
	vs_r0.xy = vs_r0.zz * vs_c12.wy;
	vs_r1.zw = vs_r0.xy + vs_c12.yw;
	vs_r0.x = dot(vs_r1, vs_c4);
	vs_r0.y = dot(vs_r1, vs_c5);
	vs_r0.z = dot(vs_r1, vs_c6);
	vs_r0.w = dot(vs_r1, vs_c7);
	vs_r1.x = dot(vs_r0, vs_c0);
	vs_r1.y = dot(vs_r0, vs_c1);
	vs_r1.w = dot(vs_r0, vs_c3);
	vs_o5.xyw = vs_r1.xyw;
	vs_o5.z = vs_c12.y;
	vs_o0.xyz = vs_v1.xyz;
	vs_o1 = vs_v2;
	vs_o2 = vs_v3;
	vs_o3 = vs_v4;
	vs_o4.xyz = vs_r2.xwz;
	gl_Position.y = gl_Position.y * vpFlip;
	gl_Position.z = gl_Position.z * 2.0 - gl_Position.w;
}

The relevant part of the HLSL shader, I think:

void SphereLightVertexShader(
    in int2 vertexIndex              : BLENDINDICES0,
    inout float3 lightCenter         : TEXCOORD0,
    // radius, ramp length, ramp mode, enable shadows
    inout float4 lightProperties     : TEXCOORD2,
    // ao radius, distance falloff, y falloff factor, ao opacity
    inout float4 moreLightProperties : TEXCOORD3,
    inout float4 color               : TEXCOORD4,
    out float3 worldPosition         : POSITION1,
    out float4 result                : POSITION0
@kg
Copy link
Contributor Author

kg commented Feb 3, 2019

Incidentally, shouldn't vs_a0 be an attribute since it's coming from the vertex buffer with the vs_vN uniforms? I'm not totally clear on how this works.

@flibitijibibo
Copy link
Collaborator

Probably have to break before this assignment when index > 0:

https://github.com/FNA-XNA/MojoShader/blob/fna-staging/mojoshader.c#L2626

@kg
Copy link
Contributor Author

kg commented Feb 3, 2019

maybe strcpy gl_position to var, then strcat the index and return that?

@flibitijibibo
Copy link
Collaborator

Try the break first. The issue isn't the name, it's that we're trying a builtin that doesn't actually exist. If we break before that assignment, it'll move to the logic that generates a varying to fill in the spot that POSITION1 will take.

@flibitijibibo
Copy link
Collaborator

Here's the git diff of what I mean, should apply cleanly to the MojoShader submodule in your local copy of FNA:

diff --git a/mojoshader.c b/mojoshader.c
index 083d8a7..fad1854 100644
--- a/mojoshader.c
+++ b/mojoshader.c
@@ -2603,6 +2603,8 @@ static void emit_GLSL_attribute(Context *ctx, RegisterType regtype, int regnum,
             switch (usage)
             {
                 case MOJOSHADER_USAGE_POSITION:
+                    if (index > 0)
+                        break;
                     usage_str = "gl_Position";
                     break;
                 case MOJOSHADER_USAGE_POINTSIZE:

@kg
Copy link
Contributor Author

kg commented Feb 5, 2019

I can't get FNA's version of mojoshader to build, are there instructions somewhere? I have all the dependencies I can figure out how to get, but cmake is exploding when I try to configure+generate with multiple errors. The one about SDL2 seems like it's probably the root cause but it's not clear to me how I'm supposed to fix it:

re2c missing. You can go on, but can't rebuild the lexer.
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
SDL2
    linked by target "finderrors" in directory E:/Documents/Projects/FNA/lib/MojoShader

Am I meant to put SDL2's sources somewhere and then point cmake to them? Which revision of SDL2?

@flibitijibibo
Copy link
Collaborator

@kg
Copy link
Contributor Author

kg commented Feb 5, 2019

Do I put SDL2 in a certain place? In my PATH?

@flibitijibibo
Copy link
Collaborator

SDL2 won’t come into play, that’s a test program acting up. It should ignore that test when it’s not found.

@flibitijibibo
Copy link
Collaborator

Latest MojoShader revision introduces some CMake changes that may make building easier. This should work now:

mkdir flibitBuild
cd flibitBuild
cmake -G "Visual Studio 10 2010" .. -DBUILD_SHARED=ON -DPROFILE_D3D=OFF -DPROFILE_BYTECODE=OFF -DPROFILE_ARB1=OFF -DPROFILE_ARB1_NV=OFF -DPROFILE_METAL=OFF -DCOMPILER_SUPPORT=OFF -DFLIP_VIEWPORT=ON -DDEPTH_CLIPPING=ON -DXNA4_VERTEXTEXTURE=ON

@flibitijibibo
Copy link
Collaborator

Fixed by 4c1c597

TheSpydog pushed a commit to TheSpydog/MojoShader that referenced this issue May 24, 2020
TheSpydog pushed a commit to TheSpydog/MojoShader that referenced this issue May 26, 2020
TheSpydog pushed a commit to TheSpydog/MojoShader that referenced this issue May 26, 2020
TheSpydog pushed a commit to TheSpydog/MojoShader that referenced this issue Jun 24, 2020
TheSpydog pushed a commit to TheSpydog/MojoShader that referenced this issue Jun 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants