Remove the remaining bits of deprecated GL usage
The drawing is now completely shader based, which makes away
with all usage of the depracted matrix stack. This also allows
us to do things like simple translations and texture coordinate
translation directly instead of doing everything indirectly
through matrices.
Fixed vertex attributes ('vertexPointer()' etc) are also
replaced with user defined attribute arrays.
			
			
This commit is contained in:
		
							parent
							
								
									88c1489554
								
							
						
					
					
						commit
						9e63fb6b64
					
				
					 29 changed files with 701 additions and 295 deletions
				
			
		| 
						 | 
				
			
			@ -1,3 +1,5 @@
 | 
			
		|||
/* Shader for approximating the way RMXP does bitmap
 | 
			
		||||
 * blending via DirectDraw */
 | 
			
		||||
 | 
			
		||||
uniform sampler2D source;
 | 
			
		||||
uniform sampler2D destination;
 | 
			
		||||
| 
						 | 
				
			
			@ -6,9 +8,11 @@ uniform vec4 subRect;
 | 
			
		|||
 | 
			
		||||
uniform float opacity;
 | 
			
		||||
 | 
			
		||||
varying vec2 v_texCoord;
 | 
			
		||||
 | 
			
		||||
void main()
 | 
			
		||||
{
 | 
			
		||||
	vec2 coor = gl_TexCoord[0].xy;
 | 
			
		||||
	vec2 coor = v_texCoord;
 | 
			
		||||
	vec2 dstCoor = (coor - subRect.xy) * subRect.zw;
 | 
			
		||||
 | 
			
		||||
	vec4 srcFrag = texture2D(source, coor);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,40 +1,44 @@
 | 
			
		|||
 | 
			
		||||
uniform sampler2D inputTexture;
 | 
			
		||||
uniform float   hueAdjust;
 | 
			
		||||
uniform float hueAdjust;
 | 
			
		||||
 | 
			
		||||
varying vec2 v_texCoord;
 | 
			
		||||
 | 
			
		||||
void main ()
 | 
			
		||||
{
 | 
			
		||||
	const vec4  kRGBToYPrime = vec4 (0.299, 0.587, 0.114, 0.0);
 | 
			
		||||
	const vec4  kRGBToI     = vec4 (0.596, -0.275, -0.321, 0.0);
 | 
			
		||||
	const vec4  kRGBToQ     = vec4 (0.212, -0.523, 0.311, 0.0);
 | 
			
		||||
	const vec4  kRGBToI      = vec4 (0.596, -0.275, -0.321, 0.0);
 | 
			
		||||
	const vec4  kRGBToQ      = vec4 (0.212, -0.523, 0.311, 0.0);
 | 
			
		||||
 | 
			
		||||
	const vec4  kYIQToR   = vec4 (1.0, 0.956, 0.621, 0.0);
 | 
			
		||||
	const vec4  kYIQToG   = vec4 (1.0, -0.272, -0.647, 0.0);
 | 
			
		||||
	const vec4  kYIQToB   = vec4 (1.0, -1.107, 1.704, 0.0);
 | 
			
		||||
	const vec4  kYIQToR      = vec4 (1.0, 0.956, 0.621, 0.0);
 | 
			
		||||
	const vec4  kYIQToG      = vec4 (1.0, -0.272, -0.647, 0.0);
 | 
			
		||||
	const vec4  kYIQToB      = vec4 (1.0, -1.107, 1.704, 0.0);
 | 
			
		||||
 | 
			
		||||
	// Sample the input pixel
 | 
			
		||||
	vec4    color   = texture2D (inputTexture, gl_TexCoord [ 0 ].xy);
 | 
			
		||||
	/* Sample the input pixel */
 | 
			
		||||
	vec4    color   = texture2D (inputTexture, v_texCoord.xy);
 | 
			
		||||
 | 
			
		||||
	// Convert to YIQ
 | 
			
		||||
	float   YPrime = dot (color, kRGBToYPrime);
 | 
			
		||||
	float   I      = dot (color, kRGBToI);
 | 
			
		||||
	float   Q      = dot (color, kRGBToQ);
 | 
			
		||||
	/* Convert to YIQ */
 | 
			
		||||
	float   YPrime  = dot (color, kRGBToYPrime);
 | 
			
		||||
	float   I       = dot (color, kRGBToI);
 | 
			
		||||
	float   Q       = dot (color, kRGBToQ);
 | 
			
		||||
 | 
			
		||||
	// Calculate the hue and chroma
 | 
			
		||||
	/* Calculate the hue and chroma */
 | 
			
		||||
	float   hue     = atan (Q, I);
 | 
			
		||||
	float   chroma  = sqrt (I * I + Q * Q);
 | 
			
		||||
 | 
			
		||||
	// Make the user's adjustments
 | 
			
		||||
	/* Make the user's adjustments */
 | 
			
		||||
	hue += hueAdjust;
 | 
			
		||||
 | 
			
		||||
	// Convert back to YIQ
 | 
			
		||||
	Q = chroma * sin (hue);
 | 
			
		||||
	I = chroma * cos (hue);
 | 
			
		||||
 | 
			
		||||
	// Convert back to RGB
 | 
			
		||||
	vec4    yIQ   = vec4 (YPrime, I, Q, 0.0);
 | 
			
		||||
	color.r = dot (yIQ, kYIQToR);
 | 
			
		||||
	color.g = dot (yIQ, kYIQToG);
 | 
			
		||||
	color.b = dot (yIQ, kYIQToB);
 | 
			
		||||
	/* Convert back to RGB */
 | 
			
		||||
	vec4 yIQ = vec4 (YPrime, I, Q, 0.0);
 | 
			
		||||
	color.r  = dot  (yIQ, kYIQToR);
 | 
			
		||||
	color.g  = dot  (yIQ, kYIQToG);
 | 
			
		||||
	color.b  = dot  (yIQ, kYIQToB);
 | 
			
		||||
 | 
			
		||||
	// Save the result
 | 
			
		||||
	gl_FragColor    = color;
 | 
			
		||||
	/* Save the result */
 | 
			
		||||
	gl_FragColor = color;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										36
									
								
								shader/plane.frag
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								shader/plane.frag
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,36 @@
 | 
			
		|||
 | 
			
		||||
uniform sampler2D texture;
 | 
			
		||||
 | 
			
		||||
uniform vec4 tone;
 | 
			
		||||
 | 
			
		||||
uniform float opacity;
 | 
			
		||||
uniform vec4 color;
 | 
			
		||||
uniform vec4 flash;
 | 
			
		||||
 | 
			
		||||
varying vec2 v_texCoord;
 | 
			
		||||
 | 
			
		||||
const vec3 lumaF = { .299, .587, .114 };
 | 
			
		||||
 | 
			
		||||
void main()
 | 
			
		||||
{
 | 
			
		||||
	/* Sample source color */
 | 
			
		||||
	vec4 frag = texture2D(texture, v_texCoord);
 | 
			
		||||
	
 | 
			
		||||
	/* Apply gray */
 | 
			
		||||
	const float luma = dot(frag.rgb, lumaF);
 | 
			
		||||
	frag.rgb = mix(frag.rgb, vec3(luma), tone.w);
 | 
			
		||||
	
 | 
			
		||||
	/* Apply tone */
 | 
			
		||||
	frag.rgb += tone.rgb;
 | 
			
		||||
 | 
			
		||||
	/* Apply opacity */
 | 
			
		||||
	frag.a *= opacity;
 | 
			
		||||
	
 | 
			
		||||
	/* Apply color */
 | 
			
		||||
	frag.rgb = mix(frag.rgb, color.rgb, color.a);
 | 
			
		||||
 | 
			
		||||
	/* Apply flash */
 | 
			
		||||
	frag.rgb = mix(frag.rgb, flash.rgb, flash.a);
 | 
			
		||||
	
 | 
			
		||||
	gl_FragColor = frag;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										9
									
								
								shader/simple.frag
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								shader/simple.frag
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,9 @@
 | 
			
		|||
 | 
			
		||||
uniform sampler2D texture;
 | 
			
		||||
 | 
			
		||||
varying vec2 v_texCoord;
 | 
			
		||||
 | 
			
		||||
void main()
 | 
			
		||||
{
 | 
			
		||||
	gl_FragColor = texture2D(texture, v_texCoord);
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										18
									
								
								shader/simple.vert
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								shader/simple.vert
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,18 @@
 | 
			
		|||
 | 
			
		||||
uniform mat4 projMat;
 | 
			
		||||
 | 
			
		||||
uniform vec2 texSizeInv;
 | 
			
		||||
uniform float texOffsetX;
 | 
			
		||||
uniform vec2 translation;
 | 
			
		||||
 | 
			
		||||
attribute vec2 position;
 | 
			
		||||
attribute vec2 texCoord;
 | 
			
		||||
 | 
			
		||||
varying vec2 v_texCoord;
 | 
			
		||||
 | 
			
		||||
void main()
 | 
			
		||||
{
 | 
			
		||||
	gl_Position = projMat * vec4(position + translation, 0, 1);
 | 
			
		||||
 | 
			
		||||
	v_texCoord = vec2(texCoord.x + texOffsetX, texCoord.y) * texSizeInv;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										11
									
								
								shader/simpleAlpha.frag
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								shader/simpleAlpha.frag
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,11 @@
 | 
			
		|||
 | 
			
		||||
uniform sampler2D texture;
 | 
			
		||||
 | 
			
		||||
varying vec2 v_texCoord;
 | 
			
		||||
varying vec4 v_color;
 | 
			
		||||
 | 
			
		||||
void main()
 | 
			
		||||
{
 | 
			
		||||
	gl_FragColor = texture2D(texture, v_texCoord);
 | 
			
		||||
	gl_FragColor.a *= v_color.a;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										7
									
								
								shader/simpleColor.frag
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								shader/simpleColor.frag
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,7 @@
 | 
			
		|||
 | 
			
		||||
varying vec4 v_color;
 | 
			
		||||
 | 
			
		||||
void main()
 | 
			
		||||
{
 | 
			
		||||
	gl_FragColor = v_color;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										20
									
								
								shader/simpleColor.vert
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								shader/simpleColor.vert
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,20 @@
 | 
			
		|||
 | 
			
		||||
uniform mat4 projMat;
 | 
			
		||||
 | 
			
		||||
uniform vec2 texSizeInv;
 | 
			
		||||
uniform vec2 translation;
 | 
			
		||||
 | 
			
		||||
attribute vec2 position;
 | 
			
		||||
attribute vec2 texCoord;
 | 
			
		||||
attribute vec4 color;
 | 
			
		||||
 | 
			
		||||
varying vec2 v_texCoord;
 | 
			
		||||
varying vec4 v_color;
 | 
			
		||||
 | 
			
		||||
void main()
 | 
			
		||||
{
 | 
			
		||||
	gl_Position = projMat * vec4(position + translation, 0, 1);
 | 
			
		||||
 | 
			
		||||
	v_texCoord = texCoord * texSizeInv;
 | 
			
		||||
	v_color = color;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -5,19 +5,18 @@ uniform vec4 tone;
 | 
			
		|||
 | 
			
		||||
uniform float opacity;
 | 
			
		||||
uniform vec4 color;
 | 
			
		||||
uniform vec4 flash;
 | 
			
		||||
 | 
			
		||||
uniform float bushDepth;
 | 
			
		||||
uniform float bushOpacity;
 | 
			
		||||
 | 
			
		||||
uniform float bushOpacity;
 | 
			
		||||
 | 
			
		||||
varying vec2 v_texCoord;
 | 
			
		||||
 | 
			
		||||
const vec3 lumaF = { .299, .587, .114 };
 | 
			
		||||
 | 
			
		||||
void main()
 | 
			
		||||
{
 | 
			
		||||
	vec2 coor = gl_TexCoord[0].xy;
 | 
			
		||||
 | 
			
		||||
	/* Sample source color */
 | 
			
		||||
	vec4 frag = texture2D(texture, coor);
 | 
			
		||||
	vec4 frag = texture2D(texture, v_texCoord);
 | 
			
		||||
	
 | 
			
		||||
	/* Apply gray */
 | 
			
		||||
	const float luma = dot(frag.rgb, lumaF);
 | 
			
		||||
| 
						 | 
				
			
			@ -32,11 +31,8 @@ void main()
 | 
			
		|||
	/* Apply color */
 | 
			
		||||
	frag.rgb = mix(frag.rgb, color.rgb, color.a);
 | 
			
		||||
 | 
			
		||||
	/* Apply flash */
 | 
			
		||||
	frag.rgb = mix(frag.rgb, flash.rgb, flash.a);
 | 
			
		||||
 | 
			
		||||
	/* Apply bush alpha by mathematical if */
 | 
			
		||||
	float underBush = float(coor.y < bushDepth);
 | 
			
		||||
	float underBush = float(v_texCoord.y < bushDepth);
 | 
			
		||||
	frag.a *= clamp(bushOpacity + underBush, 0, 1);
 | 
			
		||||
	
 | 
			
		||||
	gl_FragColor = frag;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										17
									
								
								shader/sprite.vert
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								shader/sprite.vert
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,17 @@
 | 
			
		|||
 | 
			
		||||
uniform mat4 projMat;
 | 
			
		||||
 | 
			
		||||
uniform mat4 spriteMat;
 | 
			
		||||
 | 
			
		||||
uniform vec2 texSizeInv;
 | 
			
		||||
 | 
			
		||||
attribute vec2 position;
 | 
			
		||||
attribute vec2 texCoord;
 | 
			
		||||
 | 
			
		||||
varying vec2 v_texCoord;
 | 
			
		||||
 | 
			
		||||
void main()
 | 
			
		||||
{
 | 
			
		||||
	gl_Position = projMat * spriteMat * vec4(position, 0, 1);
 | 
			
		||||
	v_texCoord = texCoord * texSizeInv;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,4 +1,3 @@
 | 
			
		|||
 | 
			
		||||
/* Fragment shader dealing with transitions */
 | 
			
		||||
 | 
			
		||||
uniform sampler2D currentScene;
 | 
			
		||||
| 
						 | 
				
			
			@ -9,15 +8,16 @@ uniform float prog;
 | 
			
		|||
/* Vague [0, 512] normalized */
 | 
			
		||||
uniform float vague;
 | 
			
		||||
 | 
			
		||||
varying vec2 v_texCoord;
 | 
			
		||||
 | 
			
		||||
void main()
 | 
			
		||||
{
 | 
			
		||||
    vec2 texCoor = gl_TexCoord[0].st;
 | 
			
		||||
    float transV = texture2D(transMap, texCoor).r;
 | 
			
		||||
    float transV = texture2D(transMap, v_texCoord).r;
 | 
			
		||||
    float cTransV = clamp(transV, prog, prog+vague);
 | 
			
		||||
    float alpha = (cTransV - prog) / vague;
 | 
			
		||||
    
 | 
			
		||||
    vec4 newFrag = texture2D(currentScene, texCoor);
 | 
			
		||||
    vec4 oldFrag = texture2D(frozenScene, texCoor);
 | 
			
		||||
    vec4 newFrag = texture2D(currentScene, v_texCoord);
 | 
			
		||||
    vec4 oldFrag = texture2D(frozenScene, v_texCoord);
 | 
			
		||||
    
 | 
			
		||||
    gl_FragColor = mix(newFrag, oldFrag, alpha);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,13 +1,16 @@
 | 
			
		|||
/* Fragment shader that produces a simple
 | 
			
		||||
 * fade in / fade out type transition */
 | 
			
		||||
 | 
			
		||||
uniform sampler2D frozenScene;
 | 
			
		||||
uniform sampler2D currentScene;
 | 
			
		||||
uniform float prog;
 | 
			
		||||
 | 
			
		||||
varying vec2 v_texCoord;
 | 
			
		||||
 | 
			
		||||
void main()
 | 
			
		||||
{
 | 
			
		||||
    vec2 texCoor = gl_TexCoord[0].st;
 | 
			
		||||
    vec4 newPixel = texture2D(currentScene, texCoor);
 | 
			
		||||
    vec4 oldPixel = texture2D(frozenScene, texCoor);
 | 
			
		||||
    vec4 newPixel = texture2D(currentScene, v_texCoord);
 | 
			
		||||
    vec4 oldPixel = texture2D(frozenScene, v_texCoord);
 | 
			
		||||
 | 
			
		||||
    gl_FragColor = mix(oldPixel, newPixel, prog);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue