Skip to content

Commit 03ad4e8

Browse files
committed
Merge pull request #436 from guycalledfrank/somode
specular occlusion modes
2 parents eaad32c + de49c96 commit 03ad4e8

5 files changed

Lines changed: 33 additions & 7 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
void occludeSpecular(inout psInternalData data) {
2+
float specOcc = data.ao;
3+
data.specularLight *= specOcc;
4+
data.reflection *= specOcc;
5+
}
6+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
uniform float material_occludeSpecularIntensity;
2+
void occludeSpecular(inout psInternalData data) {
3+
float specOcc = mix(1.0, data.ao, material_occludeSpecularIntensity);
4+
data.specularLight *= specOcc;
5+
data.reflection *= specOcc;
6+
}
7+

src/graphics/programlib/programlib_phong.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ pc.programlib.phong = {
1616
for (var prop in options) {
1717
if (prop==="lights") {
1818
for(var i=0; i<options.lights.length; i++) {
19-
props.push(options.lights[i].getType() + "_" +
20-
(options.lights[i].getCastShadows() ? 1 : 0) + "_" +
21-
options.lights[i].getFalloffMode() + "_" +
19+
props.push(options.lights[i].getType() + "_" +
20+
(options.lights[i].getCastShadows() ? 1 : 0) + "_" +
21+
options.lights[i].getFalloffMode() + "_" +
2222
!!options.lights[i].getNormalOffsetBias());
2323
}
2424
} else if (prop==="chunks") {
@@ -339,7 +339,7 @@ pc.programlib.phong = {
339339
//////////////////////////////
340340
// GENERATE FRAGMENT SHADER //
341341
//////////////////////////////
342-
if (options.forceFragmentPrecision && options.forceFragmentPrecision!="highp" &&
342+
if (options.forceFragmentPrecision && options.forceFragmentPrecision!="highp" &&
343343
options.forceFragmentPrecision !== "mediump" && options.forceFragmentPrecision !== "lowp")
344344
options.forceFragmentPrecision = null;
345345

@@ -478,7 +478,11 @@ pc.programlib.phong = {
478478
if (useAo) {
479479
code += this._addMap("ao", options, chunks, uvOffset, options.aoMapVertexColor? chunks.aoVertPS : chunks.aoTexPS);
480480
if (options.occludeSpecular) {
481-
code += options.occludeSpecularFloat? chunks.aoSpecOccPS : chunks.aoSpecOccConstPS;
481+
if (options.occludeSpecular===pc.SPECOCC_AO) {
482+
code += options.occludeSpecularFloat? chunks.aoSpecOccSimplePS : chunks.aoSpecOccConstSimplePS;
483+
} else {
484+
code += options.occludeSpecularFloat? chunks.aoSpecOccPS : chunks.aoSpecOccConstPS;
485+
}
482486
}
483487
}
484488

src/scene/scene_phongmaterial.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,12 @@ pc.extend(pc, function () {
7979
* @property {Boolean} specularMapTint Enables specularMap multiplication by specular color.
8080
* @property {Boolean} emissiveMapTint Enables emissiveMap multiplication by emissive color.
8181
* @property {pc.Texture} aoMap Baked ambient occlusion map. Modulates ambient color.
82-
* @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.
82+
* @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.
83+
* <ul>
84+
* <li><strong>{@link pc.SPECOCC_NONE}</strong>: No specular occlusion</li>
85+
* <li><strong>{@link pc.SPECOCC_AO}</strong>: Use AO map directly to occlude specular.</li>
86+
* <li><strong>{@link pc.SPECOCC_GLOSSDEPENDENT}</strong>: Modify AO map based on material glossiness/view angle to occlude specular.</li>
87+
* </ul>
8388
* @property {Number} occludeSpecularIntensity Controls visibility of specular occlusion.
8489
* @property {Boolean} specularAntialias Enables Toksvig AA for mipmapped normal maps with specular.
8590
* @property {Boolean} conserveEnergy Defines how diffuse and specular components are combined when Fresnel is on.
@@ -949,7 +954,7 @@ pc.extend(pc, function () {
949954
_defineFlag(obj, "occludeDirect", false);
950955
_defineFlag(obj, "normalizeNormalMap", true);
951956
_defineFlag(obj, "conserveEnergy", true);
952-
_defineFlag(obj, "occludeSpecular", true);
957+
_defineFlag(obj, "occludeSpecular", pc.SPECOCC_AO);
953958
_defineFlag(obj, "shadingModel", pc.SPECULAR_PHONG);
954959
_defineFlag(obj, "fresnelModel", pc.FRESNEL_NONE);
955960
_defineFlag(obj, "cubeMapProjection", pc.CUBEPROJ_NONE);

src/scene/scene_scene.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,10 @@
158158
TONEMAP_LINEAR: 0,
159159
TONEMAP_FILMIC: 1,
160160

161+
SPECOCC_NONE: 0,
162+
SPECOCC_AO: 1,
163+
SPECOCC_GLOSSDEPENDENT: 2,
164+
161165
SHADERDEF_NOSHADOW: 1,
162166
SHADERDEF_SKIN: 2,
163167
SHADERDEF_UV0: 4,

0 commit comments

Comments
 (0)