Skip to content

Commit

Permalink
Merge pull request #436 from guycalledfrank/somode
Browse files Browse the repository at this point in the history
specular occlusion modes
  • Loading branch information
Maksims committed Nov 11, 2015
2 parents eaad32c + de49c96 commit 03ad4e8
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 7 deletions.
6 changes: 6 additions & 0 deletions src/graphics/programlib/chunks/aoSpecOccConstSimple.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
void occludeSpecular(inout psInternalData data) {
float specOcc = data.ao;
data.specularLight *= specOcc;
data.reflection *= specOcc;
}

7 changes: 7 additions & 0 deletions src/graphics/programlib/chunks/aoSpecOccSimple.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
uniform float material_occludeSpecularIntensity;
void occludeSpecular(inout psInternalData data) {
float specOcc = mix(1.0, data.ao, material_occludeSpecularIntensity);
data.specularLight *= specOcc;
data.reflection *= specOcc;
}

14 changes: 9 additions & 5 deletions src/graphics/programlib/programlib_phong.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ pc.programlib.phong = {
for (var prop in options) {
if (prop==="lights") {
for(var i=0; i<options.lights.length; i++) {
props.push(options.lights[i].getType() + "_" +
(options.lights[i].getCastShadows() ? 1 : 0) + "_" +
options.lights[i].getFalloffMode() + "_" +
props.push(options.lights[i].getType() + "_" +
(options.lights[i].getCastShadows() ? 1 : 0) + "_" +
options.lights[i].getFalloffMode() + "_" +
!!options.lights[i].getNormalOffsetBias());
}
} else if (prop==="chunks") {
Expand Down Expand Up @@ -339,7 +339,7 @@ pc.programlib.phong = {
//////////////////////////////
// GENERATE FRAGMENT SHADER //
//////////////////////////////
if (options.forceFragmentPrecision && options.forceFragmentPrecision!="highp" &&
if (options.forceFragmentPrecision && options.forceFragmentPrecision!="highp" &&
options.forceFragmentPrecision !== "mediump" && options.forceFragmentPrecision !== "lowp")
options.forceFragmentPrecision = null;

Expand Down Expand Up @@ -478,7 +478,11 @@ pc.programlib.phong = {
if (useAo) {
code += this._addMap("ao", options, chunks, uvOffset, options.aoMapVertexColor? chunks.aoVertPS : chunks.aoTexPS);
if (options.occludeSpecular) {
code += options.occludeSpecularFloat? chunks.aoSpecOccPS : chunks.aoSpecOccConstPS;
if (options.occludeSpecular===pc.SPECOCC_AO) {
code += options.occludeSpecularFloat? chunks.aoSpecOccSimplePS : chunks.aoSpecOccConstSimplePS;
} else {
code += options.occludeSpecularFloat? chunks.aoSpecOccPS : chunks.aoSpecOccConstPS;
}
}
}

Expand Down
9 changes: 7 additions & 2 deletions src/scene/scene_phongmaterial.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,12 @@ pc.extend(pc, function () {
* @property {Boolean} specularMapTint Enables specularMap multiplication by specular color.
* @property {Boolean} emissiveMapTint Enables emissiveMap multiplication by emissive color.
* @property {pc.Texture} aoMap Baked ambient occlusion map. Modulates ambient color.
* @property {Boolean} occludeSpecular Uses aoMap to occlude specular/reflection. It's a hack, because real specular occlusion is view-dependent. However, it's much better than nothing.
* @property {Number} occludeSpecular Uses aoMap to occlude specular/reflection. It's a hack, because real specular occlusion is view-dependent. However, it's much better than nothing.
* <ul>
* <li><strong>{@link pc.SPECOCC_NONE}</strong>: No specular occlusion</li>
* <li><strong>{@link pc.SPECOCC_AO}</strong>: Use AO map directly to occlude specular.</li>
* <li><strong>{@link pc.SPECOCC_GLOSSDEPENDENT}</strong>: Modify AO map based on material glossiness/view angle to occlude specular.</li>
* </ul>
* @property {Number} occludeSpecularIntensity Controls visibility of specular occlusion.
* @property {Boolean} specularAntialias Enables Toksvig AA for mipmapped normal maps with specular.
* @property {Boolean} conserveEnergy Defines how diffuse and specular components are combined when Fresnel is on.
Expand Down Expand Up @@ -949,7 +954,7 @@ pc.extend(pc, function () {
_defineFlag(obj, "occludeDirect", false);
_defineFlag(obj, "normalizeNormalMap", true);
_defineFlag(obj, "conserveEnergy", true);
_defineFlag(obj, "occludeSpecular", true);
_defineFlag(obj, "occludeSpecular", pc.SPECOCC_AO);
_defineFlag(obj, "shadingModel", pc.SPECULAR_PHONG);
_defineFlag(obj, "fresnelModel", pc.FRESNEL_NONE);
_defineFlag(obj, "cubeMapProjection", pc.CUBEPROJ_NONE);
Expand Down
4 changes: 4 additions & 0 deletions src/scene/scene_scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@
TONEMAP_LINEAR: 0,
TONEMAP_FILMIC: 1,

SPECOCC_NONE: 0,
SPECOCC_AO: 1,
SPECOCC_GLOSSDEPENDENT: 2,

SHADERDEF_NOSHADOW: 1,
SHADERDEF_SKIN: 2,
SHADERDEF_UV0: 4,
Expand Down

0 comments on commit 03ad4e8

Please sign in to comment.