Jump to content

  • Log In with Google      Sign In   
  • Create Account

#Actualblueshogun96

Posted 20 November 2013 - 07:33 PM

An update on this:

 

Good news: I fixed it with the help of Apple's OpenGL Shader Builder.  Where has this thing been all my life??  Me and this tool are going to have a nice, LONG and intimate relationship together! happy.png

 

Bad news: I only managed to get the ARB version working (turns out that I had to remove the comment at the top, and it the inverse transpose of the modelview was already provided).  The GLSL version is completely broken on the tool, and the actual program.

 

New shader (ARB):

!!ARBvp1.0

# Ported from !!VP1.0 to !!ARBvp1.0 
# by blueshogun96

ATTRIB iPos = vertex.position;
ATTRIB iCol = vertex.color;
ATTRIB iTex = vertex.texcoord;
ATTRIB iNor = vertex.normal;

PARAM mvp[4] = {state.matrix.mvp};
PARAM itmv[4] = {state.matrix.modelview.invtrans};

#PARAM c0 = program.local[0];
#PARAM c1 = program.local[1];
#PARAM c2 = program.local[2];
#PARAM c3 = program.local[3];
#PARAM c4 = program.local[4];
#PARAM c5 = program.local[5];
#PARAM c6 = program.local[6];

PARAM c8 = program.local[8];
PARAM c9 = program.local[9];
PARAM c10 = program.local[10];
PARAM c11 = program.local[11];
PARAM c12 = program.local[12];
PARAM c13 = program.local[13];
PARAM c14 = program.local[14];
PARAM c15 = program.local[15];
PARAM c16 = program.local[16];
PARAM c17 = program.local[17];

OUTPUT oPos = result.position;
OUTPUT oCol = result.color;
OUTPUT oTex = result.texcoord;
#OUTPUT oNor = result.normal;

TEMP R0;
TEMP R1;
TEMP R2;
TEMP R3;
TEMP R4;
TEMP R5;
TEMP R6;

# R0 = (y coordinate of vertex * k) + (w * t)
MAD R0.x, iPos.y, c16.x, c16.z;

# R1 = cos(R0), R0 = any floating point number
MUL R0.x, c11.w, R0.x; 
EXP R0.y, R0.x; 
SLT R2.x, R0.y, c11; 
SGE R2.yz, R0.y, c11; 
DP3 R2.y, R2, c14.zwzw;   
ADD R5.xyz, -R0.y, c10; 
MUL R5, R5, R5;
MAD R0, c12.xyxy, R5, c12.zwzw; 
MAD R0, R0, R5, c13.xyxy;      
MAD R0, R0, R5, c13.zwzw;      
MAD R0, R0, R5, c14.xyxy;      
MAD R0, R0, R5, c14.zwzw;      
DP3 R1.x, R0, -R2; 

# R2 = R1 * c[10] + 1.0
MAD R2.x, R1.x, c10.w, c10.z;

# R3 = perturbed vertex
# R4 = perturbed normal
MOV R2.yw, c16;
MUL R3, iPos, R2.xyxw;
MUL R4, iNor, R2.yxyw;

# Transform vertices into clip space via modelview-projection matrix
DP4 oPos.x, R3, mvp[0];
DP4 oPos.y, R3, mvp[1];
DP4 oPos.z, R3, mvp[2];
DP4 oPos.w, R3, mvp[3];

# Transform normals via inverse transpose modelview matrix & normalize
# R5 = transformed normal
DP3 R5.x, R4, itmv[0];
DP3 R5.y, R4, itmv[1];
DP3 R5.z, R4, itmv[2];
DP3 R5.w, R5, R5;
RSQ R5.w, R5.w;
MUL R5, R5, R5.w;

# Get unit length eye vector to vertex....this is how we texture map
# R6 = vector
ADD R6, c8, iPos;
DP3 R6.w, R6, R6;
RSQ R6.w, R6.w;
MUL R6, R6, R6.w;

# Multiply by 0.5 for texture wrapping
MUL R6, R6, c10.y;
	    
# Texture coord is dot product of normal and vector from eye to vertex
DP3 oTex.x, R5, R6;

# Pass color through
MOV oCol, iCol;

END 

[attachment=18845:Screen Shot 2013-11-20 at 4.30.15 PM.png]

 

It looks even better with post processing effects such as glow, bloom, and a little bit of blur though; the final product is going to look phenomenal, I guarantee it!

 

There doesn't appear to be an easy way to convert assembly shaders to GLSL though.  I found this interesting article though, but that's not of much help to me, IMO.

 

Shogun

 

EDIT: There's 3 instructions (maybe 4) that I'm not sure that I've converted properly.

 

1. SLT R2.x, R0.y, c11;
2. SGE R2.yz, R0.y, c11;

3. ADD R5.xyz, -R0.y, c10;

4. MOV R2.yw, c16;

 

This is where I'm kinda confused.  I understand what these instructions do, but I do not understand how the swizzling effects the output of each operation.  

 

1 & 2: I understand that x and then yz are the values being written to, but is the value in R0.y being compared to c11.y or the first component, c11.x?  Or all of them?

3. This is legal in GL_NV/ARB_vertex_program, but not in GLSL, so I don't understand how ARB handles this either.  Is R0.y being subtracted from each component in c10, and input into R5.xyz?

4. This also confuses me.  So, am I moving c16.xy only into R2.yw?  Or am I moving c16.yw only?

 

Right now, I'm going through the ARB_vertex_program documentation trying to get a better understanding of how the swizzling works because I think I've been misunderstanding it the whole time.  Any ideas?


#2blueshogun96

Posted 20 November 2013 - 06:54 PM

An update on this:

 

Good news: I fixed it with the help of Apple's OpenGL Shader Builder.  Where has this thing been all my life??  Me and this tool are going to have a nice, LONG and intimate relationship together! happy.png

 

Bad news: I only managed to get the ARB version working (turns out that I had to remove the comment at the top, and it the inverse transpose of the modelview was already provided).  The GLSL version is completely broken on the tool, and the actual program.

 

New shader (ARB):

!!ARBvp1.0

# Ported from !!VP1.0 to !!ARBvp1.0 
# by blueshogun96

ATTRIB iPos = vertex.position;
ATTRIB iCol = vertex.color;
ATTRIB iTex = vertex.texcoord;
ATTRIB iNor = vertex.normal;

PARAM mvp[4] = {state.matrix.mvp};
PARAM itmv[4] = {state.matrix.modelview.invtrans};

#PARAM c0 = program.local[0];
#PARAM c1 = program.local[1];
#PARAM c2 = program.local[2];
#PARAM c3 = program.local[3];
#PARAM c4 = program.local[4];
#PARAM c5 = program.local[5];
#PARAM c6 = program.local[6];

PARAM c8 = program.local[8];
PARAM c9 = program.local[9];
PARAM c10 = program.local[10];
PARAM c11 = program.local[11];
PARAM c12 = program.local[12];
PARAM c13 = program.local[13];
PARAM c14 = program.local[14];
PARAM c15 = program.local[15];
PARAM c16 = program.local[16];
PARAM c17 = program.local[17];

OUTPUT oPos = result.position;
OUTPUT oCol = result.color;
OUTPUT oTex = result.texcoord;
#OUTPUT oNor = result.normal;

TEMP R0;
TEMP R1;
TEMP R2;
TEMP R3;
TEMP R4;
TEMP R5;
TEMP R6;

# R0 = (y coordinate of vertex * k) + (w * t)
MAD R0.x, iPos.y, c16.x, c16.z;

# R1 = cos(R0), R0 = any floating point number
MUL R0.x, c11.w, R0.x; 
EXP R0.y, R0.x; 
SLT R2.x, R0.y, c11; 
SGE R2.yz, R0.y, c11; 
DP3 R2.y, R2, c14.zwzw;   
ADD R5.xyz, -R0.y, c10; 
MUL R5, R5, R5;
MAD R0, c12.xyxy, R5, c12.zwzw; 
MAD R0, R0, R5, c13.xyxy;      
MAD R0, R0, R5, c13.zwzw;      
MAD R0, R0, R5, c14.xyxy;      
MAD R0, R0, R5, c14.zwzw;      
DP3 R1.x, R0, -R2; 

# R2 = R1 * c[10] + 1.0
MAD R2.x, R1.x, c10.w, c10.z;

# R3 = perturbed vertex
# R4 = perturbed normal
MOV R2.yw, c16;
MUL R3, iPos, R2.xyxw;
MUL R4, iNor, R2.yxyw;

# Transform vertices into clip space via modelview-projection matrix
DP4 oPos.x, R3, mvp[0];
DP4 oPos.y, R3, mvp[1];
DP4 oPos.z, R3, mvp[2];
DP4 oPos.w, R3, mvp[3];

# Transform normals via inverse transpose modelview matrix & normalize
# R5 = transformed normal
DP3 R5.x, R4, itmv[0];
DP3 R5.y, R4, itmv[1];
DP3 R5.z, R4, itmv[2];
DP3 R5.w, R5, R5;
RSQ R5.w, R5.w;
MUL R5, R5, R5.w;

# Get unit length eye vector to vertex....this is how we texture map
# R6 = vector
ADD R6, c8, iPos;
DP3 R6.w, R6, R6;
RSQ R6.w, R6.w;
MUL R6, R6, R6.w;

# Multiply by 0.5 for texture wrapping
MUL R6, R6, c10.y;
	    
# Texture coord is dot product of normal and vector from eye to vertex
DP3 oTex.x, R5, R6;

# Pass color through
MOV oCol, iCol;

END 

[attachment=18845:Screen Shot 2013-11-20 at 4.30.15 PM.png]

 

It looks even better with post processing effects such as glow, bloom, and a little bit of blur though; the final product is going to look phenomenal, I guarantee it!

 

There doesn't appear to be an easy way to convert assembly shaders to GLSL though.  I found this interesting article though, but that's not of much help to me, IMO.

 

Shogun


#1blueshogun96

Posted 20 November 2013 - 06:53 PM

An update on this:

 

Good news: I fixed it with the help of Apple's OpenGL Shader Builder.  Where has this thing been all my life??  Me and this tool are going to have a nice, LONG and intimate relationship together! happy.png

 

Bad news: I only managed to get the ARB version working (turns out that I had to remove the comment at the top, and it the inverse transpose of the modelview was already provided).  The GLSL version is completely broken on the tool, and the actual program.

 

 

[attachment=18845:Screen Shot 2013-11-20 at 4.30.15 PM.png]

 

It looks even better with post processing effects such as glow, bloom, and a little bit of blur though; the final product is going to look phenomenal, I guarantee it!

 

There doesn't appear to be an easy way to convert assembly shaders to GLSL though.  I found this interesting article though, but that's not of much help to me, IMO.

 

Shogun


PARTNERS