Permalink
Browse files

BASICNODES:

-no functional changes, only style editing...
-converted spaces to tab
-comment for normal map fix added

Reviewed by: Gustavo Pichorim Boiko <gustavo.boiko@gmail.com>
  • Loading branch information...
1 parent d214708 commit 938cdf4a3698e52585b5811e9d36f7aa5f250020 @OlafArnold committed with boiko Mar 13, 2012
Showing with 62 additions and 62 deletions.
  1. +62 −62 src/textures/basicnodes.cc
View
@@ -24,18 +24,18 @@ void textureMapper_t::setup()
}
else
{
- float step = 0.0002f;
+ float step = 0.0002f;
dU = dV = dW = step;
}
pDU = point3d_t(dU, 0, 0);
pDV = point3d_t(0, dV, 0);
pDW = point3d_t(0, 0, dW);
-
+
bumpStr /= scale.length();
- if (!tex->isNormalmap())
- bumpStr /= 100.0f;
+ if (!tex->isNormalmap())
+ bumpStr /= 100.0f;
}
// Map the texture to a cylinder
@@ -113,12 +113,12 @@ point3d_t textureMapper_t::doMapping(const point3d_t &p, const vector3d_t &N)con
case TXP_TUBE: texpt = tubemap(texpt); break;
case TXP_SPHERE:texpt = spheremap(texpt); break;
case TXP_CUBE: texpt = cubemap(texpt, N); break;
- case TXP_PLAIN: // texpt = flatmap(texpt); break;
+ case TXP_PLAIN: // texpt = flatmap(texpt); break;
default: break;
}
// Texture scale and offset
texpt = mult(texpt,scale) + offset;
-
+
return texpt;
}
@@ -154,7 +154,7 @@ void textureMapper_t::eval(nodeStack_t &stack, const renderState_t &state, const
getCoords(texpt, Ng, sp, state);
texpt = doMapping(texpt, Ng);
-
+
stack[this->ID] = nodeResult_t(tex->getColor(texpt), (doScalar) ? tex->getFloat(texpt) : 0.f );
}
@@ -170,9 +170,9 @@ void textureMapper_t::evalDerivative(nodeStack_t &stack, const renderState_t &st
{
point3d_t texpt(0.f);
vector3d_t Ng(0.f);
- float du = 0.0f, dv = 0.0f;
+ float du = 0.0f, dv = 0.0f;
- getCoords(texpt, Ng, sp, state);
+ getCoords(texpt, Ng, sp, state);
if (tex->discrete())
{
@@ -194,48 +194,48 @@ void textureMapper_t::evalDerivative(nodeStack_t &stack, const renderState_t &st
// Convert norm into shading space
du = norm * sp.dSdU;
dv = norm * sp.dSdV;
- }
- else
- {
- point3d_t i0 = (texpt - pDU);
- point3d_t i1 = (texpt + pDU);
- point3d_t j0 = (texpt - pDV);
- point3d_t j1 = (texpt + pDV);
- float dfdu = (tex->getFloat(i0) - tex->getFloat(i1)) / dU;
- float dfdv = (tex->getFloat(j0) - tex->getFloat(j1)) / dV;
-
- // now we got the derivative in UV-space, but need it in shading space:
- vector3d_t vecU = sp.dSdU;
- vector3d_t vecV = sp.dSdV;
- vecU.z = dfdu;
- vecV.z = dfdv;
- // now we have two vectors NU/NV/df; Solve plane equation to get 1/0/df and 0/1/df (i.e. dNUdf and dNVdf)
- norm = vecU ^ vecV;
- }
-
- norm.normalize();
-
- if(std::fabs(norm.z) > 1e-30f)
- {
- float NF = 1.0/norm.z * bumpStr; // normalizes z to 1, why?
- du = norm.x * NF;
- dv = norm.y * NF;
- }
- else du = dv = 0.f;
- }
+ }
+ else
+ {
+ point3d_t i0 = (texpt - pDU);
+ point3d_t i1 = (texpt + pDU);
+ point3d_t j0 = (texpt - pDV);
+ point3d_t j1 = (texpt + pDV);
+ float dfdu = (tex->getFloat(i0) - tex->getFloat(i1)) / dU;
+ float dfdv = (tex->getFloat(j0) - tex->getFloat(j1)) / dV;
+
+ // now we got the derivative in UV-space, but need it in shading space:
+ vector3d_t vecU = sp.dSdU;
+ vector3d_t vecV = sp.dSdV;
+ vecU.z = dfdu;
+ vecV.z = dfdv;
+ // now we have two vectors NU/NV/df; Solve plane equation to get 1/0/df and 0/1/df (i.e. dNUdf and dNVdf)
+ norm = vecU ^ vecV;
+ }
+
+ norm.normalize();
+
+ if(std::fabs(norm.z) > 1e-30f)
+ {
+ float NF = 1.0/norm.z * bumpStr; // normalizes z to 1, why?
+ du = norm.x * NF;
+ dv = norm.y * NF;
+ }
+ else du = dv = 0.f;
+ }
else
{
- // no uv coords -> procedurals usually, this mapping only depends on NU/NV which is fairly arbitrary
- // weird things may happen when objects are rotated, i.e. incorrect bump change
- point3d_t i0 = doMapping(texpt - dU * sp.NU, Ng);
- point3d_t i1 = doMapping(texpt + dU * sp.NU, Ng);
- point3d_t j0 = doMapping(texpt - dV * sp.NV, Ng);
- point3d_t j1 = doMapping(texpt + dV * sp.NV, Ng);
-
- du = (tex->getFloat(i0) - tex->getFloat(i1)) / dU;
- dv = (tex->getFloat(j0) - tex->getFloat(j1)) / dV;
- du *= bumpStr;
- dv *= bumpStr;
+ // no uv coords -> procedurals usually, this mapping only depends on NU/NV which is fairly arbitrary
+ // weird things may happen when objects are rotated, i.e. incorrect bump change
+ point3d_t i0 = doMapping(texpt - dU * sp.NU, Ng);
+ point3d_t i1 = doMapping(texpt + dU * sp.NU, Ng);
+ point3d_t j0 = doMapping(texpt - dV * sp.NV, Ng);
+ point3d_t j1 = doMapping(texpt + dV * sp.NV, Ng);
+
+ du = (tex->getFloat(i0) - tex->getFloat(i1)) / dU;
+ dv = (tex->getFloat(j0) - tex->getFloat(j1)) / dV;
+ du *= bumpStr;
+ dv *= bumpStr;
}
stack[this->ID] = nodeResult_t(colorA_t(du, dv, 0.f, 0.f), 0.f );
@@ -367,7 +367,7 @@ void mixNode_t::eval(nodeStack_t &stack, const renderState_t &state, const surfa
cin2 = col2;
fin2 = val2;
}
-
+
colorA_t color = f1 * cin1 + f2 * cin2;
float scalar = f1 * fin1 + f2 * fin2;
stack[this->ID] = nodeResult_t(color, scalar);
@@ -395,7 +395,7 @@ bool mixNode_t::configInputs(const paraMap_t &params, const nodeFinder_t &find)
Y_ERROR << "MixNode: Color1 not set" << yendl;
return false;
}
-
+
if( params.getParam("input2", name) )
{
input2 = find(*name);
@@ -410,7 +410,7 @@ bool mixNode_t::configInputs(const paraMap_t &params, const nodeFinder_t &find)
Y_ERROR << "MixNode: Color2 not set" << yendl;
return false;
}
-
+
if( params.getParam("factor", name) )
{
factor = find(*name);
@@ -425,7 +425,7 @@ bool mixNode_t::configInputs(const paraMap_t &params, const nodeFinder_t &find)
Y_ERROR << "MixNode: Value not set" << yendl;
return false;
}
-
+
return true;
}
@@ -445,7 +445,7 @@ class addNode_t: public mixNode_t
float f2, fin1, fin2;
colorA_t cin1, cin2;
getInputs(stack, cin1, cin2, fin1, fin2, f2);
-
+
cin1 += f2 * cin2;
fin1 += f2 * fin2;
stack[this->ID] = nodeResult_t(cin1, fin1);
@@ -461,7 +461,7 @@ class multNode_t: public mixNode_t
colorA_t cin1, cin2;
getInputs(stack, cin1, cin2, fin1, fin2, f2);
f1 = 1.f - f2;
-
+
cin1 *= colorA_t(f1) + f2 * cin2;
fin2 *= f1 + f2 * fin2;
stack[this->ID] = nodeResult_t(cin1, fin1);
@@ -476,7 +476,7 @@ class subNode_t: public mixNode_t
float f2, fin1, fin2;
colorA_t cin1, cin2;
getInputs(stack, cin1, cin2, fin1, fin2, f2);
-
+
cin1 -= f2 * cin2;
fin1 -= f2 * fin2;
stack[this->ID] = nodeResult_t(cin1, fin1);
@@ -492,7 +492,7 @@ class screenNode_t: public mixNode_t
colorA_t cin1, cin2;
getInputs(stack, cin1, cin2, fin1, fin2, f2);
f1 = 1.f - f2;
-
+
colorA_t color = colorA_t(1.f) - (colorA_t(f1) + f2 * (1.f - cin2)) * (1.f - cin1);
CFLOAT scalar = 1.0 - (f1 + f2*(1.f - fin2)) * (1.f - fin1);
stack[this->ID] = nodeResult_t(color, scalar);
@@ -508,7 +508,7 @@ class diffNode_t: public mixNode_t
colorA_t cin1, cin2;
getInputs(stack, cin1, cin2, fin1, fin2, f2);
f1 = 1.f - f2;
-
+
cin1.R = f1*cin1.R + f2*std::fabs(cin1.R - cin2.R);
cin1.G = f1*cin1.G + f2*std::fabs(cin1.G - cin2.G);
cin1.B = f1*cin1.B + f2*std::fabs(cin1.B - cin2.B);
@@ -526,7 +526,7 @@ class darkNode_t: public mixNode_t
float f2, fin1, fin2;
colorA_t cin1, cin2;
getInputs(stack, cin1, cin2, fin1, fin2, f2);
-
+
cin2 *= f2;
if(cin2.R < cin1.R) cin1.R = cin2.R;
if(cin2.G < cin1.G) cin1.G = cin2.G;
@@ -546,7 +546,7 @@ class lightNode_t: public mixNode_t
float f2, fin1, fin2;
colorA_t cin1, cin2;
getInputs(stack, cin1, cin2, fin1, fin2, f2);
-
+
cin2 *= f2;
if(cin2.R > cin1.R) cin1.R = cin2.R;
if(cin2.G > cin1.G) cin1.G = cin2.G;
@@ -567,7 +567,7 @@ class overlayNode_t: public mixNode_t
colorA_t cin1, cin2;
getInputs(stack, cin1, cin2, fin1, fin2, f2);
f1 = 1.f - f2;
-
+
colorA_t color;
color.R = (cin1.R < 0.5f) ? cin1.R * (f1 + 2.0f*f2*cin2.R) : 1.0 - (f1 + 2.0f*f2*(1.0 - cin2.R)) * (1.0 - cin1.R);
color.G = (cin1.G < 0.5f) ? cin1.G * (f1 + 2.0f*f2*cin2.G) : 1.0 - (f1 + 2.0f*f2*(1.0 - cin2.G)) * (1.0 - cin1.G);
@@ -585,7 +585,7 @@ shaderNode_t* mixNode_t::factory(const paraMap_t &params,renderEnvironment_t &re
int mode=0;
params.getParam("cfactor", val);
params.getParam("mode", mode);
-
+
switch(mode)
{
case MN_MIX: return new mixNode_t(val);

0 comments on commit 938cdf4

Please sign in to comment.