Skip to content

Commit

Permalink
Model Renderer: Renamed the generic model shader; added another shader
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Nov 2, 2015
1 parent 318c1a6 commit f44c875
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 3 deletions.
@@ -1,7 +1,7 @@
model.skeletal {
# Shader for skeletal animation and generic per-pixel lighting:
# diffuse color, normal map, emission map, specular intensity.
shader normal_specular_emission {
# diffuse color, normal map, emissive map, specular intensity.
shader generic {
variable uAlpha { value = 1 }
variable uAlphaLimit { value = 0 }
variable uEmission { value = 0 }
Expand Down Expand Up @@ -81,4 +81,77 @@ model.skeletal {
if(gl_FragColor.a < uAlphaLimit) discard;
}"
}

# Shader for damage/blood effects. No emissive map, and alpha
# output is either opaque or fully transparent. Alpha limit can
# be used to control how much of the effect is visible.
shader blood {
variable uAlphaLimit { value = 0.5 }

# Mapping when used with ModelDrawable.
textureMapping <diffuse, normals, specular>

include.vertex <include/tangentspace.glsl,
include/skeletal.glsl,
include/lighting.glsl>
vertex = "
uniform highp mat4 uMvpMatrix;

attribute highp vec4 aVertex;
attribute highp vec2 aUV;
attribute highp vec4 aBounds; // diffuse map
attribute highp vec4 aBounds2; // normal map
attribute highp vec4 aBounds3; // specular map

varying highp vec2 vUV;
varying highp vec4 vUVBounds[3];

void main(void)
{
highp mat4 bone = vertexBoneTransform();
highp mat3 surface = tangentSpace(bone);
calculateSurfaceLighting(surface);

// Vertex position.
highp vec4 modelPos = bone * aVertex;
gl_Position = uMvpMatrix * modelPos;

// Eye direction in tangent space.
calculateEyeDirection(modelPos, surface);

vUV = aUV;
vUVBounds[0] = aBounds;
vUVBounds[1] = aBounds2;
vUVBounds[2] = aBounds3;
}"

include.fragment <include/texture.glsl,
include/lighting.glsl>
fragment = "
uniform highp float uAlphaLimit;

varying highp vec2 vUV;
varying highp vec4 vUVBounds[3];

void main(void)
{
// Calculate UV at the fragment (wrapped inside the bounds).
highp vec2 wrappedUV = fract(vUV);
highp vec2 uv = mapToBounds(wrappedUV, vUVBounds[0]);
highp vec2 normalUV = mapToBounds(wrappedUV, vUVBounds[1]);
highp vec2 specularUV = mapToBounds(wrappedUV, vUVBounds[2]);

highp vec4 diffuse = texture2D(uTex, uv);
if(diffuse.a < uAlphaLimit) discard;

highp vec3 normal = normalVector(normalUV);
gl_FragColor = diffuse * diffuseLight(normal);

highp vec4 specular = specularLight(specularUV, normal);
gl_FragColor.rgb += specular.rgb;

// All accepted fragments are opaque.
gl_FragColor.a = 1.0;
}"
}
}
2 changes: 1 addition & 1 deletion doomsday/apps/client/src/render/modelrenderer.cpp
Expand Up @@ -54,7 +54,7 @@ static String const DEF_BLENDFUNC ("blendFunc");
static String const DEF_BLENDOP ("blendOp");
static String const DEF_TIMELINE ("timeline");

static String const SHADER_DEFAULT ("model.skeletal.normal_specular_emission");
static String const SHADER_DEFAULT ("model.skeletal.generic");
static String const MATERIAL_DEFAULT("default");

static Atlas::Size const MAX_ATLAS_SIZE(8192, 8192);
Expand Down

0 comments on commit f44c875

Please sign in to comment.