mirror of
https://github.com/DrBeef/Raze.git
synced 2024-11-22 20:21:20 +00:00
Separate out polymost1Frag and polymost1Vert shaders from polymost.cpp and add rules for building in the GNUmakefile.
Additionally, git ignore the shader's generated headers folder. git-svn-id: https://svn.eduke32.com/eduke32@7782 1a8010ca-5511-0410-912e-c29ae57300e0 # Conflicts: # .gitignore # source/build/src/polymost.cpp
This commit is contained in:
parent
fe36034e43
commit
f6993940e5
6 changed files with 193 additions and 253 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -54,6 +54,8 @@ project.xcworkspace/
|
|||
|
||||
.DS_Store
|
||||
._*
|
||||
|
||||
/source/build/src/generated/
|
||||
Platform/Windows/Build
|
||||
Platform/Windows/Win32
|
||||
Platform/Windows/x64
|
||||
|
|
|
@ -126,6 +126,9 @@ endef
|
|||
define RMDIR
|
||||
rm -rf $(filter-out / *,$1)
|
||||
endef
|
||||
define CAT
|
||||
cat $1
|
||||
endef
|
||||
|
||||
ifeq (0,$(HAVE_SH))
|
||||
DONT_FAIL := & rem
|
||||
|
@ -142,6 +145,9 @@ ifeq (0,$(HAVE_SH))
|
|||
define RMDIR
|
||||
rmdir /s /q $(subst /,\,$(filter-out / *,$1)) $(DONT_PRINT_STDERR) $(DONT_FAIL)
|
||||
endef
|
||||
define CAT
|
||||
type $1
|
||||
endef
|
||||
|
||||
# if, printf, exit, and ; are unavailable without sh
|
||||
PRETTY_OUTPUT := 0
|
||||
|
|
|
@ -218,6 +218,8 @@ engine_objs := \
|
|||
2d.cpp \
|
||||
hash.cpp \
|
||||
palette.cpp \
|
||||
polymost1Frag.glsl \
|
||||
polymost1Vert.glsl \
|
||||
polymost.cpp \
|
||||
texcache.cpp \
|
||||
dxtfilter.cpp \
|
||||
|
@ -1010,6 +1012,13 @@ $$($1_obj)/%.$$o: $$($1_obj)/%.c
|
|||
$$(COMPILE_STATUS)
|
||||
$$(RECIPE_IF) $$(COMPILER_C) $$($1_cflags) -c $$< -o $$@ $$(RECIPE_RESULT_COMPILE)
|
||||
|
||||
$$($1_obj)/%.$$o: $$($1_src)/%.glsl | $$($1_src)/generated
|
||||
echo "Creating header from "$$<
|
||||
echo "char const *$$(basename $$(<F)) = R\"shader(" > $$(<D)/generated/$$(<F).h
|
||||
$$(CAT) $$< >> $$(<D)/generated/$$(<F).h
|
||||
echo ")shader\";" >> $$(<D)/generated/$$(<F).h
|
||||
echo " " | $$(COMPILER_CXX) $$($1_cflags) -x c++ -c - -o $$@
|
||||
|
||||
## Cosmetic stuff
|
||||
|
||||
$$($1_obj)/%.$$o: $$($1_rsrc)/%.rc | $$($1_obj)
|
||||
|
|
|
@ -385,7 +385,7 @@ static void calcmat(vec3f_t a0, const vec2f_t *offset, float f, float mat[16], i
|
|||
mat[14] = (mat[14] + a0.y*mat[2]) + (a0.z*mat[6] + a0.x*mat[10]);
|
||||
}
|
||||
|
||||
static GLuint polymost2_compileShader(GLenum shaderType, const char* const source)
|
||||
static GLuint polymost2_compileShader(GLenum shaderType, const char* const source, int length)
|
||||
{
|
||||
GLuint shaderID = glCreateShader(shaderType);
|
||||
if (shaderID == 0)
|
||||
|
@ -393,11 +393,10 @@ static GLuint polymost2_compileShader(GLenum shaderType, const char* const sourc
|
|||
return 0;
|
||||
}
|
||||
|
||||
const char* const sources[1] = {source};
|
||||
glShaderSource(shaderID,
|
||||
1,
|
||||
sources,
|
||||
NULL);
|
||||
&source,
|
||||
&length);
|
||||
glCompileShader(shaderID);
|
||||
|
||||
GLint compileStatus;
|
||||
|
@ -848,8 +847,8 @@ void polymost_glinit()
|
|||
}\n";
|
||||
|
||||
polymost2BasicShaderProgramID = glCreateProgram();
|
||||
GLuint polymost2BasicVertexShaderID = polymost2_compileShader(GL_VERTEX_SHADER, POLYMOST2_BASIC_VERTEX_SHADER_CODE);
|
||||
GLuint polymost2BasicFragmentShaderID = polymost2_compileShader(GL_FRAGMENT_SHADER, POLYMOST2_BASIC_FRAGMENT_SHADER_CODE);
|
||||
GLuint polymost2BasicVertexShaderID = polymost2_compileShader(GL_VERTEX_SHADER, POLYMOST2_BASIC_VERTEX_SHADER_CODE, 0);
|
||||
GLuint polymost2BasicFragmentShaderID = polymost2_compileShader(GL_FRAGMENT_SHADER, POLYMOST2_BASIC_FRAGMENT_SHADER_CODE, 0);
|
||||
glBindAttribLocation(polymost2BasicShaderProgramID, 0, "i_vertPos");
|
||||
glBindAttribLocation(polymost2BasicShaderProgramID, 1, "i_texCoord");
|
||||
glAttachShader(polymost2BasicShaderProgramID, polymost2BasicVertexShaderID);
|
||||
|
@ -868,259 +867,34 @@ void polymost_glinit()
|
|||
fogRangeLoc = glGetUniformLocation(polymost2BasicShaderProgramID, "u_fogRange");
|
||||
fogColorLoc = glGetUniformLocation(polymost2BasicShaderProgramID, "u_fogColor");
|
||||
|
||||
const char* const POLYMOST1_BASIC_VERTEX_SHADER_CODE =
|
||||
"#version 110\n\
|
||||
\n\
|
||||
varying vec4 v_color;\n\
|
||||
varying float v_distance;\n\
|
||||
\n\
|
||||
//u_texturePosSize is the texture position & size packaged into a single vec4 as {pos.x, pos.y, size.x, size.y}\n\
|
||||
uniform vec4 u_texturePosSize;\n\
|
||||
uniform float u_usePalette;\n\
|
||||
uniform mat4 u_rotMatrix;\n\
|
||||
\n\
|
||||
const float c_zero = 0.0;\n\
|
||||
const float c_one = 1.0;\n\
|
||||
\n\
|
||||
void main()\n\
|
||||
{\n\
|
||||
vec4 vertex = u_rotMatrix * gl_Vertex;\n\
|
||||
vec4 eyeCoordPosition = gl_ModelViewMatrix * vertex;\n\
|
||||
gl_Position = gl_ModelViewProjectionMatrix * vertex;\n\
|
||||
\n\
|
||||
eyeCoordPosition.xyz /= eyeCoordPosition.w;\n\
|
||||
\n\
|
||||
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;\n\
|
||||
gl_TexCoord[0] = mix(gl_TexCoord[0].xyzw, gl_TexCoord[0].yxzw, u_usePalette);\n\
|
||||
\n\
|
||||
gl_TexCoord[3] = gl_TextureMatrix[3] * gl_MultiTexCoord3;\n\
|
||||
gl_TexCoord[4] = gl_TextureMatrix[4] * gl_MultiTexCoord4;\n\
|
||||
\n\
|
||||
gl_FogFragCoord = abs(eyeCoordPosition.z);\n\
|
||||
//gl_FogFragCoord = clamp((gl_Fog.end-abs(eyeCoordPosition.z))*gl_Fog.scale, c_zero, c_one);\n\
|
||||
\n\
|
||||
v_color = gl_Color;\n\
|
||||
v_distance = gl_Vertex.z;\n\
|
||||
}\n";
|
||||
const char* const POLYMOST1_BASIC_FRAGMENT_SHADER_CODE =
|
||||
"#version 110\n\
|
||||
#extension ARB_shader_texture_lod : enable\n\
|
||||
\n\
|
||||
//s_texture points to an indexed color texture\n\
|
||||
uniform sampler2D s_texture;\n\
|
||||
//s_palswap is the palette swap texture where u is the color index and v is the shade\n\
|
||||
uniform sampler2D s_palswap;\n\
|
||||
//s_palette is the base palette texture where u is the color index\n\
|
||||
uniform sampler2D s_palette;\n\
|
||||
\n\
|
||||
//u_texturePosSize is the texture position & size packaged into a single vec4 as {pos.x, pos.y, size.x, size.y}\n\
|
||||
uniform vec4 u_texturePosSize;\n\
|
||||
uniform vec2 u_halfTexelSize;\n\
|
||||
uniform vec2 u_palswapPos;\n\
|
||||
uniform vec2 u_palswapSize;\n\
|
||||
\n\
|
||||
uniform float u_shade;\n\
|
||||
uniform float u_numShades;\n\
|
||||
uniform float u_visFactor;\n\
|
||||
uniform float u_fogEnabled;\n\
|
||||
\n\
|
||||
uniform float u_useColorOnly;\n\
|
||||
uniform float u_usePalette;\n\
|
||||
uniform float u_npotEmulation;\n\
|
||||
uniform float u_npotEmulationFactor;\n\
|
||||
uniform float u_npotEmulationXOffset;\n\
|
||||
uniform float u_brightness;\n\
|
||||
uniform float u_shadeInterpolate;\n\
|
||||
\n\
|
||||
varying vec4 v_color;\n\
|
||||
varying float v_distance;\n\
|
||||
\n\
|
||||
const float c_basepalScale = 255.0/256.0;\n\
|
||||
const float c_basepalOffset = 0.5/256.0;\n\
|
||||
\n\
|
||||
const float c_zero = 0.0;\n\
|
||||
const float c_one = 1.0;\n\
|
||||
const float c_two = 2.0;\n\
|
||||
const vec4 c_vec4_one = vec4(c_one);\n\
|
||||
const float c_wrapThreshold = 0.9;\n\
|
||||
\n\
|
||||
void main()\n\
|
||||
{\n\
|
||||
float coordY = mix(gl_TexCoord[0].y,gl_TexCoord[0].x,u_usePalette);\n\
|
||||
float coordX = mix(gl_TexCoord[0].x,gl_TexCoord[0].y,u_usePalette);\n\
|
||||
float period = floor(coordY/u_npotEmulationFactor);\n\
|
||||
coordX += u_npotEmulationXOffset*floor(mod(coordY,u_npotEmulationFactor));\n\
|
||||
coordY = period+mod(coordY,u_npotEmulationFactor);\n\
|
||||
vec2 newCoord = mix(gl_TexCoord[0].xy,mix(vec2(coordX,coordY),vec2(coordY,coordX),u_usePalette),u_npotEmulation);\n\
|
||||
#ifdef GL_ARB_shader_texture_lod\n\
|
||||
vec2 texCoord = fract(newCoord.xy);\n\
|
||||
texCoord = clamp(u_texturePosSize.zw*texCoord, u_halfTexelSize, u_texturePosSize.zw-u_halfTexelSize);\n\
|
||||
vec4 color = texture2DGradARB(s_texture, u_texturePosSize.xy+texCoord, dFdx(texCoord), dFdy(texCoord));\n\
|
||||
#else\n\
|
||||
vec2 transitionBlend = fwidth(floor(newCoord.xy));\n\
|
||||
transitionBlend = fwidth(transitionBlend)+transitionBlend;\n\
|
||||
vec2 texCoord = mix(fract(newCoord.xy), abs(c_one-mod(newCoord.xy+c_one, c_two)), transitionBlend);\n\
|
||||
texCoord = clamp(u_texturePosSize.zw*texCoord, u_halfTexelSize, u_texturePosSize.zw-u_halfTexelSize);\n\
|
||||
vec4 color = texture2D(s_texture, u_texturePosSize.xy+texCoord);\n\
|
||||
#endif\n\
|
||||
\n\
|
||||
float shade = clamp((u_shade+max(u_visFactor*v_distance-0.5*u_shadeInterpolate,c_zero)), c_zero, u_numShades-c_one);\n\
|
||||
float shadeFrac = mod(shade, c_one);\n\
|
||||
float colorIndex = texture2D(s_palswap, u_palswapPos+u_palswapSize*vec2(color.r, floor(shade)/u_numShades)).r;\n\
|
||||
colorIndex = c_basepalOffset + c_basepalScale*colorIndex;\n\
|
||||
vec4 palettedColor = texture2D(s_palette, vec2(colorIndex, c_zero));\n\
|
||||
colorIndex = texture2D(s_palswap, u_palswapPos+u_palswapSize*vec2(color.r, (floor(shade)+c_one)/u_numShades)).r;\n\
|
||||
colorIndex = c_basepalOffset + c_basepalScale*colorIndex;\n\
|
||||
vec4 palettedColorNext = texture2D(s_palette, vec2(colorIndex, c_zero));\n\
|
||||
palettedColor.rgb = mix(palettedColor.rgb, palettedColorNext.rgb, shadeFrac*u_shadeInterpolate);\n\
|
||||
float fullbright = mix(u_usePalette*palettedColor.a, c_zero, u_useColorOnly);\n\
|
||||
palettedColor.a = c_one-floor(color.r);\n\
|
||||
color = mix(color, palettedColor, u_usePalette);\n\
|
||||
\n\
|
||||
color = mix(color, c_vec4_one, u_useColorOnly);\n\
|
||||
\n\
|
||||
// DEBUG \n\
|
||||
//color = texture2D(s_palswap, gl_TexCoord[0].xy);\n\
|
||||
//color = texture2D(s_palette, gl_TexCoord[0].xy);\n\
|
||||
//color = texture2D(s_texture, gl_TexCoord[0].yx);\n\
|
||||
\n\
|
||||
color.rgb = mix(v_color.rgb*color.rgb, color.rgb, fullbright);\n\
|
||||
\n\
|
||||
float fogEnabled = mix(u_fogEnabled, c_zero, u_usePalette);\n\
|
||||
fullbright = max(c_one-fogEnabled, fullbright);\n\
|
||||
float fogFactor = clamp((gl_Fog.end-gl_FogFragCoord)*gl_Fog.scale, fullbright, c_one);\n\
|
||||
//float fogFactor = clamp(gl_FogFragCoord, fullbright, c_one);\n\
|
||||
color.rgb = mix(gl_Fog.color.rgb, color.rgb, fogFactor);\n\
|
||||
\n\
|
||||
color.a *= v_color.a;\n\
|
||||
\n\
|
||||
color.rgb = pow(color.rgb, vec3(u_brightness));\n\
|
||||
\n\
|
||||
gl_FragData[0] = color;\n\
|
||||
}\n";
|
||||
const char* const POLYMOST1_EXTENDED_FRAGMENT_SHADER_CODE =
|
||||
"#version 110\n\
|
||||
#extension ARB_shader_texture_lod : enable\n\
|
||||
\n\
|
||||
//s_texture points to an indexed color texture\n\
|
||||
uniform sampler2D s_texture;\n\
|
||||
//s_palswap is the palette swap texture where u is the color index and v is the shade\n\
|
||||
uniform sampler2D s_palswap;\n\
|
||||
//s_palette is the base palette texture where u is the color index\n\
|
||||
uniform sampler2D s_palette;\n\
|
||||
\n\
|
||||
uniform sampler2D s_detail;\n\
|
||||
uniform sampler2D s_glow;\n\
|
||||
\n\
|
||||
//u_texturePosSize is the texture position & size packaged into a single vec4 as {pos.x, pos.y, size.x, size.y}\n\
|
||||
uniform vec4 u_texturePosSize;\n\
|
||||
uniform vec2 u_halfTexelSize;\n\
|
||||
uniform vec2 u_palswapPos;\n\
|
||||
uniform vec2 u_palswapSize;\n\
|
||||
\n\
|
||||
uniform float u_shade;\n\
|
||||
uniform float u_numShades;\n\
|
||||
uniform float u_visFactor;\n\
|
||||
uniform float u_fogEnabled;\n\
|
||||
\n\
|
||||
uniform float u_useColorOnly;\n\
|
||||
uniform float u_usePalette;\n\
|
||||
uniform float u_npotEmulation;\n\
|
||||
uniform float u_npotEmulationFactor;\n\
|
||||
uniform float u_npotEmulationXOffset;\n\
|
||||
uniform float u_brightness;\n\
|
||||
uniform float u_shadeInterpolate;\n\
|
||||
\n\
|
||||
uniform float u_useDetailMapping;\n\
|
||||
uniform float u_useGlowMapping;\n\
|
||||
\n\
|
||||
varying vec4 v_color;\n\
|
||||
varying float v_distance;\n\
|
||||
\n\
|
||||
const float c_basepalScale = 255.0/256.0;\n\
|
||||
const float c_basepalOffset = 0.5/256.0;\n\
|
||||
\n\
|
||||
const float c_zero = 0.0;\n\
|
||||
const float c_one = 1.0;\n\
|
||||
const float c_two = 2.0;\n\
|
||||
const vec4 c_vec4_one = vec4(c_one);\n\
|
||||
const float c_wrapThreshold = 0.9;\n\
|
||||
\n\
|
||||
void main()\n\
|
||||
{\n\
|
||||
float coordY = mix(gl_TexCoord[0].y,gl_TexCoord[0].x,u_usePalette);\n\
|
||||
float coordX = mix(gl_TexCoord[0].x,gl_TexCoord[0].y,u_usePalette);\n\
|
||||
float period = floor(coordY/u_npotEmulationFactor);\n\
|
||||
coordX += u_npotEmulationXOffset*floor(mod(coordY,u_npotEmulationFactor));\n\
|
||||
coordY = period+mod(coordY,u_npotEmulationFactor);\n\
|
||||
vec2 newCoord = mix(gl_TexCoord[0].xy,mix(vec2(coordX,coordY),vec2(coordY,coordX),u_usePalette),u_npotEmulation);\n\
|
||||
#ifdef GL_ARB_shader_texture_lod\n\
|
||||
vec2 texCoord = fract(newCoord.xy);\n\
|
||||
texCoord = clamp(u_texturePosSize.zw*texCoord, u_halfTexelSize, u_texturePosSize.zw-u_halfTexelSize);\n\
|
||||
vec4 color = texture2DGradARB(s_texture, u_texturePosSize.xy+texCoord, dFdx(texCoord), dFdy(texCoord));\n\
|
||||
#else\n\
|
||||
vec2 transitionBlend = fwidth(floor(newCoord.xy));\n\
|
||||
transitionBlend = fwidth(transitionBlend)+transitionBlend;\n\
|
||||
vec2 texCoord = mix(fract(newCoord.xy), abs(c_one-mod(newCoord.xy+c_one, c_two)), transitionBlend);\n\
|
||||
texCoord = clamp(u_texturePosSize.zw*texCoord, u_halfTexelSize, u_texturePosSize.zw-u_halfTexelSize);\n\
|
||||
vec4 color = texture2D(s_texture, u_texturePosSize.xy+texCoord);\n\
|
||||
#endif\n\
|
||||
\n\
|
||||
float shade = clamp((u_shade+max(u_visFactor*v_distance-0.5*u_shadeInterpolate,c_zero)), c_zero, u_numShades-c_one);\n\
|
||||
float shadeFrac = mod(shade, c_one);\n\
|
||||
float colorIndex = texture2D(s_palswap, u_palswapPos+u_palswapSize*vec2(color.r, floor(shade)/u_numShades)).r;\n\
|
||||
colorIndex = c_basepalOffset + c_basepalScale*colorIndex;\n\
|
||||
vec4 palettedColor = texture2D(s_palette, vec2(colorIndex, c_zero));\n\
|
||||
colorIndex = texture2D(s_palswap, u_palswapPos+u_palswapSize*vec2(color.r, (floor(shade)+c_one)/u_numShades)).r;\n\
|
||||
colorIndex = c_basepalOffset + c_basepalScale*colorIndex;\n\
|
||||
vec4 palettedColorNext = texture2D(s_palette, vec2(colorIndex, c_zero));\n\
|
||||
palettedColor.rgb = mix(palettedColor.rgb, palettedColorNext.rgb, shadeFrac*u_shadeInterpolate);\n\
|
||||
float fullbright = mix(u_usePalette*palettedColor.a, c_zero, u_useColorOnly);\n\
|
||||
palettedColor.a = c_one-floor(color.r);\n\
|
||||
color = mix(color, palettedColor, u_usePalette);\n\
|
||||
\n\
|
||||
vec4 detailColor = texture2D(s_detail, newCoord);\n\
|
||||
detailColor = mix(c_vec4_one, 2.0*detailColor, u_useDetailMapping*detailColor.a);\n\
|
||||
color.rgb *= detailColor.rgb;\n\
|
||||
\n\
|
||||
color = mix(color, c_vec4_one, u_useColorOnly);\n\
|
||||
\n\
|
||||
// DEBUG \n\
|
||||
//color = texture2D(s_palswap, gl_TexCoord[0].xy);\n\
|
||||
//color = texture2D(s_palette, gl_TexCoord[0].xy);\n\
|
||||
//color = texture2D(s_texture, gl_TexCoord[0].yx);\n\
|
||||
\n\
|
||||
color.rgb = mix(v_color.rgb*color.rgb, color.rgb, fullbright);\n\
|
||||
\n\
|
||||
float fogEnabled = mix(u_fogEnabled, c_zero, u_usePalette);\n\
|
||||
fullbright = max(c_one-fogEnabled, fullbright);\n\
|
||||
float fogFactor = clamp((gl_Fog.end-gl_FogFragCoord)*gl_Fog.scale, fullbright, c_one);\n\
|
||||
//float fogFactor = clamp(gl_FogFragCoord, fullbright, c_one);\n\
|
||||
color.rgb = mix(gl_Fog.color.rgb, color.rgb, fogFactor);\n\
|
||||
\n\
|
||||
vec4 glowColor = texture2D(s_glow, newCoord);\n\
|
||||
color.rgb = mix(color.rgb, glowColor.rgb, u_useGlowMapping*glowColor.a*(c_one-u_useColorOnly));\n\
|
||||
\n\
|
||||
color.a *= v_color.a;\n\
|
||||
\n\
|
||||
color.rgb = pow(color.rgb, vec3(u_brightness));\n\
|
||||
\n\
|
||||
gl_FragData[0] = color;\n\
|
||||
}\n";
|
||||
|
||||
polymost1BasicShaderProgramID = glCreateProgram();
|
||||
GLuint polymost1BasicVertexShaderID = polymost2_compileShader(GL_VERTEX_SHADER, POLYMOST1_BASIC_VERTEX_SHADER_CODE);
|
||||
GLuint polymost1BasicFragmentShaderID = polymost2_compileShader(GL_FRAGMENT_SHADER, POLYMOST1_BASIC_FRAGMENT_SHADER_CODE);
|
||||
glAttachShader(polymost1BasicShaderProgramID, polymost1BasicVertexShaderID);
|
||||
glAttachShader(polymost1BasicShaderProgramID, polymost1BasicFragmentShaderID);
|
||||
glLinkProgram(polymost1BasicShaderProgramID);
|
||||
#include "generated/polymost1Vert.glsl.h"
|
||||
#include "generated/polymost1Frag.glsl.h"
|
||||
|
||||
polymost1ExtendedShaderProgramID = glCreateProgram();
|
||||
GLuint polymost1ExtendedFragmentShaderID = polymost2_compileShader(GL_FRAGMENT_SHADER, POLYMOST1_EXTENDED_FRAGMENT_SHADER_CODE);
|
||||
GLuint polymost1BasicVertexShaderID = polymost2_compileShader(GL_VERTEX_SHADER, polymost1Vert, 0);
|
||||
GLuint polymost1ExtendedFragmentShaderID = polymost2_compileShader(GL_FRAGMENT_SHADER, polymost1Frag, 0);
|
||||
glAttachShader(polymost1ExtendedShaderProgramID, polymost1BasicVertexShaderID);
|
||||
glAttachShader(polymost1ExtendedShaderProgramID, polymost1ExtendedFragmentShaderID);
|
||||
glLinkProgram(polymost1ExtendedShaderProgramID);
|
||||
|
||||
int polymost1BasicFragLen = strlen(polymost1Frag);
|
||||
char* polymost1BasicFrag = (char*) malloc(polymost1BasicFragLen);
|
||||
memcpy(polymost1BasicFrag, polymost1Frag, polymost1BasicFragLen);
|
||||
char* extDefineSubstr = strstr(polymost1BasicFrag, " #define POLYMOST1_EXTENDED");
|
||||
if (extDefineSubstr)
|
||||
{
|
||||
//Disable extensions for basic fragment shader
|
||||
extDefineSubstr[0] = '/';
|
||||
extDefineSubstr[1] = '/';
|
||||
}
|
||||
polymost1BasicShaderProgramID = glCreateProgram();
|
||||
GLuint polymost1BasicFragmentShaderID = polymost2_compileShader(GL_FRAGMENT_SHADER, polymost1BasicFrag, polymost1BasicFragLen);
|
||||
glAttachShader(polymost1BasicShaderProgramID, polymost1BasicVertexShaderID);
|
||||
glAttachShader(polymost1BasicShaderProgramID, polymost1BasicFragmentShaderID);
|
||||
glLinkProgram(polymost1BasicShaderProgramID);
|
||||
free(polymost1BasicFrag);
|
||||
polymost1BasicFrag = 0;
|
||||
|
||||
// set defaults
|
||||
polymost_setCurrentShaderProgram(polymost1ExtendedShaderProgramID);
|
||||
glUniform1i(polymost1TexSamplerLoc, 0);
|
||||
|
|
116
source/build/src/polymost1Frag.glsl
Normal file
116
source/build/src/polymost1Frag.glsl
Normal file
|
@ -0,0 +1,116 @@
|
|||
#version 110
|
||||
#extension ARB_shader_texture_lod : enable
|
||||
|
||||
//include an additional space here so that we can programmatically search for and disable this preprocessor definition easily
|
||||
#define POLYMOST1_EXTENDED
|
||||
|
||||
//s_texture points to an indexed color texture
|
||||
uniform sampler2D s_texture;
|
||||
//s_palswap is the palette swap texture where u is the color index and v is the shade
|
||||
uniform sampler2D s_palswap;
|
||||
//s_palette is the base palette texture where u is the color index
|
||||
uniform sampler2D s_palette;
|
||||
|
||||
#ifdef POLYMOST1_EXTENDED
|
||||
uniform sampler2D s_detail;
|
||||
uniform sampler2D s_glow;
|
||||
#endif
|
||||
|
||||
//u_texturePosSize is the texture position & size packaged into a single vec4 as {pos.x, pos.y, size.x, size.y}
|
||||
uniform vec4 u_texturePosSize;
|
||||
uniform vec2 u_halfTexelSize;
|
||||
uniform vec2 u_palswapPos;
|
||||
uniform vec2 u_palswapSize;
|
||||
|
||||
uniform float u_shade;
|
||||
uniform float u_numShades;
|
||||
uniform float u_visFactor;
|
||||
uniform float u_fogEnabled;
|
||||
|
||||
uniform float u_useColorOnly;
|
||||
uniform float u_usePalette;
|
||||
uniform float u_npotEmulation;
|
||||
uniform float u_npotEmulationFactor;
|
||||
uniform float u_npotEmulationXOffset;
|
||||
uniform float u_shadeInterpolate;
|
||||
|
||||
#ifdef POLYMOST1_EXTENDED
|
||||
uniform float u_useDetailMapping;
|
||||
uniform float u_useGlowMapping;
|
||||
#endif
|
||||
|
||||
varying vec4 v_color;
|
||||
varying float v_distance;
|
||||
|
||||
const float c_basepalScale = 255.0/256.0;
|
||||
const float c_basepalOffset = 0.5/256.0;
|
||||
|
||||
const float c_zero = 0.0;
|
||||
const float c_one = 1.0;
|
||||
const float c_two = 2.0;
|
||||
const vec4 c_vec4_one = vec4(c_one);
|
||||
const float c_wrapThreshold = 0.9;
|
||||
|
||||
void main()
|
||||
{
|
||||
float coordY = mix(gl_TexCoord[0].y,gl_TexCoord[0].x,u_usePalette);
|
||||
float coordX = mix(gl_TexCoord[0].x,gl_TexCoord[0].y,u_usePalette);
|
||||
float period = floor(coordY/u_npotEmulationFactor);
|
||||
coordX += u_npotEmulationXOffset*floor(mod(coordY,u_npotEmulationFactor));
|
||||
coordY = period+mod(coordY,u_npotEmulationFactor);
|
||||
vec2 newCoord = mix(gl_TexCoord[0].xy,mix(vec2(coordX,coordY),vec2(coordY,coordX),u_usePalette),u_npotEmulation);
|
||||
#ifdef GL_ARB_shader_texture_lod
|
||||
vec2 texCoord = fract(newCoord.xy);
|
||||
texCoord = clamp(u_texturePosSize.zw*texCoord, u_halfTexelSize, u_texturePosSize.zw-u_halfTexelSize);
|
||||
vec4 color = texture2DGradARB(s_texture, u_texturePosSize.xy+texCoord, dFdx(texCoord), dFdy(texCoord));
|
||||
#else
|
||||
vec2 transitionBlend = fwidth(floor(newCoord.xy));
|
||||
transitionBlend = fwidth(transitionBlend)+transitionBlend;
|
||||
vec2 texCoord = mix(fract(newCoord.xy), abs(c_one-mod(newCoord.xy+c_one, c_two)), transitionBlend);
|
||||
texCoord = clamp(u_texturePosSize.zw*texCoord, u_halfTexelSize, u_texturePosSize.zw-u_halfTexelSize);
|
||||
vec4 color = texture2D(s_texture, u_texturePosSize.xy+texCoord);
|
||||
#endif
|
||||
|
||||
float shade = clamp((u_shade+max(u_visFactor*v_distance-0.5*u_shadeInterpolate,c_zero)), c_zero, u_numShades-c_one);
|
||||
float shadeFrac = mod(shade, c_one);
|
||||
float colorIndex = texture2D(s_palswap, u_palswapPos+u_palswapSize*vec2(color.r, floor(shade)/u_numShades)).r;
|
||||
colorIndex = c_basepalOffset + c_basepalScale*colorIndex;
|
||||
vec4 palettedColor = texture2D(s_palette, vec2(colorIndex, c_zero));
|
||||
colorIndex = texture2D(s_palswap, u_palswapPos+u_palswapSize*vec2(color.r, (floor(shade)+c_one)/u_numShades)).r;
|
||||
colorIndex = c_basepalOffset + c_basepalScale*colorIndex;
|
||||
vec4 palettedColorNext = texture2D(s_palette, vec2(colorIndex, c_zero));
|
||||
palettedColor.rgb = mix(palettedColor.rgb, palettedColorNext.rgb, shadeFrac*u_shadeInterpolate);
|
||||
float fullbright = mix(u_usePalette*palettedColor.a, c_zero, u_useColorOnly);
|
||||
palettedColor.a = c_one-floor(color.r);
|
||||
color = mix(color, palettedColor, u_usePalette);
|
||||
|
||||
#ifdef POLYMOST1_EXTENDED
|
||||
vec4 detailColor = texture2D(s_detail, gl_TexCoord[3].xy);
|
||||
detailColor = mix(c_vec4_one, 2.0*detailColor, u_useDetailMapping*detailColor.a);
|
||||
color.rgb *= detailColor.rgb;
|
||||
#endif
|
||||
|
||||
color = mix(color, c_vec4_one, u_useColorOnly);
|
||||
|
||||
// DEBUG
|
||||
//color = texture2D(s_palswap, gl_TexCoord[0].xy);
|
||||
//color = texture2D(s_palette, gl_TexCoord[0].xy);
|
||||
//color = texture2D(s_texture, gl_TexCoord[0].yx);
|
||||
|
||||
color.rgb = mix(v_color.rgb*color.rgb, color.rgb, fullbright);
|
||||
|
||||
float fogEnabled = mix(u_fogEnabled, c_zero, u_usePalette);
|
||||
fullbright = max(c_one-fogEnabled, fullbright);
|
||||
float fogFactor = clamp((gl_Fog.end-gl_FogFragCoord)*gl_Fog.scale, fullbright, c_one);
|
||||
//float fogFactor = clamp(gl_FogFragCoord, fullbright, c_one);
|
||||
color.rgb = mix(gl_Fog.color.rgb, color.rgb, fogFactor);
|
||||
|
||||
#ifdef POLYMOST1_EXTENDED
|
||||
vec4 glowColor = texture2D(s_glow, gl_TexCoord[4].xy);
|
||||
color.rgb = mix(color.rgb, glowColor.rgb, u_useGlowMapping*glowColor.a*(c_one-u_useColorOnly));
|
||||
#endif
|
||||
|
||||
color.a *= v_color.a;
|
||||
|
||||
gl_FragData[0] = color;
|
||||
}
|
33
source/build/src/polymost1Vert.glsl
Normal file
33
source/build/src/polymost1Vert.glsl
Normal file
|
@ -0,0 +1,33 @@
|
|||
#version 110
|
||||
|
||||
varying vec4 v_color;
|
||||
varying float v_distance;
|
||||
|
||||
//u_texturePosSize is the texture position & size packaged into a single vec4 as {pos.x, pos.y, size.x, size.y}
|
||||
uniform vec4 u_texturePosSize;
|
||||
uniform float u_usePalette;
|
||||
uniform mat4 u_rotMatrix;
|
||||
|
||||
const float c_zero = 0.0;
|
||||
const float c_one = 1.0;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 vertex = u_rotMatrix * gl_Vertex;
|
||||
vec4 eyeCoordPosition = gl_ModelViewMatrix * vertex;
|
||||
gl_Position = gl_ModelViewProjectionMatrix * vertex;
|
||||
|
||||
eyeCoordPosition.xyz /= eyeCoordPosition.w;
|
||||
|
||||
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
|
||||
gl_TexCoord[0] = mix(gl_TexCoord[0].xyzw, gl_TexCoord[0].yxzw, u_usePalette);
|
||||
|
||||
gl_TexCoord[3] = gl_TextureMatrix[3] * gl_MultiTexCoord3;
|
||||
gl_TexCoord[4] = gl_TextureMatrix[4] * gl_MultiTexCoord4;
|
||||
|
||||
gl_FogFragCoord = abs(eyeCoordPosition.z);
|
||||
//gl_FogFragCoord = clamp((gl_Fog.end-abs(eyeCoordPosition.z))*gl_Fog.scale, c_zero, c_one);
|
||||
|
||||
v_color = gl_Color;
|
||||
v_distance = gl_Vertex.z;
|
||||
}
|
Loading…
Reference in a new issue