mirror of
https://github.com/DrBeef/ioq3quest.git
synced 2025-04-18 06:11:18 +00:00
SpaceWarp force motion vector shader
This commit is contained in:
parent
433d51ffe9
commit
6542b604be
9 changed files with 202 additions and 8 deletions
2
Makefile
2
Makefile
|
@ -1893,6 +1893,8 @@ Q3R2STRINGOBJ = \
|
|||
$(B)/renderergles3/glsl/generic_vp.o \
|
||||
$(B)/renderergles3/glsl/lightall_fp.o \
|
||||
$(B)/renderergles3/glsl/lightall_vp.o \
|
||||
$(B)/renderergles3/glsl/motionvector_fp.o \
|
||||
$(B)/renderergles3/glsl/motionvector_vp.o \
|
||||
$(B)/renderergles3/glsl/pshadow_fp.o \
|
||||
$(B)/renderergles3/glsl/pshadow_vp.o \
|
||||
$(B)/renderergles3/glsl/shadowfill_fp.o \
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
uniform sampler2D u_DiffuseMap;
|
||||
|
||||
uniform int u_AlphaTest;
|
||||
|
||||
varying vec2 var_DiffuseTex;
|
||||
|
||||
varying vec4 var_Color;
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 color = texture2D(u_DiffuseMap, var_DiffuseTex);
|
||||
|
||||
float alpha = color.a * var_Color.a;
|
||||
if (u_AlphaTest == 1)
|
||||
{
|
||||
if (alpha == 0.0)
|
||||
discard;
|
||||
}
|
||||
else if (u_AlphaTest == 2)
|
||||
{
|
||||
if (alpha >= 0.5)
|
||||
discard;
|
||||
}
|
||||
else if (u_AlphaTest == 3)
|
||||
{
|
||||
if (alpha < 0.5)
|
||||
discard;
|
||||
}
|
||||
|
||||
//TODO:implement motion vector
|
||||
gl_FragColor.rgb = var_Color.rgb;
|
||||
gl_FragColor.a = alpha;
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
attribute vec3 attr_Position;
|
||||
attribute vec3 attr_Normal;
|
||||
|
||||
attribute vec4 attr_Color;
|
||||
attribute vec4 attr_TexCoord0;
|
||||
|
||||
uniform mat4 u_ModelMatrix;
|
||||
|
||||
|
||||
uniform vec4 u_BaseColor;
|
||||
uniform vec4 u_VertColor;
|
||||
|
||||
// Uniforms
|
||||
layout(shared) uniform ViewMatrices
|
||||
{
|
||||
uniform mat4 u_ViewMatrices[NUM_VIEWS];
|
||||
};
|
||||
layout(shared) uniform ProjectionMatrix
|
||||
{
|
||||
uniform mat4 u_ProjectionMatrix;
|
||||
};
|
||||
|
||||
varying vec2 var_DiffuseTex;
|
||||
varying vec4 var_Color;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 position = attr_Position;
|
||||
vec3 normal = attr_Normal;
|
||||
|
||||
gl_Position = u_ProjectionMatrix * (u_ViewMatrices[gl_ViewID_OVR] * (u_ModelMatrix * vec4(position, 1.0)));
|
||||
|
||||
var_DiffuseTex = attr_TexCoord0.st;
|
||||
var_Color = u_VertColor * attr_Color + u_BaseColor;
|
||||
var_Color.rgb = abs(normal.xyz);
|
||||
}
|
|
@ -43,6 +43,8 @@ extern const char *fallbackShader_generic_vp;
|
|||
extern const char *fallbackShader_generic_fp;
|
||||
extern const char *fallbackShader_lightall_vp;
|
||||
extern const char *fallbackShader_lightall_fp;
|
||||
extern const char *fallbackShader_motionvector_vp;
|
||||
extern const char *fallbackShader_motionvector_fp;
|
||||
extern const char *fallbackShader_pshadow_vp;
|
||||
extern const char *fallbackShader_pshadow_fp;
|
||||
extern const char *fallbackShader_shadowfill_vp;
|
||||
|
@ -179,6 +181,19 @@ typedef enum
|
|||
}
|
||||
glslPrintLog_t;
|
||||
|
||||
/*
|
||||
====================
|
||||
GLSL_OverrideShader
|
||||
====================
|
||||
*/
|
||||
shaderProgram_t* GLSL_OverrideShader(shaderProgram_t * program)
|
||||
{
|
||||
if( Cvar_VariableValue( "vr_motionVector" ) == 1)
|
||||
{
|
||||
return &tr.motionVectorShader;
|
||||
}
|
||||
return program;
|
||||
}
|
||||
|
||||
/*
|
||||
====================
|
||||
|
@ -848,7 +863,9 @@ void GLSL_FinishGPUShader(shaderProgram_t *program)
|
|||
|
||||
void GLSL_SetUniformInt(shaderProgram_t *program, int uniformNum, GLint value)
|
||||
{
|
||||
program = GLSL_OverrideShader(program);
|
||||
GLint *uniforms = program->uniforms;
|
||||
#ifdef GLSL_CACHE
|
||||
GLint *compare = (GLint *)(program->uniformBuffer + program->uniformBufferOffsets[uniformNum]);
|
||||
|
||||
if (uniforms[uniformNum] == -1)
|
||||
|
@ -866,13 +883,15 @@ void GLSL_SetUniformInt(shaderProgram_t *program, int uniformNum, GLint value)
|
|||
}
|
||||
|
||||
*compare = value;
|
||||
|
||||
#endif
|
||||
qglProgramUniform1iEXT(program->program, uniforms[uniformNum], value);
|
||||
}
|
||||
|
||||
void GLSL_SetUniformFloat(shaderProgram_t *program, int uniformNum, GLfloat value)
|
||||
{
|
||||
program = GLSL_OverrideShader(program);
|
||||
GLint *uniforms = program->uniforms;
|
||||
#ifdef GLSL_CACHE
|
||||
GLfloat *compare = (GLfloat *)(program->uniformBuffer + program->uniformBufferOffsets[uniformNum]);
|
||||
|
||||
if (uniforms[uniformNum] == -1)
|
||||
|
@ -890,13 +909,15 @@ void GLSL_SetUniformFloat(shaderProgram_t *program, int uniformNum, GLfloat valu
|
|||
}
|
||||
|
||||
*compare = value;
|
||||
|
||||
#endif
|
||||
qglProgramUniform1fEXT(program->program, uniforms[uniformNum], value);
|
||||
}
|
||||
|
||||
void GLSL_SetUniformVec2(shaderProgram_t *program, int uniformNum, const vec2_t v)
|
||||
{
|
||||
program = GLSL_OverrideShader(program);
|
||||
GLint *uniforms = program->uniforms;
|
||||
#ifdef GLSL_CACHE
|
||||
vec_t *compare = (float *)(program->uniformBuffer + program->uniformBufferOffsets[uniformNum]);
|
||||
|
||||
if (uniforms[uniformNum] == -1)
|
||||
|
@ -915,13 +936,15 @@ void GLSL_SetUniformVec2(shaderProgram_t *program, int uniformNum, const vec2_t
|
|||
|
||||
compare[0] = v[0];
|
||||
compare[1] = v[1];
|
||||
|
||||
#endif
|
||||
qglProgramUniform2fEXT(program->program, uniforms[uniformNum], v[0], v[1]);
|
||||
}
|
||||
|
||||
void GLSL_SetUniformVec3(shaderProgram_t *program, int uniformNum, const vec3_t v)
|
||||
{
|
||||
program = GLSL_OverrideShader(program);
|
||||
GLint *uniforms = program->uniforms;
|
||||
#ifdef GLSL_CACHE
|
||||
vec_t *compare = (float *)(program->uniformBuffer + program->uniformBufferOffsets[uniformNum]);
|
||||
|
||||
if (uniforms[uniformNum] == -1)
|
||||
|
@ -939,13 +962,15 @@ void GLSL_SetUniformVec3(shaderProgram_t *program, int uniformNum, const vec3_t
|
|||
}
|
||||
|
||||
VectorCopy(v, compare);
|
||||
|
||||
#endif
|
||||
qglProgramUniform3fEXT(program->program, uniforms[uniformNum], v[0], v[1], v[2]);
|
||||
}
|
||||
|
||||
void GLSL_SetUniformVec4(shaderProgram_t *program, int uniformNum, const vec4_t v)
|
||||
{
|
||||
program = GLSL_OverrideShader(program);
|
||||
GLint *uniforms = program->uniforms;
|
||||
#ifdef GLSL_CACHE
|
||||
vec_t *compare = (float *)(program->uniformBuffer + program->uniformBufferOffsets[uniformNum]);
|
||||
|
||||
if (uniforms[uniformNum] == -1)
|
||||
|
@ -963,13 +988,15 @@ void GLSL_SetUniformVec4(shaderProgram_t *program, int uniformNum, const vec4_t
|
|||
}
|
||||
|
||||
VectorCopy4(v, compare);
|
||||
|
||||
#endif
|
||||
qglProgramUniform4fEXT(program->program, uniforms[uniformNum], v[0], v[1], v[2], v[3]);
|
||||
}
|
||||
|
||||
void GLSL_SetUniformFloat5(shaderProgram_t *program, int uniformNum, const vec5_t v)
|
||||
{
|
||||
program = GLSL_OverrideShader(program);
|
||||
GLint *uniforms = program->uniforms;
|
||||
#ifdef GLSL_CACHE
|
||||
vec_t *compare = (float *)(program->uniformBuffer + program->uniformBufferOffsets[uniformNum]);
|
||||
|
||||
if (uniforms[uniformNum] == -1)
|
||||
|
@ -987,13 +1014,15 @@ void GLSL_SetUniformFloat5(shaderProgram_t *program, int uniformNum, const vec5_
|
|||
}
|
||||
|
||||
VectorCopy5(v, compare);
|
||||
|
||||
#endif
|
||||
qglProgramUniform1fvEXT(program->program, uniforms[uniformNum], 5, v);
|
||||
}
|
||||
|
||||
void GLSL_SetUniformMat4(shaderProgram_t *program, int uniformNum, const mat4_t matrix)
|
||||
{
|
||||
program = GLSL_OverrideShader(program);
|
||||
GLint *uniforms = program->uniforms;
|
||||
#ifdef GLSL_CACHE
|
||||
vec_t *compare = (float *)(program->uniformBuffer + program->uniformBufferOffsets[uniformNum]);
|
||||
|
||||
if (uniforms[uniformNum] == -1)
|
||||
|
@ -1011,12 +1040,13 @@ void GLSL_SetUniformMat4(shaderProgram_t *program, int uniformNum, const mat4_t
|
|||
}
|
||||
|
||||
Mat4Copy(matrix, compare);
|
||||
|
||||
#endif
|
||||
qglProgramUniformMatrix4fvEXT(program->program, uniforms[uniformNum], 1, GL_FALSE, matrix);
|
||||
}
|
||||
|
||||
void GLSL_SetUniformMat4BoneMatrix(shaderProgram_t *program, int uniformNum, /*const*/ mat4_t *matrix, int numMatricies)
|
||||
{
|
||||
program = GLSL_OverrideShader(program);
|
||||
GLint *uniforms = program->uniforms;
|
||||
vec_t *compare = (float *)(program->uniformBuffer + program->uniformBufferOffsets[uniformNum]);
|
||||
|
||||
|
@ -1490,6 +1520,22 @@ void GLSL_InitGPUShaders(void)
|
|||
|
||||
numEtcShaders++;
|
||||
|
||||
attribs = ATTR_POSITION | ATTR_TEXCOORD;
|
||||
extradefines[0] = '\0';
|
||||
|
||||
if (!GLSL_InitGPUShader(&tr.motionVectorShader, "motionvector", attribs, qtrue, extradefines, qtrue, fallbackShader_motionvector_vp, fallbackShader_motionvector_fp))
|
||||
{
|
||||
ri.Error(ERR_FATAL, "Could not load bokeh shader!");
|
||||
}
|
||||
|
||||
GLSL_InitUniforms(&tr.motionVectorShader);
|
||||
|
||||
GLSL_SetUniformInt(&tr.motionVectorShader, UNIFORM_TEXTUREMAP, TB_DIFFUSEMAP);
|
||||
|
||||
GLSL_FinishGPUShader(&tr.motionVectorShader);
|
||||
|
||||
numEtcShaders++;
|
||||
|
||||
|
||||
attribs = ATTR_POSITION | ATTR_TEXCOORD;
|
||||
extradefines[0] = '\0';
|
||||
|
@ -1730,6 +1776,7 @@ void GLSL_PrepareUniformBuffers(void)
|
|||
|
||||
void GLSL_BindProgram(shaderProgram_t * program)
|
||||
{
|
||||
program = GLSL_OverrideShader(program);
|
||||
GLuint programObject = program ? program->program : 0;
|
||||
char *name = program ? program->name : "NULL";
|
||||
|
||||
|
@ -1775,6 +1822,7 @@ static GLuint GLSL_CalculateProjection() {
|
|||
|
||||
void GLSL_BindBuffers( shaderProgram_t * program )
|
||||
{
|
||||
program = GLSL_OverrideShader(program);
|
||||
GLuint projection = GLSL_CalculateProjection();
|
||||
qglBindBufferBase(
|
||||
GL_UNIFORM_BUFFER,
|
||||
|
|
|
@ -1619,6 +1619,7 @@ typedef struct {
|
|||
shaderProgram_t ssaoShader;
|
||||
shaderProgram_t depthBlurShader[4];
|
||||
shaderProgram_t testcubeShader;
|
||||
shaderProgram_t motionVectorShader;
|
||||
|
||||
|
||||
// -----------------------------------------
|
||||
|
|
|
@ -49,6 +49,7 @@ cvar_t *vr_goreLevel = NULL;
|
|||
cvar_t *vr_hudDrawStatus = NULL;
|
||||
cvar_t *vr_showConsoleMessages = NULL;
|
||||
cvar_t *vr_spacewarp = NULL;
|
||||
cvar_t *vr_motionvector = NULL;
|
||||
|
||||
engine_t* VR_Init( ovrJava java )
|
||||
{
|
||||
|
@ -169,6 +170,7 @@ void VR_InitCvars( void )
|
|||
vr_hudDrawStatus = Cvar_Get ("vr_hudDrawStatus", "1", CVAR_ARCHIVE); // 0 - no hud, 1 - in-world hud, 2 - performance (static HUD)
|
||||
vr_showConsoleMessages = Cvar_Get ("vr_showConsoleMessages", "1", CVAR_ARCHIVE);
|
||||
vr_spacewarp = Cvar_Get ("vr_spaceWarp", "0", CVAR_ARCHIVE);
|
||||
vr_motionvector = Cvar_Get ("vr_motionVector", "0", CVAR_ARCHIVE);
|
||||
|
||||
// Values are: scale,right,up,forward,pitch,yaw,roll
|
||||
// VALUES PROVIDED BY SkillFur - Thank-you!
|
||||
|
|
|
@ -504,8 +504,9 @@ void VR_DrawFrame( engine_t* engine ) {
|
|||
|
||||
VR_RenderScene( engine, fov, qfalse );
|
||||
if (vr_spacewarp->integer) {
|
||||
//TODO: force motion vector shader
|
||||
Cvar_SetValue( "vr_motionVector", 1 );
|
||||
VR_RenderScene( engine, fov, qtrue );
|
||||
Cvar_SetValue( "vr_motionVector", 0 );
|
||||
}
|
||||
|
||||
for (int eye = 0; eye < ovrMaxNumEyes; eye++) {
|
||||
|
|
34
android/app/src/main/pakQ3Q/glsl/motionvector_fp.glsl
Normal file
34
android/app/src/main/pakQ3Q/glsl/motionvector_fp.glsl
Normal file
|
@ -0,0 +1,34 @@
|
|||
uniform sampler2D u_DiffuseMap;
|
||||
|
||||
uniform int u_AlphaTest;
|
||||
|
||||
varying vec2 var_DiffuseTex;
|
||||
|
||||
varying vec4 var_Color;
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 color = texture2D(u_DiffuseMap, var_DiffuseTex);
|
||||
|
||||
float alpha = color.a * var_Color.a;
|
||||
if (u_AlphaTest == 1)
|
||||
{
|
||||
if (alpha == 0.0)
|
||||
discard;
|
||||
}
|
||||
else if (u_AlphaTest == 2)
|
||||
{
|
||||
if (alpha >= 0.5)
|
||||
discard;
|
||||
}
|
||||
else if (u_AlphaTest == 3)
|
||||
{
|
||||
if (alpha < 0.5)
|
||||
discard;
|
||||
}
|
||||
|
||||
//TODO:implement motion vector
|
||||
gl_FragColor.rgb = var_Color.rgb;
|
||||
gl_FragColor.a = alpha;
|
||||
}
|
36
android/app/src/main/pakQ3Q/glsl/motionvector_vp.glsl
Normal file
36
android/app/src/main/pakQ3Q/glsl/motionvector_vp.glsl
Normal file
|
@ -0,0 +1,36 @@
|
|||
attribute vec3 attr_Position;
|
||||
attribute vec3 attr_Normal;
|
||||
|
||||
attribute vec4 attr_Color;
|
||||
attribute vec4 attr_TexCoord0;
|
||||
|
||||
uniform mat4 u_ModelMatrix;
|
||||
|
||||
|
||||
uniform vec4 u_BaseColor;
|
||||
uniform vec4 u_VertColor;
|
||||
|
||||
// Uniforms
|
||||
layout(shared) uniform ViewMatrices
|
||||
{
|
||||
uniform mat4 u_ViewMatrices[NUM_VIEWS];
|
||||
};
|
||||
layout(shared) uniform ProjectionMatrix
|
||||
{
|
||||
uniform mat4 u_ProjectionMatrix;
|
||||
};
|
||||
|
||||
varying vec2 var_DiffuseTex;
|
||||
varying vec4 var_Color;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 position = attr_Position;
|
||||
vec3 normal = attr_Normal;
|
||||
|
||||
gl_Position = u_ProjectionMatrix * (u_ViewMatrices[gl_ViewID_OVR] * (u_ModelMatrix * vec4(position, 1.0)));
|
||||
|
||||
var_DiffuseTex = attr_TexCoord0.st;
|
||||
var_Color = u_VertColor * attr_Color + u_BaseColor;
|
||||
var_Color.rgb = abs(normal.xyz);
|
||||
}
|
Loading…
Reference in a new issue