Skip to content

Commit

Permalink
Merge pull request #335 from guycalledfrank/matrefactor4
Browse files Browse the repository at this point in the history
Material system refactor 2
  • Loading branch information
guycalledfrank committed Jun 25, 2015
2 parents bfc99b1 + 0398a24 commit ce6c461
Show file tree
Hide file tree
Showing 14 changed files with 172 additions and 62 deletions.
2 changes: 1 addition & 1 deletion src/graphics/programlib/chunks/normalMap.frag
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
uniform sampler2D texture_normalMap;
uniform float material_bumpMapFactor;
uniform float material_bumpiness;
void getNormal(inout psInternalData data) {
vec3 normalMap = unpackNormal(texture2D(texture_normalMap, $UV));
data.normalMap = normalMap;
Expand Down
4 changes: 2 additions & 2 deletions src/graphics/programlib/chunks/normalMapFloat.frag
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
uniform sampler2D texture_normalMap;
uniform float material_bumpMapFactor;
uniform float material_bumpiness;
void getNormal(inout psInternalData data) {
vec3 normalMap = unpackNormal(texture2D(texture_normalMap, $UV));
data.normalMap = normalMap;
normalMap = normalize(mix(vec3(0.0, 0.0, 1.0), normalMap, material_bumpMapFactor));
normalMap = normalize(mix(vec3(0.0, 0.0, 1.0), normalMap, material_bumpiness));
data.normalW = data.TBN * normalMap;
}

4 changes: 2 additions & 2 deletions src/graphics/programlib/chunks/normalMapFloatTBNfast.frag
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
uniform sampler2D texture_normalMap;
uniform float material_bumpMapFactor;
uniform float material_bumpiness;
void getNormal(inout psInternalData data) {
vec3 normalMap = unpackNormal(texture2D(texture_normalMap, $UV));
data.normalMap = normalMap;
normalMap = mix(vec3(0.0, 0.0, 1.0), normalMap, material_bumpMapFactor);
normalMap = mix(vec3(0.0, 0.0, 1.0), normalMap, material_bumpiness);
data.normalW = normalize(data.TBN * normalMap);
}

4 changes: 2 additions & 2 deletions src/graphics/programlib/chunks/reflectionCube.frag
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
uniform samplerCube texture_cubeMap;
uniform float material_reflectionFactor;
uniform float material_reflectivity;
void addReflection(inout psInternalData data) {
vec3 lookupVec = fixSeams(cubeMapProject(data.reflDirW));
lookupVec.x *= -1.0;
data.reflection += vec4($textureCubeSAMPLE(texture_cubeMap, lookupVec).rgb, material_reflectionFactor);
data.reflection += vec4($textureCubeSAMPLE(texture_cubeMap, lookupVec).rgb, material_reflectivity);
}
4 changes: 2 additions & 2 deletions src/graphics/programlib/chunks/reflectionDpAtlas.frag
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
uniform sampler2D texture_sphereMap;
uniform float material_reflectionFactor;
uniform float material_reflectivity;

vec2 getDpAtlasUv(vec2 uv, float mip) {

Expand Down Expand Up @@ -50,7 +50,7 @@ void addReflection(inout psInternalData data) {
tex1 = mix(tex1, tex2, fract(bias));
tex1 = processEnvironment(tex1);

data.reflection += vec4(tex1, material_reflectionFactor);
data.reflection += vec4(tex1, material_reflectivity);
}


4 changes: 2 additions & 2 deletions src/graphics/programlib/chunks/reflectionPrefilteredCube.frag
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ uniform samplerCube texture_prefilteredCubeMap32;
uniform samplerCube texture_prefilteredCubeMap16;
uniform samplerCube texture_prefilteredCubeMap8;
uniform samplerCube texture_prefilteredCubeMap4;
uniform float material_reflectionFactor;
uniform float material_reflectivity;

void addReflection(inout psInternalData data) {

Expand Down Expand Up @@ -56,6 +56,6 @@ void addReflection(inout psInternalData data) {
vec4 cubeFinal = mix(cube[0], cube[1], fract(bias));
vec3 refl = processEnvironment($DECODE(cubeFinal).rgb);

data.reflection += vec4(refl, material_reflectionFactor);
data.reflection += vec4(refl, material_reflectivity);
}

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#extension GL_EXT_shader_texture_lod : enable

uniform samplerCube texture_prefilteredCubeMap128;
uniform float material_reflectionFactor;
uniform float material_reflectivity;

void addReflection(inout psInternalData data) {

Expand All @@ -11,6 +11,6 @@ void addReflection(inout psInternalData data) {

vec3 refl = processEnvironment($DECODE( textureCubeLodEXT(texture_prefilteredCubeMap128, fixedReflDir, bias) ).rgb);

data.reflection += vec4(refl, material_reflectionFactor);
data.reflection += vec4(refl, material_reflectivity);
}

4 changes: 2 additions & 2 deletions src/graphics/programlib/chunks/reflectionSphere.frag
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
uniform mat4 matrix_view;
uniform sampler2D texture_sphereMap;
uniform float material_reflectionFactor;
uniform float material_reflectivity;
void addReflection(inout psInternalData data) {

vec3 reflDirV = (mat3(matrix_view) * data.reflDirW).xyz;

float m = 2.0 * sqrt( dot(reflDirV.xy, reflDirV.xy) + (reflDirV.z+1.0)*(reflDirV.z+1.0) );
vec2 sphereMapUv = reflDirV.xy / m + 0.5;

data.reflection += vec4($texture2DSAMPLE(texture_sphereMap, sphereMapUv).rgb, material_reflectionFactor);
data.reflection += vec4($texture2DSAMPLE(texture_sphereMap, sphereMapUv).rgb, material_reflectivity);
}


4 changes: 2 additions & 2 deletions src/graphics/programlib/chunks/reflectionSphereLow.frag
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
uniform sampler2D texture_sphereMap;
uniform float material_reflectionFactor;
uniform float material_reflectivity;
void addReflection(inout psInternalData data) {

vec3 reflDirV = vNormalV;

vec2 sphereMapUv = reflDirV.xy * 0.5 + 0.5;
data.reflection += vec4($texture2DSAMPLE(texture_sphereMap, sphereMapUv).rgb, material_reflectionFactor);
data.reflection += vec4($texture2DSAMPLE(texture_sphereMap, sphereMapUv).rgb, material_reflectivity);
}

4 changes: 2 additions & 2 deletions src/graphics/programlib/chunks/refraction.frag
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
uniform float material_refraction, material_refractionIor;
uniform float material_refraction, material_refractionIndex;

vec3 refract2(vec3 viewVec, vec3 Normal, float IOR) {
float vn = dot(viewVec, Normal);
Expand All @@ -13,7 +13,7 @@ void addRefraction(inout psInternalData data) {
vec3 tmp = data.reflDirW;
vec4 tmp2 = data.reflection;
data.reflection = vec4(0.0);
data.reflDirW = refract2(-data.viewDirW, data.normalW, material_refractionIor);
data.reflDirW = refract2(-data.viewDirW, data.normalW, material_refractionIndex);

addReflection(data);

Expand Down
2 changes: 1 addition & 1 deletion src/graphics/programlib/chunks/specularAaToksvigFloat.frag
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
float antiAliasGlossiness(inout psInternalData data, float power) {
float rlen = 1.0 / saturate(length(data.normalMap));
float toksvig = 1.0 / (1.0 + power * (rlen - 1.0));
return power * mix(1.0, toksvig, material_bumpMapFactor);
return power * mix(1.0, toksvig, material_bumpiness);
}

2 changes: 1 addition & 1 deletion src/graphics/programlib/programlib_programlib.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ pc.programlib = {
// V, the view vector (vertex to eye)
code += ' vec3 map = texture2D( texture_normalMap, uv ).xyz;\n';
code += ' map = map * 255./127. - 128./127.;\n';
code += ' map.xy = map.xy * material_bumpMapFactor;\n';
code += ' map.xy = map.xy * material_bumpiness;\n';
code += ' mat3 TBN = cotangent_frame( N, -V, uv );\n';
code += ' return normalize( TBN * map );\n';
code += '}\n\n';
Expand Down
17 changes: 16 additions & 1 deletion src/scene/scene_material.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,22 @@ pc.extend(pc, function () {
* @name {number|Array|pc.Texture} data The value for the specified parameter.
* @author Will Eastcott
*/
Material.prototype.setParameter = function (name, data) {
Material.prototype.setParameter = function (arg, data) {

var name;
if (data===undefined) {
var uniformObject = arg;
if (uniformObject.length) {
for(var i=0; i<uniformObject.length; i++) this.setParameter(uniformObject[i]);
return;
} else {
name = uniformObject.name;
data = uniformObject.value;
}
} else {
name = arg;
}

var param = this.parameters[name];
if (param) {
param.data = data;
Expand Down
Loading

0 comments on commit ce6c461

Please sign in to comment.