コード例 #1
0
ファイル: evalcol.cpp プロジェクト: artemeliy/inf4715
BOOL DefObjLight::Illuminate(ShadeContext& sc, Point3& normal, Color& color, Point3 &dir, float &dot_nl, float &diffCoef)
{
	dir = Normalize(lightPos-sc.P());
	diffCoef = dot_nl = DotProd(normal, dir);
	color = intensCol;

	return (dot_nl <= 0.0f) ? 0 : 1;
}
コード例 #2
0
void plPassMtl::ShadeWithBackground(ShadeContext &sc, Color background, bool useVtxAlpha /* = true */)
{
#if 1

    // old
#if 0
    Color lightCol,rescol, diffIllum0;
    RGBA mval;
    Point3 N0,P;
    BOOL bumped = FALSE;
    int i;

    if (gbufID) 
        sc.SetGBufferID(gbufID);
    
    if (sc.mode == SCMODE_SHADOW) {
        float opac = 0.0;
        for (i=0; i < NumSubTexmaps(); i++)     {
            if (SubTexmapOn(i)) {
                hsMaxLayerBase *hsmLay = (hsMaxLayerBase *)GetSubTexmap(i);
                opac += hsmLay->GetOpacity(t);
            }
        }
        
        float f = 1.0f - opac;
        sc.out.t = Color(f,f,f);
        return;
    }
    
    N0 = sc.Normal();
    P = sc.P();
#endif

    TimeValue t = sc.CurTime();
    Color color(0, 0, 0);
    float alpha = 0.0;

    // Evaluate Base layer
    Texmap *map = fLayersPB->GetTexmap(kPassLayBase);
    if (map && ( map->ClassID() == LAYER_TEX_CLASS_ID 
                || map->ClassID() == STATIC_ENV_LAYER_CLASS_ID ) )
    {
        plLayerTex *layer = (plLayerTex*)map;
        AColor evalColor = layer->EvalColor(sc);

        color = evalColor;
        alpha = evalColor.a;
    }

    // Evaluate Top layer, if it's on
    if (fLayersPB->GetInt(kPassLayTopOn))
    {
        Texmap *map = fLayersPB->GetTexmap(kPassLayTop);
        if (map && ( map->ClassID() == LAYER_TEX_CLASS_ID 
                    || map->ClassID() == STATIC_ENV_LAYER_CLASS_ID 
                    || map->ClassID() == ANGLE_ATTEN_LAYER_CLASS_ID) )
        {
            plPlasmaMAXLayer *layer = (plPlasmaMAXLayer*)map;
            AColor evalColor = layer->EvalColor(sc);

            // Blend layers
            if( !layer->DiscardColor() )
            {
                int blendType = fLayersPB->GetInt(kPassLayBlend);
                switch (blendType)
                {
                case kBlendAdd:
                    color += evalColor * evalColor.a;
                    break;
                case kBlendAlpha:
                    color = (1.0f - evalColor.a) * color + evalColor.a * evalColor;
                    break;
                case kBlendMult:
                    color *= evalColor;
                    break;
                default:    // No blend...
                    color = evalColor;
                    break;
                }
            }
            if( !layer->DiscardAlpha() )
            {
                int alphaType = fLayersPB->GetInt(kPassLayOutputBlend);
                switch( alphaType )
                {
                case kAlphaMultiply:
                    alpha *= evalColor.a;
                    break;
                case kAlphaAdd:
                    alpha += evalColor.a;
                    break;
                case kAlphaDiscard:
                default:
                    break;
                }
            }
        }
    }

#if 1
    AColor black;
    black.Black();
    AColor white;
    white.White();


    SIllumParams ip;
    if (fBasicPB->GetInt(kPassBasEmissive))
    {
        // Emissive objects don't get shaded
        ip.diffIllum = fBasicPB->GetColor(kPassBasColorAmb, t) * color;
        ip.diffIllum.ClampMinMax();
        ip.specIllum = black;
    }
    else
    {
        //
        // Shading setup
        //

        // Setup the parameters for the shader
        ip.amb = fBasicPB->GetColor(kPassBasColorAmb, t);
        ip.diff = fBasicPB->GetColor(kPassBasColor, t) * color;
        ip.diffIllum = black;
        ip.specIllum = black;
        ip.N = sc.Normal();
        ip.V = sc.V();


        //
        // Specularity
        //
        if (fBasicPB->GetInt(kPassBasUseSpec, t))
        {
            ip.sh_str = 1.f;
            ip.spec = fBasicPB->GetColor( kPassBasSpecColor, t );
            ip.ph_exp = (float)pow(2.0f,float(fBasicPB->GetInt(kPassBasShine, t)) / 10.0f);
            ip.shine = float(fBasicPB->GetInt(kPassBasShine, t)) / 100.0f;
        }
        else
        {
            ip.spec = black;
            ip.sh_str = 0;
            ip.ph_exp = 0;
            ip.shine = 0;
        }
        ip.softThresh = 0;

        //

        // Do the shading
        Shader *myShader = GetShader(SHADER_BLINN);
        myShader->Illum(sc, ip);

        // Override shader parameters
        if (fAdvPB->GetInt(kPBAdvNoShade))
        {
            ip.diffIllum = black;
            ip.specIllum = black;
        }
        if (fAdvPB->GetInt(kPBAdvWhite))
        {
            ip.diffIllum = white;
            ip.specIllum = black;
        }

        ip.specIllum.ClampMinMax();
        ip.diffIllum = ip.amb * sc.ambientLight + ip.diff * ip.diffIllum;
        ip.diffIllum.ClampMinMax();
    }

//  AColor returnColor = AColor(opac * ip.diffIllum + ip.specIllum, opac)
#endif

    // Get opacity and combine with alpha
    float opac = float(fBasicPB->GetInt(kPassBasOpacity, t)) / 100.0f;
    alpha *= opac;

    float vtxAlpha = 1.0f;
    if (useVtxAlpha && GetOutputBlend() == plPassMtlBase::kBlendAlpha)
    {
        Point3 p;
        GetInterpVtxValue(MAP_ALPHA, sc, p);
        vtxAlpha = p.x;
    }
    alpha *= vtxAlpha;

    // MAX will do the additive/alpha/no blending for us based on what Requirements()
    // we tell it. However, since MAX's formula is bgnd*sc.out.t + sc.out.c,
    // we have to multiply our output color by the alpha.
    // If we ever need a more complicated blending function, you can request the
    // background color via Requirements() (otherwise it's just black) and then do
    // the blending yourself; however, if the transparency isn't set, the shadows
    // will be opaque, so be careful.
    Color outC = ip.diffIllum + ip.specIllum;

    sc.out.c = ( outC * alpha );
    sc.out.t = Color( 1.f - alpha, 1.f - alpha, 1.f - alpha );

#endif
}
コード例 #3
0
ファイル: plate.cpp プロジェクト: artemeliy/inf4715
RGBA Plate::EvalColor(ShadeContext& sc) {
	BMM_Color_64 c;
	IPoint2 s;
	int id = sc.NodeID();
	PlateMap *pmap = FindMap(id);
	if (gbufID) sc.SetGBufferID(gbufID);
	if (pmap) {
		s = sc.ScreenCoord();
		int w = pmap->bm->Width(); 
		int h = pmap->bm->Height();

		Point3 view = sc.OrigView();
		Point3 v2 = sc.V();
		Point3 p = sc.P();
		Point3 dV,dvf;
		Point3 N0 = sc.OrigNormal();

		Point3 vf = RefractVector(sc, N0, view, sc.GetIOR()); 
		
		RenderGlobalContext *gc = sc.globContext;
		if (gc==NULL) return blackrgba;

		// total deflection due to refraction
		dV = view-v2;

		// deflection due to flat refracton (no bumps)
		dvf = view-vf;

		dV = refrAmt*(dV-dvf) + thick*dvf;

		// compute screen deflection: This is really a cheat, and the
		// scale factor is arbitrary. Infact it depends on the distance 
		// between to the point on the glass plate and  to the point being
		// seen behind it, which we don't know.
		// these should be multiplied by the factor (Zbehind-Zcur)/Zcur
		// This assumes that the factor is .1

		float dsx,dsy;
		if (gc->projType==0) {
			// perspective
			dsx = dV.x*0.1f*gc->xscale;
			dsy = dV.y*0.1f*gc->yscale;
			}
		else {
			// parallel projection
			dsx = -dV.x*gc->xscale*10.0f;
			dsy = -dV.y*gc->yscale*10.0f;
			}

		if (gc->fieldRender) dsy *= 2.0f;		
		int x = s.x - (pmap->org.x+gc->devWidth/2);
		int y = s.y - (pmap->org.y+gc->devHeight/2);

		if (applyBlur) {
			float du = 1.0f/float(w);
			float dv = 1.0f/float(h);

			float u = (float(x)+dsx)*du; 
			float v = (float(y)+dsy)*dv; 
			if (u<0.0f||u>1.0f||v<0.0f||v>1.0f) {
				if (useEnvMap) {
					return sc.EvalGlobalEnvironMap(view-dvf);
					}
				else 
					return blackrgba;
				}
			else 
				pmap->bm->GetFiltered(u,v, du*blur, dv*blur,&c);
			}
		else {
			int ix = x + int(dsx); 
			int iy = y + int(dsy); 
			if (ix<0||ix>=w||iy<0||iy>=h) {
				if (useEnvMap)
					return sc.EvalGlobalEnvironMap(view-dvf);
				else 
					return blackrgba;
				}
			else 
				pmap->bm->GetLinearPixels(ix,iy,1,&c);
			}
		return c;
		}
	else 
		return blackrgba;
	}
