Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'sprites' into for-0.38.0
Conflicts:
	src/engine/renderer/tr_local.h
	src/engine/renderer/tr_shade_calc.cpp
	src/engine/renderer/tr_shadows.cpp
  • Loading branch information
gimhael committed Apr 4, 2015
2 parents a0719f7 + ca8eff2 commit ceb650f
Show file tree
Hide file tree
Showing 39 changed files with 1,223 additions and 1,518 deletions.
1 change: 0 additions & 1 deletion CMakeLists.txt
Expand Up @@ -629,7 +629,6 @@ set( RENDERERLIST
${ENGINE_DIR}/renderer/tr_shade.cpp
${ENGINE_DIR}/renderer/tr_shade_calc.cpp
${ENGINE_DIR}/renderer/tr_shader.cpp
${ENGINE_DIR}/renderer/tr_shadows.cpp
${ENGINE_DIR}/renderer/tr_skin.cpp
${ENGINE_DIR}/renderer/tr_sky.cpp
${ENGINE_DIR}/renderer/tr_surface.cpp
Expand Down
164 changes: 86 additions & 78 deletions main/glsl/deformVertexes_vp.glsl
Expand Up @@ -22,7 +22,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
// deformVertexes_vp.glsl - Quake 3 deformVertexes semantic


uniform float u_DeformParms[MAX_SHADER_DEFORM_PARMS];
uniform vec4 u_DeformParms[MAX_SHADER_DEFORM_PARMS];

float triangle(float x)
{
Expand All @@ -34,92 +34,100 @@ float sawtooth(float x)
return fract( x );
}

/*
define WAVEVALUE( table, base, amplitude, phase, freq ) \
((base) + table[ Q_ftol( ( ( (phase) + backEnd.refdef.floatTime * (freq) ) * FUNCTABLE_SIZE ) ) & FUNCTABLE_MASK ] * (amplitude))
*/
// --------------------------------------------------------------------
ivec4 permute(ivec4 x) {
return ((62 * x + 1905) * x) % 961;
}

float WaveValue(float func, float base, float amplitude, float phase, float freq, float time)
{
float value = phase + ( time * freq );

float d;

if(func == GF_SIN)
d = sin(value * 2.0 * M_PI) ;
else if(func == GF_SQUARE)
d = sign(sin(value * 2.0 * M_PI));
else if(func == GF_TRIANGLE)
d = triangle(value);
else if(func == GF_SAWTOOTH)
d = sawtooth(value);
else
d = 1.0 - sawtooth(value);

return base + d * amplitude;
float grad(int idx, vec4 p) {
int i = idx & 31;
float u = i < 24 ? p.x : p.y;
float v = i < 16 ? p.y : p.z;
float w = i < 8 ? p.z : p.w;

return ((i & 4) != 0 ? -u : u)
+ ((i & 2) != 0 ? -v : v)
+ ((i & 1) != 0 ? -w : w);
}

vec4 fade(in vec4 t) {
return t * t * t * (t * (t * 6.0 - 15.0) + 10.0);
}

vec4 pnoise(vec4 v) {
ivec4 iv = ivec4(floor(v));
vec4 rv = fract(v);
vec4 f[2];

f[0] = fade(rv);
f[1] = 1.0 - f[0];

vec4 value = vec4(0.0);
for(int idx = 0; idx < 16; idx++) {
ivec4 offs = ivec4( idx & 1, (idx & 2) >> 1, (idx & 4) >> 2, (idx & 8) >> 3 );
float w = f[offs.x].x * f[offs.y].y * f[offs.z].z * f[offs.w].w;
ivec4 p = permute(iv + offs);

value.x += w * grad(p.x, rv);
value.y += w * grad(p.y, rv);
value.z += w * grad(p.z, rv);
value.w += w * grad(p.w, rv);
}
return value;
}
// --------------------------------------------------------------------

void DeformVertex( inout vec4 pos,
inout vec3 normal,
inout vec2 st,
inout vec4 color,
in float time)
{
vec4 work = vec4(0.0);

int i, deformOfs = 0;
int numDeforms = int(u_DeformParms[deformOfs++]);

for(i = 0; i < numDeforms; i++)
for(int deformOfs = 0; deformOfs < MAX_SHADER_DEFORM_PARMS; deformOfs++)
{
int deformGen = int(u_DeformParms[deformOfs++]);


if(deformGen == DEFORM_WAVE)
{
float func = u_DeformParms[deformOfs++];
float base = u_DeformParms[deformOfs++];
float amplitude = u_DeformParms[deformOfs++];
float phase = u_DeformParms[deformOfs++];
float freq = u_DeformParms[deformOfs++];

float spread = u_DeformParms[deformOfs++];

float off = (pos.x + pos.y + pos.z) * spread;
float scale = WaveValue(func, base, amplitude, phase + off, freq, time);
vec3 offset = normal * scale;

pos.xyz += offset;
}
else if(deformGen == DEFORM_BULGE)
{
float bulgeWidth = u_DeformParms[deformOfs++];
float bulgeHeight = u_DeformParms[deformOfs++];
float bulgeSpeed = u_DeformParms[deformOfs++];

float now = time * bulgeSpeed;

float off = st.x * bulgeWidth + now;
float scale = sin(off) * bulgeHeight;
vec3 offset = normal * scale;

pos.xyz += offset;
}
else if(deformGen == DEFORM_MOVE)
{
float func = u_DeformParms[deformOfs++];
float base = u_DeformParms[deformOfs++];
float amplitude = u_DeformParms[deformOfs++];
float phase = u_DeformParms[deformOfs++];
float freq = u_DeformParms[deformOfs++];

vec3 move;
move.x = u_DeformParms[deformOfs++];
move.y = u_DeformParms[deformOfs++];
move.z = u_DeformParms[deformOfs++];

float scale = WaveValue(func, base, amplitude, phase, freq, time);
vec3 offset = move * scale;

pos.xyz += offset;
}
vec4 parms = u_DeformParms[ deformOfs ];
int cmd = int(parms.w);

if( cmd == DSTEP_LOAD_POS ) {
work.xyz = pos.xyz * parms.xyz;
} else if( cmd == DSTEP_LOAD_NORM ) {
work.xyz = normal.xyz * parms.xyz;
} else if( cmd == DSTEP_LOAD_COLOR ) {
work.xyz = color.xyz * parms.xyz;
} else if( cmd == DSTEP_LOAD_TC ) {
work.xyz = vec3(st, 1.0) * parms.xyz;
} else if( cmd == DSTEP_LOAD_VEC ) {
work.xyz = parms.xyz;
} else if( cmd == DSTEP_MODIFY_POS ) {
pos.xyz += (parms.x + parms.y * work.a) * work.xyz;
} else if( cmd == DSTEP_MODIFY_NORM ) {
normal.xyz += (parms.x + parms.y * work.a) * work.xyz;
normal = normalize(normal);
} else if( cmd == DSTEP_MODIFY_COLOR ) {
color.xyz += (parms.x + parms.y * work.a) * work.xyz;
} else if( cmd == DSTEP_SIN ) {
work.a = sin( 2.0 * M_PI * (parms.x + parms.y * (work.x + work.y + work.z) + parms.z * time) );
} else if( cmd == DSTEP_SQUARE ) {
work.a = sign(sin( 2.0 * M_PI * (parms.x + parms.y * (work.x + work.y + work.z) + parms.z * time) ) );
} else if( cmd == DSTEP_TRIANGLE ) {
work.a = triangle(parms.x + parms.y * (work.x + work.y + work.z) + parms.z * time);
} else if( cmd == DSTEP_SAWTOOTH ) {
work.a = sawtooth(parms.x + parms.y * (work.x + work.y + work.z) + parms.z * time);
} else if( cmd == DSTEP_INVERSE_SAWTOOTH ) {
work.a = 1.0 - sawtooth(parms.x + parms.y * (work.x + work.y + work.z) + parms.z * time);
} else if( cmd == DSTEP_NOISE ) {
//work = pnoise(vec4(parms.y * work.xyz, parms.z * time));
work = noise4(vec4(parms.y * work.xyz, parms.z * time));
} else if( cmd == DSTEP_ROTGROW ) {
if(work.z > parms.x * time)
work.a = 0.0;
else {
work.a = parms.y * atan(pos.y, pos.x) + parms.z * time;
work.a = 0.5 * sin(work.a) + 0.5;
}
} else
break;
}
}
46 changes: 8 additions & 38 deletions main/glsl/fogQuake3_vp.glsl
Expand Up @@ -22,16 +22,6 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

/* fogQuake3_vp.glsl */

attribute vec3 attr_Position;
attribute vec2 attr_TexCoord0;
attribute vec4 attr_QTangent;
attribute vec4 attr_Color;

attribute vec3 attr_Position2;
attribute vec4 attr_QTangent2;

uniform float u_VertexInterpolation;

uniform vec3 u_ViewOrigin;

uniform float u_Time;
Expand All @@ -49,41 +39,21 @@ varying vec3 var_Position;
varying vec2 var_Tex;
varying vec4 var_Color;

vec3 QuatTransVec(in vec4 quat, in vec3 vec) {
vec3 tmp = 2.0 * cross( quat.xyz, vec );
return vec + quat.w * tmp + cross( quat.xyz, tmp );
}



void main()
{
vec4 position;
vec3 normal;
vec2 texCoord;

#if defined(USE_VERTEX_SKINNING)

VertexSkinning_P_N( attr_Position, attr_QTangent,
position, normal );

#elif defined(USE_VERTEX_ANIMATION)

VertexAnimation_P_N(attr_Position, attr_Position2,
attr_QTangent, attr_QTangent2,
u_VertexInterpolation,
position, normal);
localBasis LB;
vec2 texCoord, lmCoord;
vec4 color;

#else
position = vec4(attr_Position, 1.0);
normal = QuatTransVec( attr_QTangent, vec3( 0.0, 0.0, 1.0 ) );
#endif
VertexFetch( position, LB, color, texCoord, lmCoord );

texCoord = attr_TexCoord0;
color = /* color * u_ColorModulate + */ u_Color;

DeformVertex( position,
normal,
LB.normal,
texCoord,
color,
u_Time);

// transform vertex position into homogenous clip-space
Expand Down Expand Up @@ -122,5 +92,5 @@ void main()

var_Tex = vec2(s, t);

var_Color = /* attr_Color * u_ColorModulate + */ u_Color;
var_Color = color;
}
77 changes: 12 additions & 65 deletions main/glsl/forwardLighting_vp.glsl
Expand Up @@ -22,16 +22,6 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

/* forwardLighting_vp.glsl */

attribute vec3 attr_Position;
attribute vec2 attr_TexCoord0;
attribute vec4 attr_QTangent;
attribute vec4 attr_Color;

attribute vec3 attr_Position2;
attribute vec4 attr_QTangent2;

uniform float u_VertexInterpolation;

uniform mat4 u_DiffuseTextureMatrix;
uniform mat4 u_NormalTextureMatrix;
uniform mat4 u_SpecularTextureMatrix;
Expand Down Expand Up @@ -61,61 +51,22 @@ varying vec4 var_Binormal;
varying vec4 var_Normal;
//varying vec4 var_Color; // Tr3B - maximum vars reached

vec3 QuatTransVec(in vec4 quat, in vec3 vec) {
vec3 tmp = 2.0 * cross( quat.xyz, vec );
return vec + quat.w * tmp + cross( quat.xyz, tmp );
}


void main()
{
vec4 position;
vec3 tangent;
vec3 binormal;
vec3 normal;
vec2 texCoord;

#if defined(USE_VERTEX_SKINNING)

#if defined(USE_NORMAL_MAPPING)
VertexSkinning_P_TBN( attr_Position, attr_QTangent,
position, tangent, binormal, normal);
#else
VertexSkinning_P_N( attr_Position, attr_QTangent,
position, normal);
#endif

#elif defined(USE_VERTEX_ANIMATION)

#if defined(USE_NORMAL_MAPPING)
VertexAnimation_P_TBN( attr_Position, attr_Position2,
attr_QTangent, attr_QTangent2,
u_VertexInterpolation,
position, tangent, binormal, normal);
#else
VertexAnimation_P_N(attr_Position, attr_Position2,
attr_QTangent, attr_QTangent2,
u_VertexInterpolation,
position, normal);
#endif

#else
position = vec4(attr_Position, 1.0);

#if defined(USE_NORMAL_MAPPING)
tangent = QuatTransVec( attr_QTangent, vec3( 1.0, 0.0, 0.0 ) );
binormal = QuatTransVec( attr_QTangent, vec3( 0.0, 1.0, 0.0 ) );
tangent *= sign( attr_QTangent.w );
#endif

normal = QuatTransVec( attr_QTangent, vec3( 0.0, 0.0, 1.0 ) );
#endif
localBasis LB;
vec2 texCoord, lmCoord;
vec4 color;

VertexFetch( position, LB, color, texCoord, lmCoord);

texCoord = attr_TexCoord0;
// assign color
color = color * u_ColorModulate + u_Color;

DeformVertex( position,
normal,
LB.normal,
texCoord.st,
color,
u_Time);

// transform vertex position into homogenous clip-space
Expand All @@ -125,11 +76,11 @@ void main()
var_Position = (u_ModelMatrix * position).xyz;

#if defined(USE_NORMAL_MAPPING)
var_Tangent.xyz = (u_ModelMatrix * vec4(tangent, 0.0)).xyz;
var_Binormal.xyz = (u_ModelMatrix * vec4(binormal, 0.0)).xyz;
var_Tangent.xyz = (u_ModelMatrix * vec4(LB.tangent, 0.0)).xyz;
var_Binormal.xyz = (u_ModelMatrix * vec4(LB.binormal, 0.0)).xyz;
#endif

var_Normal.xyz = mat3(u_ModelMatrix) * normal;
var_Normal.xyz = mat3(u_ModelMatrix) * LB.normal;

// calc light xy,z attenuation in light space
var_TexAttenuation = u_LightAttenuationMatrix * position;
Expand All @@ -145,10 +96,6 @@ void main()
var_TexSpecular = (u_SpecularTextureMatrix * vec4(texCoord, 0.0, 1.0)).st;
#endif

// assign color
vec4 color = attr_Color * u_ColorModulate + u_Color;
// color = vec4(1.0);

var_TexDiffuse.p = color.r;
var_TexNormal.pq = color.gb;
}

0 comments on commit ceb650f

Please sign in to comment.