AColor UVtex::EvalColor(ShadeContext& sc) { if (gbufID) sc.SetGBufferID(gbufID); #if MAX_RELEASE > 3100 Point3 uvw; if (uvChannel < 0) { if (sc.InMtlEditor()) { Point2 a, b; sc.ScreenUV(a, b); uvw = Point3(a.x, a.y, 0.0f); } else if (sc.globContext != NULL && sc.NodeID() >= 0) { RenderInstance* ri = sc.globContext->GetRenderInstance(sc.NodeID()); Mesh* m = ri->mesh; if (m->mapSupport(uvChannel)) { Point3 bc = sc.BarycentricCoords(); int i = sc.FaceNumber(); UVVert* v = m->mapVerts(uvChannel); TVFace* f = m->mapFaces(uvChannel); uvw = v[f[i].t[0]] * bc.x + v[f[i].t[1]] * bc.y + v[f[i].t[2]] * bc.z; } else { uvw = Point3(0.0,0.0,0.0); } } else { uvw = Point3(0.0,0.0,0.0); } } else { uvw = sc.UVW(uvChannel); } #else Point3 uvw = sc.UVW(uvChannel); #endif if (clampUVW) { uvw.x = Clamp(uvw.x); uvw.y = Clamp(uvw.y); uvw.z = Clamp(uvw.z); } else { uvw.x = mod(uvw.x, 1.0000001f); uvw.y = mod(uvw.y, 1.0000001f); uvw.z = mod(uvw.z, 1.0000001f); } return EvalUVtex(uvw); }
// Seed random number generator void BerconGradient::seedRandomGen(ShadeContext& sc) { int seed = 1; if (previewMatIDMode) { seed = sc.mtlNum; } else { if (p_randMat) { seed += sc.mtlNum; } if (p_randObj) { int hand = (int)sc.Node()->GetHandle(); seed += hand*(hand*hand*15731 + 789221); } if (p_randPar) { Object *ob = sc.GetEvalObject(); if (ob && ob->IsParticleSystem()) { ParticleObject *obj = (ParticleObject*)ob; IChkMtlAPI* chkMtlAPI = static_cast<IChkMtlAPI*>(obj->GetInterface(I_NEWMTLINTERFACE)); if ((chkMtlAPI && chkMtlAPI->SupportsParticleIDbyFace())) { int id = chkMtlAPI->GetParticleFromFace(sc.FaceNumber()); seed += id*(id*id*571 + 789221); } } } if (p_randTile) { seed += (int)(sc.UVW(99).z); } } seed *= p_seed; srand(seed*(seed*seed*15731 + 789221)); }