Пример #1
0
float BerconGradient::getGradientValueNormal(ShadeContext& sc) {
	switch (p_normalType) {	 
		case 0: { // View			 
			return -DotProd(sc.Normal(), sc.V());
		}
		case 1: { // Local X
			return (sc.VectorTo(sc.Normal(), REF_OBJECT)).x;
		}
		case 2: { // Local Y
			return (sc.VectorTo(sc.Normal(), REF_OBJECT)).y;
		}
		case 3: { // Local Z
			return (sc.VectorTo(sc.Normal(), REF_OBJECT)).z;
		}
		case 4: { // World X
			return (sc.VectorTo(sc.Normal(), REF_WORLD)).x;
		}
		case 5: { // World Y
			return (sc.VectorTo(sc.Normal(), REF_WORLD)).y;
		}
		case 6: { // World Z
			return (sc.VectorTo(sc.Normal(), REF_WORLD)).z;
		}
		case 7: { // Camera X
			return sc.Normal().x; //(sc.VectorTo(sc.Normal(), REF_CAMERA)).x;
		}
		case 8: { // Camera Y
			return sc.Normal().y; //(sc.VectorTo(sc.Normal(), REF_CAMERA)).y;
		}
		case 9: { // Camera Z
			return sc.Normal().z; //(sc.VectorTo(sc.Normal(), REF_CAMERA)).z;
		}
		case 10: { // To Object
			if (sc.InMtlEditor() || !p_node)
				return -DotProd(sc.Normal(), sc.V());												
			return DotProd(sc.Normal(), FNormalize(sc.PointFrom((p_node->GetNodeTM(sc.CurTime())).GetTrans(),REF_WORLD) - sc.P()));							
		}
		case 11: { // Object Z			
			if (sc.InMtlEditor() || !p_node)
				return -DotProd(sc.Normal(), sc.V());				
			return DotProd(sc.Normal(), FNormalize(sc.VectorFrom(p_node->GetNodeTM(sc.CurTime()).GetRow(2),REF_WORLD)));			
		}
	}
	return 0.f;
}
Пример #2
0
// perpendicular to N, in the U (reference) direction
Point3 GetTangent( ShadeContext &sc, int uvChan )
{
// Point3 basisVecs[ 3 ];
// sc.DPdUVW( basisVecs, uvChan ); // 0 is vtxclr, 1..n is uv channels, max_meshmaps in mesh.h
// Point3 U = Normalize( basisVecs[0] );
   
   Point3 U = sc.VectorFrom( Point3( 0.01f, 0.0f, 1.0f ), REF_OBJECT );
//Retry:
   U = Normalize( U );

   Point3 N = sc.Normal();       //assumed normalized

   // the line between the tip of vec[0] and its projection on N is tangent
   float UN = Dot( U, N );
// if ( Abs(UN) > 0.9999999f ){
//    U = sc.VectorFrom( Point3( 0.01f, 1.0f, 0.0f ), REF_OBJECT ); 
//    goto Retry;
// }
   Point3 T = U - N * UN;
   T = Normalize( T );
   return T;
}