コード例 #4
0
ファイル: BerconGradient.cpp プロジェクト: GeorgeR/BerconMaps
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;
}
コード例 #5
0
ファイル: BerconGradient.cpp プロジェクト: GeorgeR/BerconMaps
float BerconGradient::getGradientValueDist(ShadeContext& sc) {
	switch (p_normalType) {	 
		case 0: { // View			 
			return -sc.P().z; //Length(sc.OrigView()); //(sc.PointTo(sc.P(), REF_CAMERA)).z;
		}
		case 1: { // Local X
			return (sc.PointTo(sc.P(), REF_OBJECT)).x;
		}
		case 2: { // Local Y
			return (sc.PointTo(sc.P(), REF_OBJECT)).y;
		}
		case 3: { // Local Z
			return (sc.PointTo(sc.P(), REF_OBJECT)).z;
		}
		case 4: { // World X
			return (sc.PointTo(sc.P(), REF_WORLD)).x;
		}
		case 5: { // World Y
			return (sc.PointTo(sc.P(), REF_WORLD)).y;
		}
		case 6: { // World Z
			return (sc.PointTo(sc.P(), REF_WORLD)).z;
		}
		case 7: { // Camera X
			return sc.P().x; //(sc.PointTo(sc.P(), REF_CAMERA)).x;
		}
		case 8: { // Camera Y
			return sc.P().y; //(sc.PointTo(sc.P(), REF_CAMERA)).y;
		}
		case 9: { // Camera Z
			return -sc.P().z; //-(sc.PointTo(sc.P(), REF_CAMERA)).z;
		}
		case 10: { // To Object
			if (sc.InMtlEditor() || !p_node)
				return -sc.P().z; //(sc.PointTo(sc.P(), REF_CAMERA)).z;			
			return Length((p_node->GetNodeTM(sc.CurTime())).GetTrans() - sc.PointTo(sc.P(), REF_WORLD));
		}
		case 11: { // Object Z			
			if (sc.InMtlEditor() || !p_node)
				return -sc.P().z; //(sc.PointTo(sc.P(), REF_CAMERA)).z;			
			Matrix3 tm = p_node->GetNodeTM(sc.CurTime());
			Point3 a = tm.GetTrans() - sc.PointTo(sc.P(), REF_WORLD);
			Point3 b = FNormalize(tm.GetRow(2));
			return (-DotProd(b, a) / Length(b));
		}
	}
	return 0.f;
}