double cPrimitives::PrimitiveSphere(CVector3 _point, const sPrimitiveSphere &sphere) const { CVector3 point = _point - sphere.position; point = sphere.rotationMatrix.RotateVector(point); point = point.mod(sphere.repeat); double dist = point.Length() - sphere.radius; return sphere.empty ? fabs(dist) : dist; }
double sPrimitiveSphere::PrimitiveDistance(CVector3 _point) const { CVector3 point = _point - position; point = rotationMatrix.RotateVector(point); point = point.mod(repeat); double dist = point.Length() - radius; return empty ? fabs(dist) : dist; }
double cPrimitives::PrimitiveRectangle(CVector3 _point, const sPrimitiveRectangle &rectangle) const { CVector3 point = _point - rectangle.position; point = rectangle.rotationMatrix.RotateVector(point); CVector3 boxTemp; boxTemp.x = max(fabs(point.x) - rectangle.width * 0.5, 0.0); boxTemp.y = max(fabs(point.y) - rectangle.height * 0.5, 0.0); boxTemp.z = fabs(point.z); return boxTemp.Length(); }
double sPrimitiveRectangle::PrimitiveDistance(CVector3 _point) const { CVector3 point = _point - position; point = rotationMatrix.RotateVector(point); CVector3 boxTemp; boxTemp.x = max(fabs(point.x) - width * 0.5, 0.0); boxTemp.y = max(fabs(point.y) - height * 0.5, 0.0); boxTemp.z = fabs(point.z); return boxTemp.Length(); }
sRGBAfloat cRenderWorker::LightShading(const sShaderInputData &input, cLights::sLight light, int number, sRGBAfloat *outSpecular) { sRGBAfloat shading; CVector3 d = light.position - input.point; double distance = d.Length(); //angle of incidence CVector3 lightVector = d; lightVector.Normalize(); double intensity = 100.0 * light.intensity / (distance * distance) / number; double shade = input.normal.Dot(lightVector); if (shade < 0) shade = 0; shade = shade * intensity; if (shade > 500.0) shade = 500.0; //specular CVector3 half = lightVector - input.viewVector; half.Normalize(); double shade2 = input.normal.Dot(half); if (shade2 < 0.0) shade2 = 0.0; shade2 = pow(shade2, 30.0) * 1.0; shade2 *= intensity * params->specular; if (shade2 > 15.0) shade2 = 15.0; //calculate shadow if ((shade > 0.01 || shade2 > 0.01) && params->shadow) { double light = AuxShadow(input, distance, lightVector); shade *= light; shade2 *= light; } else { if (params->shadow) { shade = 0; shade2 = 0; } } shading.R = shade * light.colour.R / 65536.0; shading.G = shade * light.colour.G / 65536.0; shading.B = shade * light.colour.B / 65536.0; outSpecular->R = shade2 * light.colour.R / 65536.0; outSpecular->G = shade2 * light.colour.G / 65536.0; outSpecular->B = shade2 * light.colour.B / 65536.0; return shading; }
double CalculateDistanceMinPlane(const sParamRender ¶ms, const cNineFractals &fractals, const CVector3 planePoint, const CVector3 direction, const CVector3 orthDirection, bool *stopRequest) { // the plane is defined by the 'planePoint' and the orthogogonal 'direction' // the method will return the minimum distance from the plane to the fractal double distStep = 0.0; CVector3 point = planePoint; const double detail = 0.5; const int transVectorAngles = 5; CVector3 rotationAxis = planePoint; rotationAxis.Normalize(); while (distStep == 0 || distStep > 0.00001) { CVector3 pointNextBest(0, 0, 0); double newDistStepMin = 0; for (int i = 0; i <= transVectorAngles; i++) { const double angle = (double(i) / transVectorAngles) * 2.0 * M_PI; CVector3 transversalVect = orthDirection; transversalVect = transversalVect.RotateAroundVectorByAngle(rotationAxis, angle); transversalVect.Normalize(); CVector3 pointNext = point + direction * distStep; if (i > 0) pointNext += transversalVect * distStep / 2.0; const sDistanceIn in(pointNext, 0, false); sDistanceOut out; const double dist = CalculateDistance(params, fractals, in, &out); const double newDistStep = dist * detail * 0.5; if (newDistStep < newDistStepMin || newDistStepMin == 0) { pointNextBest = pointNext; newDistStepMin = newDistStep; } } if (newDistStepMin > 1000) newDistStepMin = 1000; if (distStep != 0 && newDistStepMin > distStep) break; distStep = newDistStepMin; point = pointNextBest; // qDebug() << "pointNextBest" << pointNextBest.Debug(); if (point.Length() > 1000000) { WriteLog("CalculateDistanceMinPlane(): surface not found!", 1); return 0; } gApplication->processEvents(); if (*stopRequest) { return 0; } } return CVector3(point - planePoint).Dot(direction); }
// --[ Method ]--------------------------------------------------------------- // // - Class : CVector3 // - Prototype : float Angle(const CVector3& vector) // // - Purpose : Returns the angle between two vectors. // // --------------------------------------------------------------------------- float CVector3::Angle(const CVector3& vector) const { float fDotProduct = m_fX * vector.m_fX + m_fY * vector.m_fY + m_fZ * vector.m_fZ; float fArg = fDotProduct / (Length() * vector.Length()); #ifdef _DEBUG if(fArg < -1.0f || fArg > 1.0f) { CLogger::ErrorWindow("acosf arg %f (%f, %f, %f)*(%f, %f, %f)", fArg, m_fX, m_fY, m_fZ, vector.m_fX, vector.m_fY, vector.m_fZ); } #endif return RAD_TO_DEG(acosf(fArg)); }
void VectorToAngle(const CVector3 &v, CVector3 &a) { if (v.x == 0.f && v.y == 0.f) { if (v.z > 0.f) a.x = -90.f; else a.x = 90.f; a.y = 0.f; } else { a.x = -RAD2DEG(asin(v.z / (v.Length() + M_EPSILON))); a.y = RAD2DEG(atan2(v.y, v.x)); } a.z = 0.f; }
void BoxFoldBulbPow2Iteration(CVector3 &z, const cFractal *fractal) { if (z.x > fractal->foldingIntPow.foldfactor) z.x = fractal->foldingIntPow.foldfactor * 2.0 - z.x; else if (z.x < -fractal->foldingIntPow.foldfactor) z.x = -fractal->foldingIntPow.foldfactor * 2.0 - z.x; if (z.y > fractal->foldingIntPow.foldfactor) z.y = fractal->foldingIntPow.foldfactor * 2.0 - z.y; else if (z.y < -fractal->foldingIntPow.foldfactor) z.y = -fractal->foldingIntPow.foldfactor * 2.0 - z.y; if (z.z > fractal->foldingIntPow.foldfactor) z.z = fractal->foldingIntPow.foldfactor * 2.0 - z.z; else if (z.z < -fractal->foldingIntPow.foldfactor) z.z = -fractal->foldingIntPow.foldfactor * 2.0 - z.z; double r = z.Length(); double fR2_2 = 1.0; double mR2_2 = 0.25; double r2_2 = r * r; double tglad_factor1_2 = fR2_2 / mR2_2; if (r2_2 < mR2_2) { z = z * tglad_factor1_2; } else if (r2_2 < fR2_2) { double tglad_factor2_2 = fR2_2 / r2_2; z = z * tglad_factor2_2; } z = z * 2.0; double x2 = z.x * z.x; double y2 = z.y * z.y; double z2 = z.z * z.z; double temp = 1.0 - z2 / (x2 + y2); CVector3 zTemp; zTemp.x = (x2 - y2) * temp; zTemp.y = 2.0 * z.x * z.y * temp; zTemp.z = -2.0 * z.z * sqrt(x2 + y2); z = zTemp; z.z *= fractal->foldingIntPow.zFactor; //INFO remark: changed sequence of operation. adding of C constant was before multiplying by z-factor }
void SmoothMandelboxIteration(CVector3 &z, const cFractal *fractal, sMandelboxAux &aux) { double sm = fractal->mandelbox.sharpness; double zk1 = SmoothConditionAGreaterB(z.x, fractal->mandelbox.foldingLimit, sm); double zk2 = SmoothConditionALessB(z.x, -fractal->mandelbox.foldingLimit, sm); z.x = z.x * (1.0 - zk1) + (fractal->mandelbox.foldingValue - z.x) * zk1; z.x = z.x * (1.0 - zk2) + (-fractal->mandelbox.foldingValue - z.x) * zk2; aux.mboxColor += (zk1 + zk2) * fractal->mandelbox.colorFactor.x; double zk3 = SmoothConditionAGreaterB(z.y, fractal->mandelbox.foldingLimit, sm); double zk4 = SmoothConditionALessB(z.y, -fractal->mandelbox.foldingLimit, sm); z.y = z.y * (1.0 - zk3) + (fractal->mandelbox.foldingValue - z.y) * zk3; z.y = z.y * (1.0 - zk4) + (-fractal->mandelbox.foldingValue - z.y) * zk4; aux.mboxColor += (zk3 + zk4) * fractal->mandelbox.colorFactor.y; double zk5 = SmoothConditionAGreaterB(z.z, fractal->mandelbox.foldingLimit, sm); double zk6 = SmoothConditionALessB(z.z, -fractal->mandelbox.foldingLimit, sm); z.z = z.z * (1.0 - zk5) + (fractal->mandelbox.foldingValue - z.z) * zk5; z.z = z.z * (1.0 - zk6) + (-fractal->mandelbox.foldingValue - z.z) * zk6; aux.mboxColor += (zk5 + zk6) * fractal->mandelbox.colorFactor.z; double r = z.Length(); double r2 = r * r; double tglad_factor2 = fractal->mandelbox.fR2 / r2; double rk1 = SmoothConditionALessB(r2, fractal->mandelbox.mR2, sm); double rk2 = SmoothConditionALessB(r2, fractal->mandelbox.fR2, sm); double rk21 = (1.0 - rk1) * rk2; z = z * (1.0 - rk1) + z * (fractal->mandelbox.mboxFactor1 * rk1); z = z * (1.0 - rk21) + z * (tglad_factor2 * rk21); aux.mboxDE = aux.mboxDE * (1.0 - rk1) + aux.mboxDE * (fractal->mandelbox.mboxFactor1 * rk1); aux.mboxDE = aux.mboxDE * (1.0 - rk21) + aux.mboxDE * (tglad_factor2 * rk21); aux.mboxColor += rk1 * fractal->mandelbox.colorFactorSp1; aux.mboxColor += rk21 * fractal->mandelbox.colorFactorSp2; z = fractal->mandelbox.mainRot.RotateVector(z); z = z * fractal->mandelbox.scale; aux.mboxDE = aux.mboxDE * fabs(fractal->mandelbox.scale) + 1.0; }
/** * Check for ray intersection */ bool CBulletSphereModel::CheckIntersectionWithRay(Real &f_t_on_ray, const CRay3 &ray) const { CVector3 rayOrigin = ray.GetStart(); CVector3 rayDirection; ray.GetDirection(rayDirection); CVector3 sourceToOrigin = rayOrigin - position; double sourceToOriginLength = sourceToOrigin.Length(); double lineDotSourceToOrigin = rayDirection.DotProduct(sourceToOrigin); double solutionCheck = pow(lineDotSourceToOrigin, 2); solutionCheck -= pow(sourceToOriginLength, 2); solutionCheck += pow(entity->GetRadius(), 2); if(solutionCheck < 0) return false; f_t_on_ray = -lineDotSourceToOrigin - sqrt(solutionCheck); return true; }
double sPrimitiveBox::PrimitiveDistance(CVector3 _point) const { CVector3 point = _point - position; point = rotationMatrix.RotateVector(point); point = point.mod(repeat); if (empty) { double boxDist = -1e10; boxDist = max(fabs(point.x) - size.x * 0.5, boxDist); boxDist = max(fabs(point.y) - size.y * 0.5, boxDist); boxDist = max(fabs(point.z) - size.z * 0.5, boxDist); return fabs(boxDist); } else { CVector3 boxTemp; boxTemp.x = max(fabs(point.x) - size.x * 0.5, 0.0); boxTemp.y = max(fabs(point.y) - size.y * 0.5, 0.0); boxTemp.z = max(fabs(point.z) - size.z * 0.5, 0.0); return boxTemp.Length() - rounding; } }
double cPrimitives::PrimitiveBox(CVector3 _point, const sPrimitiveBox &box) const { CVector3 point = _point - box.position; point = box.rotationMatrix.RotateVector(point); point = point.mod(box.repeat); if(box.empty) { double boxDist = -1e10; boxDist = max(fabs(point.x) - box.size.x * 0.5, boxDist); boxDist = max(fabs(point.y) - box.size.y * 0.5, boxDist); boxDist = max(fabs(point.z) - box.size.z * 0.5, boxDist); return fabs(boxDist); } else { CVector3 boxTemp; boxTemp.x = max(fabs(point.x) - box.size.x * 0.5, 0.0); boxTemp.y = max(fabs(point.y) - box.size.y * 0.5, 0.0); boxTemp.z = max(fabs(point.z) - box.size.z * 0.5, 0.0); return boxTemp.Length() - box.rounding; } }
void CWiFiSensor::UpdateWithRange() { CSpace::TAnyEntityMap& tEntityMap = m_cSpace.GetEntitiesByType("wifi_equipped_entity"); /*Get the robot position*/ const CVector3& cRobotPosition = m_pcWiFiEquippedEntity->GetPosition(); /* Buffer for calculating the message--robot distance */ CVector3 cVectorToMessage; CVector3 cVectorRobotToMessage; Real fMessageDistance; TMessageList t_temporaryMsgs; for(CSpace::TAnyEntityMap::iterator it = tEntityMap.begin(); it != tEntityMap.end(); ++it){ CWiFiEquippedEntity& cWifiEntity = *(any_cast<CWiFiEquippedEntity*>(it->second)); /*Avoiding self messaging*/ if(&cWifiEntity != m_pcWiFiEquippedEntity){ cVectorToMessage = cWifiEntity.GetPosition(); cVectorRobotToMessage = cVectorToMessage - cRobotPosition; /* Check that the distance is lower than the range */ fMessageDistance = cVectorRobotToMessage.Length(); // std::cerr << "Distance is: " << fMessageDistance << std::endl; if(fMessageDistance < m_pcWiFiEquippedEntity->GetRange()){ t_temporaryMsgs = cWifiEntity.GetAllMessages(); Real probability = m_pcWiFiEquippedEntity->GetProbability(); for(TMessageList::iterator jt = t_temporaryMsgs.begin();jt != t_temporaryMsgs.end();++jt){ //std::cerr << jt->Payload << std::endl; if(jt->Recipient == m_pcEntity->GetId() || jt->Recipient == "-1"){ if ( m_pcRNG->Uniform(ProbRange) < (probability) ) { // Receive with a certain probability of success m_tMessages.push_back(*jt); } } } } } } }
void CEPuckRangeAndBearingSensor::Update() { /* Clear the previous received packets */ ClearRABReceivedPackets(); /* Get robot position */ const CVector3& cRobotPosition = m_pcEmbodiedEntity->GetPosition(); /* Get robot orientation */ CRadians cTmp1, cTmp2, cOrientationZ; m_pcEmbodiedEntity->GetOrientation().ToEulerAngles(cOrientationZ, cTmp1, cTmp2); /* Buffer for calculating the message--robot distance */ CVector3 cVectorToMessage; CVector3 cVectorRobotToMessage; Real fMessageDistance; /* Buffer for the received packet */ TEPuckRangeAndBearingReceivedPacket tPacket; /* Initialize the occlusion check ray start to the position of the robot */ CRay cOcclusionCheckRay; cOcclusionCheckRay.SetStart(cRobotPosition); /* Buffer to store the intersection data */ CSpace::SEntityIntersectionItem<CEmbodiedEntity> sIntersectionData; /* Ignore the sensing robot when checking for occlusions */ TEmbodiedEntitySet tIgnoreEntities; tIgnoreEntities.insert(m_pcEmbodiedEntity); /* * 1. Go through all the CRABEquippedEntities<2> (those compatible with this sensor) * 2. For each of them * a) Check that the receiver is not out of range * b) Check if there is an occlusion * c) If there isn't, get the info and set reading for that robot */ CSpace::TAnyEntityMap& tEntityMap = m_cSpace.GetEntitiesByType("rab_equipped_entity<2>"); for(CSpace::TAnyEntityMap::iterator it = tEntityMap.begin(); it != tEntityMap.end(); ++it) { CRABEquippedEntity<2>& cRABEntity = *(any_cast<CRABEquippedEntity<2>*>(it->second)); /* Check the RAB equipped entity is not this robot (avoid self-messaging) */ if(&cRABEntity != m_pcRABEquippedEntity) { /* Get the position of the RAB equipped entity */ cVectorToMessage = cRABEntity.GetPosition(); cVectorRobotToMessage = (cVectorToMessage - cRobotPosition) * 100; // in cms /* Check that the distance is lower than the range */ fMessageDistance = cVectorRobotToMessage.Length(); if(fMessageDistance < cRABEntity.GetRange()) { /* Set the ray end */ cOcclusionCheckRay.SetEnd(cVectorToMessage); /* Check occlusion between robot and message location */ if(!m_bCheckOcclusions || (! m_cSpace.GetClosestEmbodiedEntityIntersectedByRay(sIntersectionData, cOcclusionCheckRay, tIgnoreEntities)) || sIntersectionData.IntersectedEntity->GetId() == cRABEntity.GetId()) { /* The message is not occluded */ if(m_bShowRays) m_pcControllableEntity->AddCheckedRay(false, cOcclusionCheckRay); /* Set the reading */ tPacket.Id = m_unLatestPacketId++; CRadians cVertical = CRadians::ZERO; cVectorRobotToMessage.ToSphericalCoordsHorizontal(tPacket.Range, cVertical, tPacket.BearingHorizontal); tPacket.BearingHorizontal -= cOrientationZ; tPacket.BearingHorizontal.SignedNormalize(); cRABEntity.GetData(tPacket.Data); m_tLastReceivedPackets.push_back(tPacket); } else { /* The message is occluded */ if(m_bShowRays) { m_pcControllableEntity->AddCheckedRay(true, cOcclusionCheckRay); m_pcControllableEntity->AddIntersectionPoint(cOcclusionCheckRay, sIntersectionData.TOnRay); } } } } } }
void Compute(const cNineFractals &fractals, const sFractalIn &in, sFractalOut *out) { // QTextStream outStream(stdout); // clock_t tim; // tim = rdtsc(); // repeat, move and rotate CVector3 point2 = in.point.mod(in.common.repeat) - in.common.fractalPosition; point2 = in.common.mRotFractalRotation.RotateVector(point2); CVector3 z = point2; double r = z.Length(); CVector3 c = z; double minimumR = 100.0; double w = 0.0; double orbitTrapTotal = 0.0; enumFractalFormula formula = fractal::none; out->maxiter = true; int fractalIndex = 0; if (in.forcedFormulaIndex >= 0) fractalIndex = in.forcedFormulaIndex; const cFractal *defaultFractal = fractals.GetFractal(fractalIndex); sExtendedAux extendedAux; extendedAux.r_dz = 1.0; extendedAux.r = r; extendedAux.color = 1.0; extendedAux.actualScale = fractals.GetFractal(fractalIndex)->mandelbox.scale; extendedAux.DE = 1.0; extendedAux.c = c; extendedAux.cw = 0; extendedAux.foldFactor = 0.0; extendedAux.minRFactor = 0.0; extendedAux.scaleFactor = 0.0; // extendedAux.newR = 1e+20; // extendedAux.axisBias = 1e+20; // extendedAux.orbitTraps = 1e+20; // extendedAux.transformSampling = 1e+20; // main iteration loop int i; int sequence = 0; CVector3 lastGoodZ; CVector3 lastZ; for (i = 0; i < in.maxN; i++) { lastGoodZ = lastZ; lastZ = z; // hybrid fractal sequence if (in.forcedFormulaIndex >= 0) { sequence = in.forcedFormulaIndex; } else { sequence = fractals.GetSequence(i); } // foldings if (in.common.foldings.boxEnable) { BoxFolding(z, &in.common.foldings, extendedAux); r = z.Length(); } if (in.common.foldings.sphericalEnable) { extendedAux.r = r; SphericalFolding(z, &in.common.foldings, extendedAux); r = z.Length(); } const cFractal *fractal = fractals.GetFractal(sequence); formula = fractal->formula; // temporary vector for weight function CVector3 tempZ = z; extendedAux.r = r; if (!fractals.IsHybrid() || fractals.GetWeight(sequence) > 0.0) { // calls for fractal formulas switch (formula) { case mandelbulb: { MandelbulbIteration(z, fractal, extendedAux); break; } case mandelbulb2: { Mandelbulb2Iteration(z, extendedAux); break; } case mandelbulb3: { Mandelbulb3Iteration(z, extendedAux); break; } case mandelbulb4: { Mandelbulb4Iteration(z, fractal, extendedAux); break; } case fast_mandelbulb_power2: { MandelbulbPower2Iteration(z, extendedAux); break; } case xenodreambuie: { XenodreambuieIteration(z, fractal, extendedAux); break; } case mandelbox: { MandelboxIteration(z, fractal, extendedAux); break; } case smoothMandelbox: { SmoothMandelboxIteration(z, fractal, extendedAux); break; } case boxFoldBulbPow2: { BoxFoldBulbPow2Iteration(z, fractal); break; } case menger_sponge: { MengerSpongeIteration(z, extendedAux); break; } case kaleidoscopicIFS: { KaleidoscopicIFSIteration(z, fractal, extendedAux); break; } case aexion: { AexionIteration(z, w, i, fractal, extendedAux); break; } case hypercomplex: { HypercomplexIteration(z, w, extendedAux); break; } case quaternion: { QuaternionIteration(z, w, extendedAux); break; } case benesi: { BenesiIteration(z, c, extendedAux); break; } case bristorbrot: { BristorbrotIteration(z, extendedAux); break; } case ides: { IdesIteration(z, fractal); break; } case ides2: { Ides2Iteration(z, fractal); break; } case buffalo: { BuffaloIteration(z, fractal, extendedAux); break; } case quickdudley: { QuickDudleyIteration(z); break; } case quickDudleyMod: { QuickDudleyModIteration(z, fractal); break; } case lkmitch: { LkmitchIteration(z); break; } case makin3d2: { Makin3D2Iteration(z); break; } case msltoeDonut: { MsltoeDonutIteration(z, fractal, extendedAux); break; } case msltoesym2Mod: { MsltoeSym2ModIteration(z, c, fractal, extendedAux); break; } case msltoesym3Mod: { MsltoeSym3ModIteration(z, c, i, fractal, extendedAux); break; } case msltoesym3Mod2: { MsltoeSym3Mod2Iteration(z, c, fractal, extendedAux); break; } case msltoesym3Mod3: { MsltoeSym3Mod3Iteration(z, c, i, fractal, extendedAux); break; } case msltoesym4Mod: { MsltoeSym4ModIteration(z, c, fractal, extendedAux); break; } case msltoeToroidal: { MsltoeToroidalIteration(z, fractal, extendedAux); break; } case msltoeToroidalMulti: { MsltoeToroidalMultiIteration(z, fractal, extendedAux); break; } case generalizedFoldBox: { GeneralizedFoldBoxIteration(z, fractal, extendedAux); break; } case aboxMod1: { AboxMod1Iteration(z, fractal, extendedAux); break; } case aboxMod2: { AboxMod2Iteration(z, fractal, extendedAux); break; } case aboxModKali: { AboxModKaliIteration(z, fractal, extendedAux); break; } case aboxModKaliEiffie: { AboxModKaliEiffieIteration(z, c, i, fractal, extendedAux); break; } case aboxVSIcen1: { AboxVSIcen1Iteration(z, c, fractal, extendedAux); break; } case aexionOctopusMod: { AexionOctopusModIteration(z, c, fractal); break; } case amazingSurf: { AmazingSurfIteration(z, fractal, extendedAux); break; } case amazingSurfMod1: { AmazingSurfMod1Iteration(z, fractal, extendedAux); break; } case amazingSurfMulti: { AmazingSurfMultiIteration(z, i, fractal, extendedAux); break; } case benesiPineTree: { BenesiPineTreeIteration(z, c, fractal, extendedAux); break; } case benesiT1PineTree: { BenesiT1PineTreeIteration(z, c, i, fractal, extendedAux); break; } case benesiMagTransforms: { BenesiMagTransformsIteration(z, c, i, fractal, extendedAux); break; } case collatz: { CollatzIteration(z, extendedAux); break; } case collatzMod: { CollatzModIteration(z, c, fractal, extendedAux); break; } case eiffieMsltoe: { EiffieMsltoeIteration(z, c, fractal, extendedAux); break; } case foldBoxMod1: { FoldBoxMod1Iteration(z, i, fractal, extendedAux); break; } case iqBulb: { IQbulbIteration(z, fractal, extendedAux); break; } case kalisets1: { Kalisets1Iteration(z, c, fractal, extendedAux); break; } case mandelboxMenger: { MandelboxMengerIteration(z, c, i, fractal, extendedAux); break; } case mandelbulbBermarte: { MandelbulbBermarteIteration(z, fractal, extendedAux); break; } case mandelbulbKali: { MandelbulbKaliIteration(z, fractal, extendedAux); break; } case mandelbulbKaliMulti: { MandelbulbKaliMultiIteration(z, c, fractal, extendedAux); break; } case mandelbulbMulti: { MandelbulbMultiIteration(z, c, fractal, extendedAux); break; } case mandelbulbVaryPowerV1: { MandelbulbVaryPowerV1Iteration(z, i, fractal, extendedAux); break; } case mengerMod1: { MengerMod1Iteration(z, i, fractal, extendedAux); break; } case mengerMiddleMod: { MengerMiddleModIteration(z, c, i, fractal, extendedAux); break; } case mengerPrismShape: { MengerPrismShapeIteration(z, i, fractal, extendedAux); break; } case mengerPwr2Poly: { MengerPwr2PolyIteration(z, c, i, fractal, extendedAux); break; } case riemannSphereMsltoe: { RiemannSphereMsltoeIteration(z, fractal); break; } case riemannSphereMsltoeV1: { RiemannSphereMsltoeV1Iteration(z, fractal); break; } case riemannBulbMsltoeMod2: { RiemannBulbMsltoeMod2Iteration(z, fractal); break; } case quaternion3D: { Quaternion3DIteration(z, fractal, extendedAux); break; } case fastImagscaPower2: { FastImagscaPower2Iteration(z); break; } case crossMenger: { CrossMengerIteration(z, c, i, fractal, extendedAux); break; } // transforms // ------------------------------------------------------------------------------------------ case transfAdditionConstant: { TransformAdditionConstantIteration(z, fractal); break; } case transfAdditionConstantVaryV1: { TransformAdditionConstantVaryV1Iteration(z, i, fractal); break; } case transfAddCpixel: { TransformAddCpixelIteration(z, c, fractal); break; } case transfAddCpixelAxisSwap: { TransformAddCpixelAxisSwapIteration(z, c, fractal); break; } case transfAddCpixelCxCyAxisSwap: { TransformAddCpixelCxCyAxisSwapIteration(z, c, fractal); break; } case transfAddCpixelPosNeg: { TransformAddCpixelPosNegIteration(z, c, fractal); break; } case transfAddCpixelVaryV1: { TransformAddCpixelVaryV1Iteration(z, c, i, fractal); break; } case transfBenesiT1: { TransformBenesiT1Iteration(z, fractal, extendedAux); break; } case transfBenesiT1Mod: { TransformBenesiT1ModIteration(z, fractal, extendedAux); break; } case transfBenesiT2: { TransformBenesiT2Iteration(z, fractal, extendedAux); break; } case transfBenesiT3: { TransformBenesiT3Iteration(z, fractal); break; } case transfBenesiT4: { TransformBenesiT4Iteration(z, fractal); break; } case transfBenesiT5b: { TransformBenesiT5bIteration(z, fractal); break; } case transfBenesiMagForward: { TransformBenesiMagForwardIteration(z); break; } case transfBenesiMagBackward: { TransformBenesiMagBackwardIteration(z); break; } case transfBenesiCubeSphere: { TransformBenesiCubeSphereIteration(z); break; } case transfBenesiSphereCube: { TransformBenesiSphereCubeIteration(z); break; } case transfBoxFold: { TransformBoxFoldIteration(z, fractal, extendedAux); break; } case transfBoxFoldXYZ: { TransformBoxFoldXYZIteration(z, fractal, extendedAux); break; } case transfBoxOffset: { TransformBoxOffsetIteration(z, fractal, extendedAux); break; } case transfFabsAddConstant: { TransformFabsAddConstantIteration(z, fractal); break; } case transfFabsAddConstantV2: { TransformFabsAddConstantV2Iteration(z, fractal); break; } case transfFabsAddMulti: { TransformFabsAddMultiIteration(z, fractal); break; } case transfFoldingTetra3D: { TransformFoldingTetra3DIteration(z, fractal); break; } case transfIterationWeight: { TransformIterationWeightIteration(z, i, fractal); break; } case transfInvCylindrical: { TransformInvCylindricalIteration(z, fractal, extendedAux); break; } case transfLinCombineCxyz: { TransformLinCombineCxyz(c, fractal); break; } case transfMultipleAngle: { TransformMultipleAngle(z, fractal, extendedAux); break; } case transfNegFabsAddConstant: { TransformNegFabsAddConstantIteration(z, fractal); break; } case transfPwr2Polynomial: { TransformPwr2PolynomialIteration(z, fractal, extendedAux); break; } case transfRotation: { TransformRotationIteration(z, fractal); break; } case transfRotationVaryV1: { TransformRotationVaryV1Iteration(z, i, fractal); break; } case transfRpow3: { TransformRpow3Iteration(z, fractal, extendedAux); break; } case transfScale: { TransformScaleIteration(z, fractal, extendedAux); break; } case transfScaleVaryV1: { TransformScaleVaryV1Iteration(z, i, fractal, extendedAux); break; } case transfScale3D: { TransformScale3DIteration(z, fractal, extendedAux); break; } case platonicSolid: { TransformPlatonicSolidIteration(z, fractal); break; } case transfRPower: { TransformPowerR(z, fractal, extendedAux); break; } case transfSphereInvC: { TransformSphereInvCIteration(z, c, fractal); break; } case transfSphereInv: { TransformSphereInvIteration(z, fractal, extendedAux); break; } case transfSphericalOffset: { TransformSphericalOffsetIteration(z, fractal, extendedAux); break; } case transfSphericalFold: { TransformSphericalFoldIteration(z, fractal, extendedAux); break; } case transfSphericalFoldAbox: { TransformSphericalFoldAboxIteration(z, fractal, extendedAux); break; } case transfSphericalFoldVaryV1: { TransformSphericalFoldVaryV1Iteration(z, i, fractal, extendedAux); break; } case transfSphericalPwrFold: { TransformSphericalPwrFoldIteration(z, fractal, extendedAux); break; } case transfSurfFoldMulti: { TransformSurfFoldMultiIteration(z, fractal, extendedAux); break; } case transfZvectorAxisSwap: { TransformZvectorAxisSwapIteration(z, fractal); break; } case transfRotationFoldingPlane: { TransformRotationFoldingPlane(z, fractal, extendedAux); break; } case transfQuaternionFold: { TransformQuaternionFoldIteration(z, c, fractal, extendedAux); break; } case transfMengerFold: { TransformMengerFoldIteration(z, fractal, extendedAux); break; } // 4D --------------------------------------------------------------------------- case quaternion4D: { CVector4 z4D(z, w); Quaternion4DIteration(z4D, i, fractal); z = z4D.GetXYZ(); w = z4D.w; break; } case mandelboxVaryScale4D: { CVector4 z4D(z, w); MandelboxVaryScale4DIteration(z4D, i, fractal, extendedAux); z = z4D.GetXYZ(); w = z4D.w; break; } case transfAdditionConstant4D: { CVector4 z4D(z, w); TransformAdditionConstant4DIteration(z4D, fractal); z = z4D.GetXYZ(); w = z4D.w; break; } case transfBoxFold4D: { CVector4 z4D(z, w); TransformBoxFold4DIteration(z4D, fractal, extendedAux); z = z4D.GetXYZ(); w = z4D.w; break; } case transfFabsAddConstant4D: { CVector4 z4D(z, w); TransformFabsAddConstant4DIteration(z4D, fractal); z = z4D.GetXYZ(); w = z4D.w; break; } case transfFabsAddConstantV24D: { CVector4 z4D(z, w); TransformFabsAddConstantV24DIteration(z4D, fractal); z = z4D.GetXYZ(); w = z4D.w; break; } case transfIterationWeight4D: { CVector4 z4D(z, w); TransformIterationWeight4DIteration(z4D, i, fractal); z = z4D.GetXYZ(); w = z4D.w; break; } case transfScale4D: { CVector4 z4D(z, w); TransformScale4DIteration(z4D, fractal, extendedAux); z = z4D.GetXYZ(); w = z4D.w; break; } case transfSphericalFold4D: { CVector4 z4D(z, w); TransformSphericalFold4DIteration(z4D, fractal, extendedAux); z = z4D.GetXYZ(); w = z4D.w; break; } default: double high = fractals.GetBailout(sequence) * 10.0; z = CVector3(high, high, high); break; } } // addition of constant if (fractals.IsAddCConstant(sequence)) { switch (formula) { case aboxMod1: case amazingSurf: // case amazingSurfMod1: { if (fractals.IsJuliaEnabled(sequence)) { CVector3 juliaC = fractals.GetJuliaConstant(sequence) * fractals.GetConstantMultiplier(sequence); z += CVector3(juliaC.y, juliaC.x, juliaC.z); } else { z += CVector3(c.y, c.x, c.z) * fractals.GetConstantMultiplier(sequence); } break; } default: { if (fractals.IsJuliaEnabled(sequence)) { z += fractals.GetJuliaConstant(sequence) * fractals.GetConstantMultiplier(sequence); } else { z += c * fractals.GetConstantMultiplier(sequence); } break; } } } if (fractals.IsHybrid()) { z = SmoothCVector(tempZ, z, fractals.GetWeight(sequence)); } // r calculation // r = sqrt(z.x * z.x + z.y * z.y + z.z * z.z + w * w); switch (fractal->formula) { case fastImagscaPower2: { CVector3 z2 = z * z; r = sqrt(z2.x + z2.y + z2.z) + (z2.y * z2.z) / (z2.x); break; } // scator magnitudes // magnitude in imaginary scator algebra default: { r = sqrt(z.x * z.x + z.y * z.y + z.z * z.z + w * w); break; } } if (z.IsNotANumber()) { z = lastZ; r = z.Length(); w = 0.0; out->maxiter = true; break; } // escape conditions if (fractals.IsCheckForBailout(sequence)) { if (Mode == calcModeNormal) { if (r > fractals.GetBailout(sequence)) { out->maxiter = false; break; } } else if (Mode == calcModeDeltaDE1) { if (r > fractals.GetBailout(sequence)) { out->maxiter = false; break; } } else if (Mode == calcModeDeltaDE2) { if (i == in.maxN) break; } else if (Mode == calcModeColouring) { double len = 0.0; switch (in.fractalColoring.coloringAlgorithm) { case sFractalColoring::fractalColoringStandard: { len = r; break; } case sFractalColoring::fractalColoringZDotPoint: { len = fabs(z.Dot(in.point)); break; } case sFractalColoring::fractalColoringSphere: { len = fabs((z - in.point).Length() - in.fractalColoring.sphereRadius); break; } case sFractalColoring::fractalColoringCross: { len = dMin(fabs(z.x), fabs(z.y), fabs(z.z)); break; } case sFractalColoring::fractalColoringLine: { len = fabs(z.Dot(in.fractalColoring.lineDirection)); break; } case sFractalColoring::fractalColoringNone: { len = r; break; } } if (fractal->formula != mandelbox || in.fractalColoring.coloringAlgorithm != sFractalColoring::fractalColoringStandard) { if (len < minimumR) minimumR = len; } if (r > 1e15) break; } else if (Mode == calcModeOrbitTrap) { CVector3 delta = z - in.common.fakeLightsOrbitTrap; double distance = delta.Length(); if (i >= in.common.fakeLightsMinIter && i <= in.common.fakeLightsMaxIter) orbitTrapTotal += (1.0f / (distance * distance)); if (distance > 1000) { out->orbitTrapR = orbitTrapTotal; break; } } } if (z.IsNotANumber()) // detection of dead computation { // if(Mode != calcModeColouring) // qWarning() << "Dead computation\n" // << "iteration: " << i << "Formula:" << formula << "Sequence:" << sequence // << "\nPoint:" << in.point.Debug() // << "\nLast good z:" << lastGoodZ.Debug() // << "\nPrevious z:" << lastZ.Debug(); z = lastGoodZ; break; } } // final calculations if (Mode == calcModeNormal) { if (fractals.IsHybrid()) { if (extendedAux.r_dz > 0) { if (fractals.GetDEFunctionType(0) == fractal::linearDEFunction) { out->distance = r / fabs(extendedAux.DE); } else if (fractals.GetDEFunctionType(0) == fractal::logarithmicDEFunction) { out->distance = 0.5 * r * log(r) / extendedAux.r_dz; } } else { out->distance = r; } } else { switch (formula) { case benesi: case benesiPineTree: case benesiT1PineTree: case bristorbrot: case buffalo: case eiffieMsltoe: case fast_mandelbulb_power2: case hypercomplex: case iqBulb: case mandelbulb: case mandelbulb2: case mandelbulb3: case mandelbulb4: case mandelbulbBermarte: case mandelbulbKali: case mandelbulbKaliMulti: case mandelbulbMulti: case mandelbulbVaryPowerV1: case msltoesym2Mod: case msltoesym3Mod: case msltoesym3Mod2: case msltoesym3Mod3: case msltoesym4Mod: case msltoeToroidal: // TODO fix?? case msltoeToroidalMulti: // TODO fix?? case quaternion: case transfQuaternionFold: // hmmm, this issue again case quaternion3D: case xenodreambuie: { if (extendedAux.r_dz > 0) out->distance = 0.5 * r * log(r) / extendedAux.r_dz; else out->distance = r; break; } case mandelbox: case mandelboxMenger: case smoothMandelbox: case mandelboxVaryScale4D: case generalizedFoldBox: case foldBoxMod1: case aboxModKali: case aboxModKaliEiffie: case aboxMod1: case aboxMod2: case amazingSurf: case amazingSurfMod1: case amazingSurfMulti: case kalisets1: case aboxVSIcen1: { if (extendedAux.DE > 0) out->distance = r / fabs(extendedAux.DE); else out->distance = r; break; } case kaleidoscopicIFS: case menger_sponge: case crossMenger: case mengerPrismShape: case collatz: case collatzMod: case mengerMod1: case mengerMiddleMod: case transfMengerFold: // hmmm, this issue again case mengerPwr2Poly: { if (extendedAux.DE > 0) out->distance = (r - 2.0) / (extendedAux.DE); else out->distance = r; break; } default: out->distance = -1.0; break; } } } // color calculation else if (Mode == calcModeColouring) { double mboxDE = 1.0; mboxDE = extendedAux.DE; double r2 = r / fabs(mboxDE); if (r2 > 20) r2 = 20; if (fractals.IsHybrid()) { if (minimumR > 100) minimumR = 100; double mboxColor = 0.0; mboxColor = extendedAux.color; if (mboxColor > 1000) mboxColor = 1000; out->colorIndex = minimumR * 1000.0 + mboxColor * 100 + r2 * 5000.0; /*out->colorIndex = extendedAux.color * 100.0 * extendedAux.foldFactor // folds part + r * defaultFractal->mandelbox.color.factorR / 1e13 // abs z part + 1.0 * r2 * 5000.0 // for backwards compatability + extendedAux.scaleFactor * r * i / 1e15 // scale part conditional on i & r + ((in.fractalColoring.coloringAlgorithm != sFractalColoring::fractalColoringStandard) ? minimumR * extendedAux.minRFactor * 1000.0 : 0.0);*/ } else { switch (formula) { case mandelbox: case smoothMandelbox: case mandelboxVaryScale4D: case generalizedFoldBox: case amazingSurfMod1: case foldBoxMod1: out->colorIndex = extendedAux.color * 100.0 // folds part + r * defaultFractal->mandelbox.color.factorR / 1e13 // abs z part + ((in.fractalColoring.coloringAlgorithm != sFractalColoring::fractalColoringStandard) ? minimumR * 1000.0 : 0.0); break; case mengerMod1: case aboxModKali: case aboxMod1: case menger_sponge: case collatz: case collatzMod: case kaleidoscopicIFS: case mengerPwr2Poly: case mengerMiddleMod: out->colorIndex = minimumR * 1000.0; break; case amazingSurf: out->colorIndex = minimumR * 200.0; break; case amazingSurfMulti: case mandelboxMenger: // case amazingSurfMod1: out->colorIndex = extendedAux.color * 100.0 * extendedAux.foldFactor // folds part + r * defaultFractal->mandelbox.color.factorR / 1e13 // abs z part + extendedAux.scaleFactor * r2 * 5000.0 // for backwards compatability //+ extendedAux.scaleFactor * r * i / 1e15 // scale part conditional on i & r + ((in.fractalColoring.coloringAlgorithm != sFractalColoring::fractalColoringStandard) ? minimumR * extendedAux.minRFactor * 1000.0 : 0.0); break; case msltoeDonut: out->colorIndex = extendedAux.color * 2000.0 / i; break; default: out->colorIndex = minimumR * 5000.0; break; } } } else { out->distance = 0.0; } out->iters = i + 1; out->z = z; // CVector3( z.x, z.y, w); // tim = rdtsc() - tim; perf+= tim; perfCount++; outStream << (double)perf/perfCount - 560.0 << // endl; //------------- 3249 ns for all calculation ---------------- }
sRGBAfloat cRenderWorker::VolumetricShader( const sShaderInputData &input, sRGBAfloat oldPixel, sRGBAfloat *opacityOut) { sRGBAfloat output; float totalOpacity = 0.0; output.R = oldPixel.R; output.G = oldPixel.G; output.B = oldPixel.B; output.A = oldPixel.A; // volumetric fog init double colourThresh = params->volFogColour1Distance; double colourThresh2 = params->volFogColour2Distance; double fogReduce = params->volFogDistanceFactor; double fogIntensity = params->volFogDensity; // visible lights init int numberOfLights = data->lights.GetNumberOfLights(); if (numberOfLights < 4) numberOfLights = 4; // glow init double glow = input.stepCount * params->glowIntensity / 512.0 * params->DEFactor; double glowN = 1.0 - glow; if (glowN < 0.0) glowN = 0.0; double glowR = (params->glowColor1.R * glowN + params->glowColor2.R * glow) / 65536.0; double glowG = (params->glowColor1.G * glowN + params->glowColor2.G * glow) / 65536.0; double glowB = (params->glowColor1.B * glowN + params->glowColor2.B * glow) / 65536.0; double totalStep = 0.0; // qDebug() << "Start volumetric shader &&&&&&&&&&&&&&&&&&&&"; sShaderInputData input2 = input; for (int index = input.stepCount - 1; index > 0; index--) { double step = input.stepBuff[index].step; double distance = input.stepBuff[index].distance; CVector3 point = input.stepBuff[index].point; totalStep += step; input2.point = point; input2.distThresh = input.stepBuff[index].distThresh; // qDebug() << "i" << index << "dist" << distance << "iters" << input.stepBuff[index].iters << // "distThresh" << input2.distThresh << "step" << step << "point" << point.Debug(); if (totalStep < CalcDelta(point)) { continue; } step = totalStep; totalStep = 0.0; //------------------- glow if (params->glowEnabled) { double glowOpacity = glow / input.stepCount; if (glowOpacity > 1.0) glowOpacity = 1.0; output.R = glowOpacity * glowR + (1.0 - glowOpacity) * output.R; output.G = glowOpacity * glowG + (1.0 - glowOpacity) * output.G; output.B = glowOpacity * glowB + (1.0 - glowOpacity) * output.B; output.A += glowOpacity; } // qDebug() << "step" << step; //------------------ visible light if (params->auxLightVisibility > 0) { double miniStep = 0.0; double lastMiniSteps = -1.0; for (double miniSteps = 0.0; miniSteps < step; miniSteps += miniStep) { double lowestLightSize = 1e10; double lowestLightDist = 1e10; for (int i = 0; i < numberOfLights; ++i) { const cLights::sLight *light = data->lights.GetLight(i); if (light->enabled) { CVector3 lightDistVect = (point - input.viewVector * miniSteps) - light->position; double lightDist = lightDistVect.Length(); double lightSize = sqrt(light->intensity) * params->auxLightVisibilitySize; double distToLightSurface = lightDist - lightSize; if (distToLightSurface < 0.0) distToLightSurface = 0.0; if (distToLightSurface <= lowestLightDist) { if (lightSize < lowestLightSize) { lowestLightSize = lightSize; } lowestLightDist = distToLightSurface; } } } miniStep = 0.1 * (lowestLightDist + 0.1 * lowestLightSize); if (miniStep > step - miniSteps) miniStep = step - miniSteps; // qDebug() << "lowDist:" << lowestLightDist << "lowSize" << lowestLightSize << "miniStep" // << miniStep; for (int i = 0; i < numberOfLights; ++i) { const cLights::sLight *light = data->lights.GetLight(i); if (light->enabled) { CVector3 lightDistVect = (point - input.viewVector * miniSteps) - light->position; double lightDist = lightDistVect.Length(); double lightSize = sqrt(light->intensity) * params->auxLightVisibilitySize; double r2 = lightDist / lightSize; double bellFunction = 1.0 / (1.0 + pow(r2, 4.0)); double lightDensity = miniStep * bellFunction * params->auxLightVisibility / lightSize; output.R += lightDensity * light->colour.R / 65536.0; output.G += lightDensity * light->colour.G / 65536.0; output.B += lightDensity * light->colour.B / 65536.0; output.A += lightDensity; } } if (miniSteps == lastMiniSteps) { // qWarning() << "Dead computation\n" // << "\npoint:" << (point - input.viewVector * miniSteps).Debug(); break; } lastMiniSteps = miniSteps; } } // fake lights (orbit trap) if (params->fakeLightsEnabled) { sFractalIn fractIn(point, params->minN, params->N, params->common, -1); sFractalOut fractOut; Compute<fractal::calcModeOrbitTrap>(*fractal, fractIn, &fractOut); double r = fractOut.orbitTrapR; r = sqrt(1.0f / (r + 1.0e-30f)); double fakeLight = 1.0 / (pow(r, 10.0 / params->fakeLightsVisibilitySize) * pow(10.0, 10.0 / params->fakeLightsVisibilitySize) + 1e-100); output.R += fakeLight * step * params->fakeLightsVisibility; output.G += fakeLight * step * params->fakeLightsVisibility; output.B += fakeLight * step * params->fakeLightsVisibility; output.A += fakeLight * step * params->fakeLightsVisibility; } //---------------------- volumetric lights with shadows in fog for (int i = 0; i < 5; i++) { if (i == 0 && params->volumetricLightEnabled[0]) { sRGBAfloat shadowOutputTemp = MainShadow(input2); output.R += shadowOutputTemp.R * step * params->volumetricLightIntensity[0] * params->mainLightColour.R / 65536.0; output.G += shadowOutputTemp.G * step * params->volumetricLightIntensity[0] * params->mainLightColour.G / 65536.0; output.B += shadowOutputTemp.B * step * params->volumetricLightIntensity[0] * params->mainLightColour.B / 65536.0; output.A += (shadowOutputTemp.R + shadowOutputTemp.G + shadowOutputTemp.B) / 3.0 * step * params->volumetricLightIntensity[0]; } if (i > 0) { const cLights::sLight *light = data->lights.GetLight(i - 1); if (light->enabled && params->volumetricLightEnabled[i]) { CVector3 lightVectorTemp = light->position - point; double distanceLight = lightVectorTemp.Length(); double distanceLight2 = distanceLight * distanceLight; lightVectorTemp.Normalize(); double lightShadow = AuxShadow(input2, distanceLight, lightVectorTemp); output.R += lightShadow * light->colour.R / 65536.0 * params->volumetricLightIntensity[i] * step / distanceLight2; output.G += lightShadow * light->colour.G / 65536.0 * params->volumetricLightIntensity[i] * step / distanceLight2; output.B += lightShadow * light->colour.B / 65536.0 * params->volumetricLightIntensity[i] * step / distanceLight2; output.A += lightShadow * params->volumetricLightIntensity[i] * step / distanceLight2; } } } //----------------------- basic fog if (params->fogEnabled) { double fogDensity = step / params->fogVisibility; if (fogDensity > 1.0) fogDensity = 1.0; output.R = fogDensity * params->fogColor.R / 65536.0 + (1.0 - fogDensity) * output.R; output.G = fogDensity * params->fogColor.G / 65536.0 + (1.0 - fogDensity) * output.G; output.B = fogDensity * params->fogColor.B / 65536.0 + (1.0 - fogDensity) * output.B; totalOpacity = fogDensity + (1.0 - fogDensity) * totalOpacity; output.A = fogDensity + (1.0 - fogDensity) * output.A; } //-------------------- volumetric fog if (fogIntensity > 0.0 && params->volFogEnabled) { double densityTemp = (step * fogReduce) / (distance * distance + fogReduce * fogReduce); double k = distance / colourThresh; if (k > 1) k = 1.0; double kn = 1.0 - k; double fogRtemp = (params->volFogColour1.R * kn + params->volFogColour2.R * k); double fogGtemp = (params->volFogColour1.G * kn + params->volFogColour2.G * k); double fogBtemp = (params->volFogColour1.B * kn + params->volFogColour2.B * k); double k2 = distance / colourThresh2 * k; if (k2 > 1) k2 = 1.0; kn = 1.0 - k2; fogRtemp = (fogRtemp * kn + params->volFogColour3.R * k2); fogGtemp = (fogGtemp * kn + params->volFogColour3.G * k2); fogBtemp = (fogBtemp * kn + params->volFogColour3.B * k2); double fogDensity = 0.3 * fogIntensity * densityTemp / (1.0 + fogIntensity * densityTemp); if (fogDensity > 1) fogDensity = 1.0; output.R = fogDensity * fogRtemp / 65536.0 + (1.0 - fogDensity) * output.R; output.G = fogDensity * fogGtemp / 65536.0 + (1.0 - fogDensity) * output.G; output.B = fogDensity * fogBtemp / 65536.0 + (1.0 - fogDensity) * output.B; // qDebug() << "densityTemp " << densityTemp << "k" << k << "k2" << k2 << "fogTempR" << // fogRtemp << "fogDensity" << fogDensity << "output.R" << output.R; totalOpacity = fogDensity + (1.0 - fogDensity) * totalOpacity; output.A = fogDensity + (1.0 - fogDensity) * output.A; } // iter fog if (params->iterFogEnabled) { int L = input.stepBuff[index].iters; double opacity = IterOpacity(step, L, params->N, params->iterFogOpacityTrim, params->iterFogOpacity); sRGBAfloat newColour(0.0, 0.0, 0.0, 0.0); if (opacity > 0) { // fog colour double iterFactor1 = (L - params->iterFogOpacityTrim) / (params->iterFogColor1Maxiter - params->iterFogOpacityTrim); double k = iterFactor1; if (k > 1.0) k = 1.0; if (k < 0.0) k = 0.0; double kn = 1.0 - k; double fogColR = (params->iterFogColour1.R * kn + params->iterFogColour2.R * k); double fogColG = (params->iterFogColour1.G * kn + params->iterFogColour2.G * k); double fogColB = (params->iterFogColour1.B * kn + params->iterFogColour2.B * k); double iterFactor2 = (L - params->iterFogColor1Maxiter) / (params->iterFogColor2Maxiter - params->iterFogColor1Maxiter); double k2 = iterFactor2; if (k2 < 0.0) k2 = 0.0; if (k2 > 1.0) k2 = 1.0; kn = 1.0 - k2; fogColR = (fogColR * kn + params->iterFogColour3.R * k2); fogColG = (fogColG * kn + params->iterFogColour3.G * k2); fogColB = (fogColB * kn + params->iterFogColour3.B * k2); //---- for (int i = 0; i < 5; i++) { if (i == 0) { if (params->mainLightEnable && params->mainLightIntensity > 0.0) { sRGBAfloat shadowOutputTemp = MainShadow(input2); newColour.R += shadowOutputTemp.R * params->mainLightColour.R / 65536.0 * params->mainLightIntensity; newColour.G += shadowOutputTemp.G * params->mainLightColour.G / 65536.0 * params->mainLightIntensity; newColour.B += shadowOutputTemp.B * params->mainLightColour.B / 65536.0 * params->mainLightIntensity; } } if (i > 0) { const cLights::sLight *light = data->lights.GetLight(i - 1); if (light->enabled) { CVector3 lightVectorTemp = light->position - point; double distanceLight = lightVectorTemp.Length(); double distanceLight2 = distanceLight * distanceLight; lightVectorTemp.Normalize(); double lightShadow = AuxShadow(input2, distanceLight, lightVectorTemp); double intensity = light->intensity * 100.0; newColour.R += lightShadow * light->colour.R / 65536.0 / distanceLight2 * intensity; newColour.G += lightShadow * light->colour.G / 65536.0 / distanceLight2 * intensity; newColour.B += lightShadow * light->colour.B / 65536.0 / distanceLight2 * intensity; } } } if (params->ambientOcclusionEnabled && params->ambientOcclusionMode == params::AOmodeMultipeRays) { sRGBAfloat AO = AmbientOcclusion(input2); newColour.R += AO.R * params->ambientOcclusion; newColour.G += AO.G * params->ambientOcclusion; newColour.B += AO.B * params->ambientOcclusion; } if (opacity > 1.0) opacity = 1.0; output.R = output.R * (1.0 - opacity) + newColour.R * opacity * fogColR / 65536.0; output.G = output.G * (1.0 - opacity) + newColour.G * opacity * fogColG / 65536.0; output.B = output.B * (1.0 - opacity) + newColour.B * opacity * fogColB / 65536.0; totalOpacity = opacity + (1.0 - opacity) * totalOpacity; output.A = opacity + (1.0 - opacity) * output.A; } } if (totalOpacity > 1.0) totalOpacity = 1.0; if (output.A > 1.0) output.A = 1.0; (*opacityOut).R = totalOpacity; (*opacityOut).G = totalOpacity; (*opacityOut).B = totalOpacity; } // next stepCount return output; }
sRGBAfloat cRenderWorker::LightShading( const sShaderInputData &input, const cLights::sLight *light, int number, sRGBAfloat *outSpecular) { sRGBAfloat shading; CVector3 d = light->position - input.point; double distance = d.Length(); // angle of incidence CVector3 lightVector = d; lightVector.Normalize(); double intensity = 100.0 * light->intensity / (distance * distance) / number; double shade = input.normal.Dot(lightVector); if (shade < 0) shade = 0; shade = (1.0 - input.material->shading) + shade * input.material->shading; shade = shade * intensity; if (shade > 500.0) shade = 500.0; // specular CVector3 half = lightVector - input.viewVector; half.Normalize(); double shade2 = input.normal.Dot(half); if (shade2 < 0.0) shade2 = 0.0; double diffuse = 10.0 * (1.1 - input.material->diffussionTextureIntensity * (input.texDiffuse.R + input.texDiffuse.G + input.texDiffuse.B) / 3.0); shade2 = pow(shade2, 30.0 / input.material->specularWidth / diffuse) / diffuse; shade2 *= intensity * input.material->specular; if (shade2 > 15.0) shade2 = 15.0; // calculate shadow if ((shade > 0.01 || shade2 > 0.01) && params->shadow) { double auxShadow = AuxShadow(input, distance, lightVector); shade *= auxShadow; shade2 *= auxShadow; } else { if (params->shadow) { shade = 0; shade2 = 0; } } shading.R = shade * light->colour.R / 65536.0; shading.G = shade * light->colour.G / 65536.0; shading.B = shade * light->colour.B / 65536.0; outSpecular->R = shade2 * light->colour.R / 65536.0; outSpecular->G = shade2 * light->colour.G / 65536.0; outSpecular->B = shade2 * light->colour.B / 65536.0; return shading; }
/*! * @brief 衝突検出と解決。 *@param[in] nextPosition 次の座標。 */ void EnemyTest::CollisionDetectAndResolve(CVector3 nextPosition) { //XZ平面を調べる。 { int loopCount = 0; while (true) { CVector3 addPos; addPos.Subtract(nextPosition, position); CVector3 posTmp = position; posTmp.y += radius + 0.2f; btTransform start, end; start.setIdentity(); end.setIdentity(); start.setOrigin(*(btVector3*)(&posTmp)); CVector3 newPos; SweepResultWall callback; callback.startPos = position; CVector3 addPosXZ = addPos; addPosXZ.y = 0.0f; if (addPosXZ.Length() > 0.0001f) { newPos.Add(posTmp, addPosXZ); end.setOrigin(btVector3(newPos.x, newPos.y, newPos.z)); PhysicsWorld().ConvexSweepTest((const btConvexShape*)collider.GetBody(), start, end, callback); } if (callback.isHit) { //当たった。 float t = fabsf(acosf(callback.hitNormal.Dot(CVector3::Up))); if (t >= CMath::PI * 0.3f) { //壁。 nextPosition.x = callback.hitPos.x; nextPosition.z = callback.hitPos.z; //半径分押し戻す。 CVector3 hitNormalXZ = callback.hitNormal; hitNormalXZ.y = 0.0f; hitNormalXZ.Normalize(); CVector3 t = hitNormalXZ; t.Scale(radius); nextPosition.Add(t); //続いて壁に沿って滑らせる。 t.Cross(hitNormalXZ, CVector3::Up); t.Normalize(); //押し戻しで動いた分は減算する。 CVector3 t2; t2.Subtract(nextPosition, position); t2.y = 0.0f; addPosXZ.Subtract(t2); t.Scale(t.Dot(addPosXZ)); nextPosition.Add(t); } } else { //どことも当たらないので終わり。 break; } loopCount++; if (loopCount == 5) { break; } } } //下方向を調べる。 { CVector3 addPos; addPos.Subtract(nextPosition, position); btTransform start, end; start.setIdentity(); end.setIdentity(); start.setOrigin(btVector3(position.x, position.y + radius, position.z)); CVector3 newPos; SweepResultGround callback; callback.startPos = position; if (addPos.y < 0.0f) { newPos = (*(CVector3*)&start.getOrigin()); newPos.y += addPos.y; end.setOrigin(btVector3(newPos.x, newPos.y, newPos.z)); PhysicsWorld().ConvexSweepTest((const btConvexShape*)collider.GetBody(), start, end, callback); } if (callback.isHit) { //当たった。 float t = fabsf(acosf(callback.hitNormal.Dot(CVector3::Up))); if (t < CMath::PI * 0.3f) { //地面。 CVector3 Circle; float x = 0.0f; float offset = 0.0f; //押し戻す量。 Circle = CVector3::Zero; Circle = position; Circle.y = callback.hitPos.y;//円の中心 CVector3 v; v.Subtract(Circle, callback.hitPos); x = v.Length();//物体の角とプレイヤーの間の横幅の距離が求まる。 offset = sqrt(max(0.0f, radius*radius - x*x));//yの平方根を求める。 moveSpeed.y = 0.0f; isJump = false; nextPosition.y = callback.hitPos.y + offset - radius; } } } position = nextPosition; }
void EnemyTest::Update() { CVector3 nextPosition = position; const float MOVE_SPEED = 5.0f; if (state == enStateRun || state == enStateStand) { if (Pad(0).IsTrigger(enButtonRB3)) { isPointLightOn = !isPointLightOn; } if (Pad(0).IsPress(enButtonA)) { //Aボタンが押された。 //車との距離を調べる。 CVector3 diff = g_car->GetPosition(); diff.Subtract(position); if (diff.Length() < 2.0f) { //車との距離が2m以内。 state = enState_RideOnCar; skinModel.SetShadowReceiverFlag(false); skinModel.SetShadowCasterFlag(false); g_car->SetRideOnFlag(true); g_camera->SetCar(g_car); return; } else if(!isJump){ //車との距離が離れていたらジャンプ。 moveSpeed.y = 8.0f; isJump = true; } } //走りか立ち状態の時。 CVector3 moveDirLocal; moveDirLocal.y = 0.0f; moveDirLocal.x = Pad(0).GetLStickXF(); moveDirLocal.z = Pad(0).GetLStickYF(); const CMatrix& mViewInv = g_camera->GetCamera().GetViewMatrixInv(); //カメラ空間から見た奥方向のベクトルを取得。 CVector3 cameraZ; cameraZ.x = mViewInv.m[2][0]; cameraZ.y = 0.0f; //Y軸いらない。 cameraZ.z = mViewInv.m[2][2]; cameraZ.Normalize(); //Y軸を打ち消しているので正規化する。 //カメラから見た横方向のベクトルを取得。 CVector3 cameraX; cameraX.x = mViewInv.m[0][0]; cameraX.y = 0.0f; //Y軸はいらない。 cameraX.z = mViewInv.m[0][2]; cameraX.Normalize(); //Y軸を打ち消しているので正規化する。 CVector3 moveDir; moveDir.x = cameraX.x * moveDirLocal.x + cameraZ.x * moveDirLocal.z; moveDir.y = 0.0f; //Y軸はいらない。 moveDir.z = cameraX.z * moveDirLocal.x + cameraZ.z * moveDirLocal.z; moveSpeed.x = moveDir.x * MOVE_SPEED; moveSpeed.z = moveDir.z * MOVE_SPEED; //Y方向には重力落下を加える。 const float GRAVITY = -18.8f; moveSpeed.y += GRAVITY * GameTime().GetFrameDeltaTime(); CVector3 addPos = moveSpeed; addPos.Scale(GameTime().GetFrameDeltaTime()); nextPosition.Add(addPos); if (moveDir.LengthSq() > 0.0001f) { rotation.SetRotation(CVector3::Up, atan2f(moveDir.x, moveDir.z)); //走り状態に遷移。 state = enStateRun; } else { //立ち状態。 state = enStateStand; } ShadowMap().SetLightTarget(position); CVector3 lightPos; lightPos.Add(position, toLightPos); ShadowMap().SetLightPosition(lightPos); //コリジョン検出と解決を行う。 CollisionDetectAndResolve(nextPosition); } else if (state == enState_RideOnCar) { ShadowMap().SetLightTarget(g_car->GetPosition()); CVector3 lightPos; lightPos.Add(g_car->GetPosition(), toLightPos); ShadowMap().SetLightPosition(lightPos); if (g_car->GetMoveSpeed().Length() < 0.1f) { //車が停止状態。 if (Pad(0).IsPress(enButtonB)) { //降車。 g_camera->SetCar(NULL); g_car->SetRideOnFlag(false); skinModel.SetShadowReceiverFlag(true); skinModel.SetShadowCasterFlag(true); position = g_car->GetPosition(); state = enStateStand; } } } skinModel.Update(position, rotation, CVector3::One); //ポイントライトの位置を更新。 UpdatePointLightPosition(); //アニメーションコントロール。 AnimationControl(); lastFrameState = state; }
// Pre-processing after loading, returns true on success - just calculates bounding box here // Rejects mesh if no sub-meshes or any empty sub-meshes bool CMesh::PreProcess() { // Ensure at least one non-empty sub-mesh if (m_NumSubMeshes == 0 || m_SubMeshes[0].numVertices == 0) { return false; } // Set initial bounds from first vertex // Assuming first three floats are the vertex coord x,y & z. Would be better to support // a flexible data type system like DirectX vertex declarations (D3DVERTEXELEMENT9) TFloat32* pVertexCoord = reinterpret_cast<TFloat32*>(m_SubMeshes[0].vertices); m_MinBounds.x = m_MaxBounds.x = *pVertexCoord++; m_MinBounds.y = m_MaxBounds.y = *pVertexCoord++; m_MinBounds.z = m_MaxBounds.z = *pVertexCoord; m_BoundingRadius = m_MinBounds.Length(); // Go through all submeshes ... for (TUInt32 subMesh = 0; subMesh < m_NumSubMeshes; ++subMesh) { // Reject mesh if it contains empty sub-meshes if (m_SubMeshes[subMesh].numVertices == 0) { return false; } // Go through all vertices TUInt8* pVertex = m_SubMeshes[subMesh].vertices; for (TUInt32 vert = 0; vert < m_SubMeshes[subMesh].numVertices; ++vert) { // Get vertex coord as vector pVertexCoord = reinterpret_cast<TFloat32*>(pVertex); // Assume float x,y,z coord again CVector3 vertex; vertex.x = *pVertexCoord++; vertex.y = *pVertexCoord++; vertex.z = *pVertexCoord; // Compare vertex against current bounds, updating bounds where necessary if (vertex.x < m_MinBounds.x) { m_MinBounds.x = vertex.x; } if (vertex.x > m_MaxBounds.x) { m_MaxBounds.x = vertex.x; } ++pVertexCoord; if (vertex.y < m_MinBounds.y) { m_MinBounds.y = vertex.y; } if (vertex.y > m_MaxBounds.y) { m_MaxBounds.y = vertex.y; } ++pVertexCoord; if (vertex.z < m_MinBounds.z) { m_MinBounds.z = vertex.z; } if (vertex.z > m_MaxBounds.z) { m_MaxBounds.z = vertex.z; } TFloat32 length = vertex.Length(); if (length > m_BoundingRadius) { m_BoundingRadius = length; } // Step to next vertex (flexible vertex size) pVertex += m_SubMeshes[subMesh].vertexSize; } } return true; }
double CalculateColorIndex(bool isHybrid, double r, CVector4 z, double colorMin, const sExtendedAux &extendedAux, const sFractalColoring &fractalColoring, fractal::enumColoringFunction coloringFunction, const sFractal *defaultFractal) { double colorIndex = 0.0; // color by numbers if (fractalColoring.extraColorEnabledFalse) { double colorValue = 0.0; // initial color value colorValue = fractalColoring.initialColorValue; // colorValue initial condition components if (fractalColoring.initCondFalse) { double initColorValue = 0.0; CVector3 xyzC = CVector3(extendedAux.c.x, extendedAux.c.y, extendedAux.c.z); if (fractalColoring.icRadFalse) initColorValue = xyzC.Length() * fractalColoring.icRadWeight; if (fractalColoring.icXYZFalse) { if (fractalColoring.icFabsFalse) { xyzC = xyzC * fractalColoring.xyzC111; } else { xyzC = fabs(xyzC) * fractalColoring.xyzC111; } initColorValue += xyzC.x + xyzC.y + xyzC.z; } colorValue += initColorValue; } // orbit trap component if (fractalColoring.orbitTrapTrue) { // if (fractalColoring.tempLimitFalse) minimumR = min(100.0, minimumR); // TEMP for testing colorValue += colorMin * fractalColoring.orbitTrapWeight; } // auxiliary color components if (fractalColoring.auxColorFalse) { double auxColor = extendedAux.color; // if (fractalColoring.tempLimitFalse) auxColor = min(auxColor, 1000.0); // TEMP for testing colorValue += auxColor * fractalColoring.auxColorWeight // aux.color + extendedAux.colorHybrid // transf_hybrid_color inputs * fractalColoring.auxColorHybridWeight; } // radius components (historic) if (fractalColoring.radFalse) { double rad = r; if (fractalColoring.radDiv1e13False) rad /= 1e13; if (fractalColoring.radSquaredFalse) rad *= rad; colorValue += rad * fractalColoring.radWeight; } // radius / DE components (historic) if (fractalColoring.radDivDeFalse) { double distEst = extendedAux.DE; double radDE = r; if (fractalColoring.radDivDE1e13False) radDE /= 1e13; if (fractalColoring.radDivDeSquaredFalse) radDE *= radDE; radDE /= distEst; // if (fractalColoring.tempLimitFalse) radDE = min(radDE, 20.0); // TEMP for testing colorValue += radDE * fractalColoring.radDivDeWeight; } double addValue = 0.0; // XYZ bias (example of a basic input) double xyzValue = 0.0; if (fractalColoring.xyzBiasEnabledFalse) { CVector3 xyzAxis = CVector3(z.x, z.y, z.z); if (fractalColoring.xyzDiv1e13False) xyzAxis /= 1e13; if (fractalColoring.xyzFabsFalse) { xyzAxis = xyzAxis * fractalColoring.xyz000; } else { xyzAxis = fabs(xyzAxis) * fractalColoring.xyz000; } if (fractalColoring.xyzXSqrdFalse) xyzAxis.x *= xyzAxis.x; if (fractalColoring.xyzYSqrdFalse) xyzAxis.y *= xyzAxis.y; if (fractalColoring.xyzZSqrdFalse) xyzAxis.z *= xyzAxis.z; xyzValue = (xyzAxis.x + xyzAxis.y + xyzAxis.z) * (1.0 + (fractalColoring.xyzIterScale * extendedAux.i)); } addValue += xyzValue; // addValue accumulates outputs colorValue += addValue; // all extra inputs // colorValue iteration components if (fractalColoring.iterGroupFalse) { // Iter ADD, this allows the input to be influenced by iteration number if (fractalColoring.iterAddScaleTrue && extendedAux.i > fractalColoring.iStartValue) { int iUse = extendedAux.i - fractalColoring.iStartValue; colorValue += fractalColoring.iterAddScale * iUse; } // Iter SCALE, if (fractalColoring.iterScaleFalse && extendedAux.i >= fractalColoring.iStartValue) { int iUse = extendedAux.i - fractalColoring.iStartValue; colorValue *= (iUse * fractalColoring.iterScale) + 1.0; } } // final colorValue controls if (fractalColoring.globalPaletteFalse) { // // add curve function if (fractalColoring.addEnabledFalse) { if (colorValue > fractalColoring.addStartValue) { colorValue += (1.0 - 1.0 / (1.0 + (colorValue - fractalColoring.addStartValue) / fractalColoring.addSpread)) * fractalColoring.addMax; } } // parabolic function if (fractalColoring.parabEnabledFalse) { if (colorValue > fractalColoring.parabStartValue) { double parab = colorValue - fractalColoring.cosStartValue; parab = parab * parab * fractalColoring.parabScale; colorValue += parab; } } // trig function if (fractalColoring.cosEnabledFalse) { if (colorValue > fractalColoring.cosStartValue) { double trig = (0.5 - 0.5 * cos((colorValue - fractalColoring.cosStartValue) * M_PI / (fractalColoring.cosPeriod * 2.0))) * fractalColoring.cosAdd; colorValue += trig; } } // round function if (fractalColoring.roundEnabledFalse) { double roundScale = fractalColoring.roundScale; colorValue /= roundScale; colorValue = round(colorValue) * roundScale; } } // palette max min controls double minCV = fractalColoring.minColorValue; double maxCV = fractalColoring.maxColorValue; if (colorValue < minCV) colorValue = minCV; if (colorValue > maxCV) colorValue = maxCV; colorIndex = colorValue * 256.0; // convert to colorValue units } // HYBRID MODE coloring else if (isHybrid) { // orbit trap colorMin = min(100.0, colorMin); // aux.color (init cond = 1.0) double mboxColor = extendedAux.color; // double mboxColor = min(extendedAux.color, 1000.0); // rad/DE double r2 = min(r / fabs(extendedAux.DE), 20.0); // summation if (!fractalColoring.extraColorOptionsEnabledFalse) { colorIndex = (colorMin * 1000.0 + mboxColor * 100.0 + r2 * 5000.0); } else { colorIndex = (colorMin * 1000.0 * fractalColoring.hybridOrbitTrapScale1 + mboxColor * 100.0 * fractalColoring.hybridAuxColorScale1 + r2 * 5000.0 * fractalColoring.hybridRadDivDeScale1); } } // NORMAL MODE Coloring (single fractal) else { switch (coloringFunction) { case coloringFunctionABox: colorIndex = extendedAux.color * 100.0 // folds part + r * defaultFractal->mandelbox.color.factorR / 1e13 // r or abs z part + ((fractalColoring.coloringAlgorithm != fractalColoring_Standard) ? colorMin * 1000.0 : 0.0); // ABOX if fractalColoring_Standard) minimumR = 0.0 // ABOX r and minimumR values changed in V215 by bailout update // ABOX extendedAux.color is f(i), change bailout = change value break; case coloringFunctionIFS: colorIndex = colorMin * 1000.0; break; case coloringFunctionAmazingSurf: colorIndex = colorMin * 200.0; break; case coloringFunctionDonut: colorIndex = extendedAux.color * 2000.0 / extendedAux.i; break; case coloringFunctionDefault: colorIndex = colorMin * 5000.0; break; case coloringFunctionUndefined: colorIndex = 0.0; break; } } return colorIndex; }
void CEPuckLightSensor::Update() { /* Here we assume that the e-puck is rotated only wrt to the Z axis */ /* Erase readings */ for(size_t i = 0; i < m_tReadings.size(); ++i) { m_tReadings[i].Value = 0.0f; } /* Get e-puck position */ const CVector3& cEPuckPosition = GetEntity().GetEmbodiedEntity().GetPosition(); /* Get e-puck orientation */ CRadians cTmp1, cTmp2, cOrientationZ; GetEntity().GetEmbodiedEntity().GetOrientation().ToEulerAngles(cOrientationZ, cTmp1, cTmp2); /* Buffer for calculating the light--e-puck distance */ CVector3 cLightDistance; /* Buffer for the angle of the sensor wrt to the e-puck */ CRadians cLightAngle; /* Initialize the occlusion check ray start to the baseline of the e-puck */ CRay cOcclusionCheckRay; cOcclusionCheckRay.SetStart(cEPuckPosition); /* Buffer to store the intersection data */ CSpace::SEntityIntersectionItem<CEmbodiedEntity> sIntersectionData; /* Ignore the sensing ropuck when checking for occlusions */ TEmbodiedEntitySet tIgnoreEntities; tIgnoreEntities.insert(&GetEntity().GetEmbodiedEntity()); /* * 1. go through the list of light entities in the scene * 2. check if a light is occluded * 3. if it isn't, distribute the reading across the sensors * NOTE: the readings are additive * 4. go through the sensors and clamp their values */ try{ CSpace::TAnyEntityMap& tEntityMap = m_cSpace.GetEntitiesByType("light_entity"); for(CSpace::TAnyEntityMap::iterator it = tEntityMap.begin(); it != tEntityMap.end(); ++it) { /* Get a reference to the light */ CLightEntity& cLight = *(any_cast<CLightEntity*>(it->second)); /* Consider the light only if it has non zero intensity */ if(cLight.GetIntensity() > 0.0f) { /* Get the light position */ const CVector3& cLightPosition = cLight.GetPosition(); /* Set the ray end */ cOcclusionCheckRay.SetEnd(cLightPosition); /* Check occlusion between the e-puck and the light */ if(! m_cSpace.GetClosestEmbodiedEntityIntersectedByRay(sIntersectionData, cOcclusionCheckRay, tIgnoreEntities)) { /* The light is not occluded */ if(m_bShowRays) GetEntity().GetControllableEntity().AddCheckedRay(false, cOcclusionCheckRay); /* Get the distance between the light and the e-puck */ cOcclusionCheckRay.ToVector(cLightDistance); /* Linearly scale the distance with the light intensity The greater the intensity, the smaller the distance */ cLightDistance /= cLight.GetIntensity(); /* Get the angle wrt to e-puck rotation */ cLightAngle = cLightDistance.GetZAngle(); cLightAngle -= cOrientationZ; /* Transform it into counter-clockwise rotation */ cLightAngle.Negate().UnsignedNormalize(); /* Find reading corresponding to the sensor */ SInt16 nMin = 0; for(SInt16 i = 1; i < NUM_READINGS; ++i){ if((cLightAngle - m_tReadings[i].Angle).GetAbsoluteValue() < (cLightAngle - m_tReadings[nMin].Angle).GetAbsoluteValue()) nMin = i; } /* Set the actual readings */ Real fReading = cLightDistance.Length(); m_tReadings[Modulo((SInt16)(nMin-1), NUM_READINGS)].Value += ComputeReading(fReading * Cos(cLightAngle - m_tReadings[Modulo(nMin-1, NUM_READINGS)].Angle)); m_tReadings[ nMin ].Value += ComputeReading(fReading); m_tReadings[Modulo((SInt16)(nMin+1), NUM_READINGS)].Value += ComputeReading(fReading * Cos(cLightAngle - m_tReadings[Modulo(nMin+1, NUM_READINGS)].Angle)); } else { /* The ray is occluded */ if(m_bShowRays) { GetEntity().GetControllableEntity().AddCheckedRay(true, cOcclusionCheckRay); GetEntity().GetControllableEntity().AddIntersectionPoint(cOcclusionCheckRay, sIntersectionData.TOnRay); } } } } } catch(argos::CARGoSException& e){ } /* Now go through the sensors, add noise and clamp their values if above 1024 or under 1024 */ for(size_t i = 0; i < m_tReadings.size(); ++i) { if(m_fNoiseLevel>0.0f) AddNoise(i); if(m_tReadings[i].Value > 1024.0f) m_tReadings[i].Value = 1024.0f; if(m_tReadings[i].Value < 0.0f) m_tReadings[i].Value = 0.0f; } }
cRenderWorker::sRayRecursionOut cRenderWorker::RayRecursion(sRayRecursionIn in, sRayRecursionInOut &inOut) { sRayMarchingOut rayMarchingOut; *inOut.rayMarchingInOut.buffCount = 0; //trace the light in given direction CVector3 point = RayMarching(in.rayMarchingIn, &inOut.rayMarchingInOut, &rayMarchingOut); sRGBAfloat resultShader = in.resultShader; sRGBAfloat objectColour = in.objectColour; //here will be called branch for RayRecursion(); sRGBAfloat objectShader; objectShader.A = 0.0; sRGBAfloat backgroundShader; sRGBAfloat volumetricShader; sRGBAfloat specular; //prepare data for shaders CVector3 lightVector = shadowVector; sShaderInputData shaderInputData; shaderInputData.distThresh = rayMarchingOut.distThresh; shaderInputData.delta = CalcDelta(point); shaderInputData.lightVect = lightVector; shaderInputData.point = point; shaderInputData.viewVector = in.rayMarchingIn.direction; shaderInputData.lastDist = rayMarchingOut.lastDist; shaderInputData.depth = rayMarchingOut.depth; shaderInputData.stepCount = *inOut.rayMarchingInOut.buffCount; shaderInputData.stepBuff = inOut.rayMarchingInOut.stepBuff; shaderInputData.invertMode = in.calcInside; shaderInputData.objectId = rayMarchingOut.objectId; cObjectData objectData = data->objectData[shaderInputData.objectId]; shaderInputData.material = &data->materials[objectData.materialId]; sRGBAfloat reflectShader = in.resultShader; double reflect = shaderInputData.material->reflectance; sRGBAfloat transparentShader = in.resultShader; double transparent = shaderInputData.material->transparencyOfSurface; sRGBfloat transparentColor = sRGBfloat(shaderInputData.material->transparencyInteriorColor.R / 65536.0, shaderInputData.material->transparencyInteriorColor.G / 65536.0, shaderInputData.material->transparencyInteriorColor.B / 65536.0); resultShader.R = transparentColor.R; resultShader.G = transparentColor.G; resultShader.B = transparentColor.B; CVector3 vn; //if found any object if (rayMarchingOut.found) { //calculate normal vector vn = CalculateNormals(shaderInputData); shaderInputData.normal = vn; if(shaderInputData.material->diffusionTexture.IsLoaded()) shaderInputData.texDiffuse = TextureShader(shaderInputData, cMaterial::texDiffuse, shaderInputData.material); else shaderInputData.texDiffuse = sRGBfloat(1.0, 1.0, 1.0); if(shaderInputData.material->normalMapTexture.IsLoaded()) { vn = NormalMapShader(shaderInputData); } //prepare refraction values double n1, n2; if (in.calcInside) //if trance is inside the object { n1 = shaderInputData.material ->transparencyIndexOfRefraction; //reverse refractive indices n2 = 1.0; } else { n1 = 1.0; n2 = shaderInputData.material ->transparencyIndexOfRefraction; ; } if (inOut.rayIndex < reflectionsMax) { //calculate refraction (transparency) if (transparent > 0.0) { sRayRecursionIn recursionIn; sRayMarchingIn rayMarchingIn; sRayMarchingInOut rayMarchingInOut; //calculate direction of refracted light CVector3 newDirection = RefractVector(vn, in.rayMarchingIn.direction, n1, n2); //move starting point a little CVector3 newPoint = point + in.rayMarchingIn.direction * shaderInputData.distThresh * 1.0; //if is total internal reflection the use reflection instead of refraction bool internalReflection = false; if (newDirection.Length() == 0.0) { newDirection = ReflectionVector(vn, in.rayMarchingIn.direction); newPoint = point + in.rayMarchingIn.direction * shaderInputData.distThresh * 1.0; internalReflection = true; } //preparation for new recursion rayMarchingIn.binaryEnable = true; rayMarchingIn.direction = newDirection; rayMarchingIn.maxScan = params->viewDistanceMax; rayMarchingIn.minScan = 0.0; rayMarchingIn.start = newPoint; rayMarchingIn.invertMode = !in.calcInside || internalReflection; recursionIn.rayMarchingIn = rayMarchingIn; recursionIn.calcInside = !in.calcInside || internalReflection; recursionIn.resultShader = resultShader; recursionIn.objectColour = objectColour; //setup buffers for ray data inOut.rayIndex++; //increase recursion index rayMarchingInOut.buffCount = &rayBuffer[inOut.rayIndex].buffCount; rayMarchingInOut.stepBuff = rayBuffer[inOut.rayIndex].stepBuff; inOut.rayMarchingInOut = rayMarchingInOut; //recursion for refraction sRayRecursionOut recursionOutTransparent = RayRecursion(recursionIn, inOut); transparentShader = recursionOutTransparent.resultShader; } //calculate reflection if (reflect > 0.0) { sRayRecursionIn recursionIn; sRayMarchingIn rayMarchingIn; sRayMarchingInOut rayMarchingInOut; //calculate new direction of reflection CVector3 newDirection = ReflectionVector(vn, in.rayMarchingIn.direction); CVector3 newPoint = point + newDirection * shaderInputData.distThresh; //prepare for new recursion rayMarchingIn.binaryEnable = true; rayMarchingIn.direction = newDirection; rayMarchingIn.maxScan = params->viewDistanceMax; rayMarchingIn.minScan = 0.0; rayMarchingIn.start = newPoint; rayMarchingIn.invertMode = false; recursionIn.rayMarchingIn = rayMarchingIn; recursionIn.calcInside = false; recursionIn.resultShader = resultShader; recursionIn.objectColour = objectColour; //setup buffers for ray data inOut.rayIndex++; //increase recursion index rayMarchingInOut.buffCount = &rayBuffer[inOut.rayIndex].buffCount; rayMarchingInOut.stepBuff = rayBuffer[inOut.rayIndex].stepBuff; inOut.rayMarchingInOut = rayMarchingInOut; //recursion for reflection sRayRecursionOut recursionOutReflect = RayRecursion(recursionIn, inOut); reflectShader = recursionOutReflect.resultShader; } if (transparent > 0.0) inOut.rayIndex--; //decrease recursion index if (reflect > 0.0) inOut.rayIndex--; //decrease recursion index } shaderInputData.normal = vn; //calculate effects for object surface objectShader = ObjectShader(shaderInputData, &objectColour, &specular); //calculate reflectance according to Fresnel equations double reflectance = 1.0; double reflectanceN = 1.0; if (shaderInputData.material->fresnelReflectance) { reflectance = Reflectance(vn, in.rayMarchingIn.direction, n1, n2); if (reflectance < 0.0) reflectance = 0.0; if (reflectance > 1.0) reflectance = 1.0; reflectanceN = 1.0 - reflectance; } //combine all results resultShader.R = (objectShader.R + specular.R); resultShader.G = (objectShader.G + specular.G); resultShader.B = (objectShader.B + specular.B); if (reflectionsMax > 0) { sRGBfloat reflectDiffused; double diffIntes = shaderInputData.material->diffussionTextureIntensity; double diffIntesN = 1.0 - diffIntes; reflectDiffused.R = reflect * shaderInputData.texDiffuse.R * diffIntes + reflect * diffIntesN; reflectDiffused.G = reflect * shaderInputData.texDiffuse.G * diffIntes + reflect * diffIntesN; reflectDiffused.B = reflect * shaderInputData.texDiffuse.B * diffIntes + reflect * diffIntesN; resultShader.R = transparentShader.R * transparent * reflectanceN + (1.0 - transparent * reflectanceN) * resultShader.R; resultShader.G = transparentShader.G * transparent * reflectanceN + (1.0 - transparent * reflectanceN) * resultShader.G; resultShader.B = transparentShader.B * transparent * reflectanceN + (1.0 - transparent * reflectanceN) * resultShader.B; resultShader.R = reflectShader.R * reflectDiffused.R * reflectance + (1.0 - reflectDiffused.R * reflectance) * resultShader.R; resultShader.G = reflectShader.G * reflectDiffused.G * reflectance + (1.0 - reflectDiffused.G * reflectance) * resultShader.G; resultShader.B = reflectShader.B * reflectDiffused.B * reflectance + (1.0 - reflectDiffused.B * reflectance) * resultShader.B; } if(resultShader.R < 0.0) resultShader.R = 0.0; if(resultShader.G < 0.0) resultShader.G = 0.0; if(resultShader.B < 0.0) resultShader.B = 0.0; } else //if object not found then calculate background { backgroundShader = BackgroundShader(shaderInputData); resultShader = backgroundShader; shaderInputData.depth = 1e20; vn = mRot.RotateVector(CVector3(0.0, -1.0, 0.0)); } sRGBAfloat opacityOut; if (in.calcInside) //if the object interior is traced, then the absorption of light has to be calculated { for (int index = shaderInputData.stepCount - 1; index > 0; index--) { double step = shaderInputData.stepBuff[index].step; //CVector3 point = shaderInputData.stepBuff[index].point; //shaderInputData.point = point; //sRGBAfloat color = SurfaceColour(shaderInputData); //transparentColor.R = color.R; //transparentColor.G = color.G; //transparentColor.B = color.B; double opacity = -log(shaderInputData.material ->transparencyOfInterior) * step; if (opacity > 1.0) opacity = 1.0; resultShader.R = opacity * transparentColor.R + (1.0 - opacity) * resultShader.R; resultShader.G = opacity * transparentColor.G + (1.0 - opacity) * resultShader.G; resultShader.B = opacity * transparentColor.B + (1.0 - opacity) * resultShader.B; } } else //if now is outside the object, then calculate all volumetric effects like fog, glow... { volumetricShader = VolumetricShader(shaderInputData, resultShader, &opacityOut); resultShader = volumetricShader; } //prepare final result sRayRecursionOut out; out.point = point; out.rayMarchingOut = rayMarchingOut; out.objectColour = objectColour; out.resultShader = resultShader; out.found = (shaderInputData.depth == 1e20) ? false : true; out.fogOpacity = opacityOut.R; out.normal = vn; return out; }
void CFootBotLightRotZOnlySensor::Update() { /* Erase readings */ for(size_t i = 0; i < m_tReadings.size(); ++i) { m_tReadings[i].Value = 0.0f; } /* Get foot-bot orientation */ CRadians cTmp1, cTmp2, cOrientationZ; m_pcEmbodiedEntity->GetOriginAnchor().Orientation.ToEulerAngles(cOrientationZ, cTmp1, cTmp2); /* Ray used for scanning the environment for obstacles */ CRay3 cOcclusionCheckRay; cOcclusionCheckRay.SetStart(m_pcEmbodiedEntity->GetOriginAnchor().Position); CVector3 cRobotToLight; /* Buffer for the angle of the light wrt to the foot-bot */ CRadians cAngleLightWrtFootbot; /* Buffers to contain data about the intersection */ SEmbodiedEntityIntersectionItem sIntersection; /* List of light entities */ CSpace::TMapPerTypePerId::iterator itLights = m_cSpace.GetEntityMapPerTypePerId().find("light"); if (itLights != m_cSpace.GetEntityMapPerTypePerId().end()) { CSpace::TMapPerType& mapLights = itLights->second; /* * 1. go through the list of light entities in the scene * 2. check if a light is occluded * 3. if it isn't, distribute the reading across the sensors * NOTE: the readings are additive * 4. go through the sensors and clamp their values */ for(CSpace::TMapPerType::iterator it = mapLights.begin(); it != mapLights.end(); ++it) { /* Get a reference to the light */ CLightEntity& cLight = *(any_cast<CLightEntity*>(it->second)); /* Consider the light only if it has non zero intensity */ if(cLight.GetIntensity() > 0.0f) { /* Set the ray end */ cOcclusionCheckRay.SetEnd(cLight.GetPosition()); /* Check occlusion between the foot-bot and the light */ if(! GetClosestEmbodiedEntityIntersectedByRay(sIntersection, cOcclusionCheckRay, *m_pcEmbodiedEntity)) { /* The light is not occluded */ if(m_bShowRays) { m_pcControllableEntity->AddCheckedRay(false, cOcclusionCheckRay); } /* Get the distance between the light and the foot-bot */ cOcclusionCheckRay.ToVector(cRobotToLight); /* * Linearly scale the distance with the light intensity * The greater the intensity, the smaller the distance */ cRobotToLight /= cLight.GetIntensity(); /* Get the angle wrt to foot-bot rotation */ cAngleLightWrtFootbot = cRobotToLight.GetZAngle(); cAngleLightWrtFootbot -= cOrientationZ; /* * Find closest sensor index to point at which ray hits footbot body * Rotate whole body by half a sensor spacing (corresponding to placement of first sensor) * Division says how many sensor spacings there are between first sensor and point at which ray hits footbot body * Increase magnitude of result of division to ensure correct rounding */ Real fIdx = (cAngleLightWrtFootbot - SENSOR_HALF_SPACING) / SENSOR_SPACING; SInt32 nReadingIdx = (fIdx > 0) ? fIdx + 0.5f : fIdx - 0.5f; /* Set the actual readings */ Real fReading = cRobotToLight.Length(); /* * Take 6 readings before closest sensor and 6 readings after - thus we * process sensors that are with 180 degrees of intersection of light * ray with robot body */ for(SInt32 nIndexOffset = -6; nIndexOffset < 7; ++nIndexOffset) { UInt32 unIdx = Modulo(nReadingIdx + nIndexOffset, 24); CRadians cAngularDistanceFromOptimalLightReceptionPoint = Abs((cAngleLightWrtFootbot - m_tReadings[unIdx].Angle).SignedNormalize()); /* * ComputeReading gives value as if sensor was perfectly in line with * light ray. We then linearly decrease actual reading from 1 (dist * 0) to 0 (dist PI/2) */ m_tReadings[unIdx].Value += ComputeReading(fReading) * ScaleReading(cAngularDistanceFromOptimalLightReceptionPoint); } } else { /* The ray is occluded */ if(m_bShowRays) { m_pcControllableEntity->AddCheckedRay(true, cOcclusionCheckRay); m_pcControllableEntity->AddIntersectionPoint(cOcclusionCheckRay, sIntersection.TOnRay); } } } } /* Apply noise to the sensors */ if(m_bAddNoise) { for(size_t i = 0; i < 24; ++i) { m_tReadings[i].Value += m_pcRNG->Uniform(m_cNoiseRange); } } /* Trunc the reading between 0 and 1 */ for(size_t i = 0; i < 24; ++i) { SENSOR_RANGE.TruncValue(m_tReadings[i].Value); } } else { /* There are no lights in the environment */ if(m_bAddNoise) { /* Go through the sensors */ for(UInt32 i = 0; i < m_tReadings.size(); ++i) { /* Apply noise to the sensor */ m_tReadings[i].Value += m_pcRNG->Uniform(m_cNoiseRange); /* Trunc the reading between 0 and 1 */ SENSOR_RANGE.TruncValue(m_tReadings[i].Value); } } } }
void Compute(const cNineFractals &fractals, const sFractalIn &in, sFractalOut *out) { //QTextStream outStream(stdout); //clock_t tim; //tim = rdtsc(); //repeat, move and rotate CVector3 point2 = in.point.mod(in.common.repeat) - in.common.fractalPosition; point2 = in.common.mRotFractalRotation.RotateVector(point2); CVector3 z = point2; double r = z.Length(); CVector3 c = z; double minimumR = 100.0; double w = 0.0; double orbitTrapTotal = 0.0; enumFractalFormula formula = fractal::none; out->maxiter = true; int fractalIndex = 0; if (in.forcedFormulaIndex >= 0) fractalIndex = in.forcedFormulaIndex; const cFractal *defaultFractal = fractals.GetFractal(fractalIndex); sExtendedAux extendedAux[NUMBER_OF_FRACTALS]; int maxFractal = (in.forcedFormulaIndex >= 0) ? in.forcedFormulaIndex : fractals.GetMaxFractalIndex(); int minFractal = (in.forcedFormulaIndex >= 0) ? in.forcedFormulaIndex : 0; for (int i = minFractal; i <= maxFractal; i++) { extendedAux[i].r_dz = 1.0; extendedAux[i].r = r; extendedAux[i].color = 1.0; extendedAux[i].actualScale = fractals.GetFractal(i)->mandelbox.scale; extendedAux[i].DE = 1.0; extendedAux[i].c = c; extendedAux[i].cw = 0; extendedAux[i].newR = 1e+20; extendedAux[i].axisBias = 1e+20; extendedAux[i].orbitTraps = 1e+20; extendedAux[i].transformSampling = 1e+20; } //main iteration loop int i; int sequence = 0; int lastSequnce = 0; for (i = 0; i < in.maxN; i++) { //hybrid fractal sequence if (in.forcedFormulaIndex >= 0) { sequence = in.forcedFormulaIndex; } else { sequence = fractals.GetSequence(i); } //for optimized DE calculation if(fractals.UseOptimizedDE()) { extendedAux[sequence] = extendedAux[lastSequnce]; lastSequnce = sequence; } //foldings if (in.common.foldings.boxEnable) { BoxFolding(z, &in.common.foldings, extendedAux[sequence]); r = z.Length(); } if (in.common.foldings.sphericalEnable) { extendedAux[sequence].r = r; SphericalFolding(z, &in.common.foldings, extendedAux[sequence]); r = z.Length(); } const cFractal *fractal = fractals.GetFractal(sequence); formula = fractal->formula; //temporary vector for weight function CVector3 tempZ = z; extendedAux[sequence].r = r; if (!fractals.IsHybrid() || fractals.GetWeight(sequence) > 0.0) { //calls for fractal formulas switch (formula) { case mandelbulb: { MandelbulbIteration(z, fractal, extendedAux[sequence]); break; } case mandelbulb2: { Mandelbulb2Iteration(z, extendedAux[sequence]); break; } case mandelbulb3: { Mandelbulb3Iteration(z, extendedAux[sequence]); break; } case mandelbulb4: { Mandelbulb4Iteration(z, fractal, extendedAux[sequence]); break; } case fast_mandelbulb_power2: { MandelbulbPower2Iteration(z, extendedAux[sequence]); break; } case xenodreambuie: { XenodreambuieIteration(z, fractal, extendedAux[sequence]); break; } case mandelbox: { MandelboxIteration(z, fractal, extendedAux[sequence]); break; } case smoothMandelbox: { SmoothMandelboxIteration(z, fractal, extendedAux[sequence]); break; } case boxFoldBulbPow2: { BoxFoldBulbPow2Iteration(z, fractal); break; } case menger_sponge: { MengerSpongeIteration(z, extendedAux[sequence]); break; } case kaleidoscopicIFS: { KaleidoscopicIFSIteration(z, fractal, extendedAux[sequence]); break; } case aexion: { AexionIteration(z, w, i, fractal, extendedAux[sequence]); break; } case hypercomplex: { HypercomplexIteration(z, w, extendedAux[sequence]); break; } case quaternion: { QuaternionIteration(z, w, extendedAux[sequence]); break; } case benesi: { BenesiIteration(z, c, extendedAux[sequence]); break; } case bristorbrot: { BristorbrotIteration(z, extendedAux[sequence]); break; } case ides: { IdesIteration(z, fractal); break; } case ides2: { Ides2Iteration(z, fractal); break; } case buffalo: { BuffaloIteration(z, fractal, extendedAux[sequence]); break; } case quickdudley: { QuickDudleyIteration(z); break; } case quickDudleyMod: { QuickDudleyModIteration(z, fractal); break; } case lkmitch: { LkmitchIteration(z); break; } case makin3d2: { Makin3D2Iteration(z); break; } case msltoeDonut: { MsltoeDonutIteration(z, fractal, extendedAux[sequence]); break; } case msltoesym2Mod: { MsltoeSym2ModIteration(z, c, fractal, extendedAux[sequence]); break; } case msltoesym3Mod: { MsltoeSym3ModIteration(z, c, i, fractal, extendedAux[sequence]); break; } case msltoesym3Mod2: { MsltoeSym3Mod2Iteration(z, c, fractal, extendedAux[sequence]); break; } case msltoesym3Mod3: { MsltoeSym3Mod3Iteration(z, c, i, fractal, extendedAux[sequence]); break; } case msltoesym4Mod: { MsltoeSym4ModIteration(z, c, fractal, extendedAux[sequence]); break; } case generalizedFoldBox: { GeneralizedFoldBoxIteration(z, fractal, extendedAux[sequence]); break; } case mandelbulb5: { Mandelbulb5Iteration(z, c, minimumR, i, fractal, extendedAux[sequence]); break; } case mandelbox103: { Mandelbox103Iteration(z, c, minimumR, i, fractal, extendedAux[sequence]); break; } case quaternion104: { CVector4 z4D(z, w); Quaternion104Iteration(z4D, CVector4(c, 0.0), i, fractal, extendedAux[sequence]); z = z4D.GetXYZ(); w = z4D.w; break; } case mengerSponge105: { MengerSponge105Iteration(z, c, minimumR, i, fractal, extendedAux[sequence]); break; } case mandelbulb6Beta: { Mandelbulb6BetaIteration(z, c, minimumR, i, fractal, extendedAux[sequence]); break; } case benesiTransforms: { BenesiTransformsIteration(z, c, minimumR, i, fractal, extendedAux[sequence]); break; } case aboxMod1: { AboxMod1Iteration(z, fractal, extendedAux[sequence]); break; } case aboxMod2: { AboxMod2Iteration(z, fractal, extendedAux[sequence]); break; } case aboxModKali: { AboxModKaliIteration(z, fractal, extendedAux[sequence]); break; } case aboxVSIcen1: { AboxVSIcen1Iteration(z, c, fractal, extendedAux[sequence]); break; } case aexionOctopusMod: { AexionOctopusModIteration(z, c, fractal); break; } case amazingSurf: { AmazingSurfIteration(z, fractal, extendedAux[sequence]); break; } case amazingSurfMod1: { AmazingSurfMod1Iteration(z, fractal, extendedAux[sequence]); break; } case benesiPineTree: { BenesiPineTreeIteration(z, c, fractal, extendedAux[sequence]); break; } case benesiT1PineTree: { BenesiT1PineTreeIteration(z, c, i, fractal, extendedAux[sequence]); break; } case eiffieMsltoe: { EiffieMsltoeIteration(z, c, fractal, extendedAux[sequence]); break; } case foldBoxMod1: { FoldBoxMod1Iteration(z, i, fractal, extendedAux[sequence]); break; } case iqBulb: { IQbulbIteration(z, fractal, extendedAux[sequence]); break; } case kalisets1: { Kalisets1Iteration(z, c, fractal, extendedAux[sequence]); break; } case mandelbulbMulti: { MandelbulbMultiIteration(z, fractal, extendedAux[sequence]); break; } case mandelbulbVaryPowerV1: { MandelbulbVaryPowerV1Iteration(z, i, fractal, extendedAux[sequence]); break; } case mengerMod1: { MengerMod1Iteration(z, i, fractal, extendedAux[sequence]); break; } case riemannSphereMsltoe: { RiemannSphereMsltoeIteration(z, fractal); break; } case riemannSphereMsltoeV1: { RiemannSphereMsltoeV1Iteration(z, fractal); break; } case quaternion3D: { Quaternion3DIteration(z, fractal, extendedAux[sequence]); break; } //transforms ------------------------------------------------------------------------------------------ case transfAdditionConstant: { TransformAdditionConstantIteration(z, fractal); break; } case transfAdditionConstantVaryV1: { TransformAdditionConstantVaryV1Iteration(z, i, fractal); break; } case transfAddCpixel: { TransformAddCpixelIteration(z, c, fractal); break; } case transfAddCpixelAxisSwap: { TransformAddCpixelAxisSwapIteration(z, c, fractal); break; } case transfAddCpixelCxCyAxisSwap: { TransformAddCpixelCxCyAxisSwapIteration(z, c, fractal); break; } case transfAddCpixelPosNeg: { TransformAddCpixelPosNegIteration(z, c, fractal); break; } case transfAddCpixelVaryV1: { TransformAddCpixelVaryV1Iteration(z, c, i, fractal); break; } case transfBenesiT1: { TransformBenesiT1Iteration(z, fractal, extendedAux[sequence]); break; } case transfBenesiT1Mod: { TransformBenesiT1ModIteration(z, fractal, extendedAux[sequence]); break; } case transfBenesiT2: { TransformBenesiT2Iteration(z, fractal, extendedAux[sequence]); break; } case transfBenesiT3: { TransformBenesiT3Iteration(z, fractal); break; } case transfBenesiT4: { TransformBenesiT4Iteration(z, fractal); break; } case transfBenesiT5b: { TransformBenesiT5bIteration(z, fractal); break; } case transfBenesiMagForward: { TransformBenesiMagForwardIteration(z); break; } case transfBenesiMagBackward: { TransformBenesiMagBackwardIteration(z); break; } case transfBenesiCubeSphere: { TransformBenesiCubeSphereIteration(z); break; } case transfBenesiSphereCube: { TransformBenesiSphereCubeIteration(z); break; } case transfBoxFold: { TransformBoxFoldIteration(z, fractal, extendedAux[sequence]); break; } case transfBoxFoldXYZ: { TransformBoxFoldXYZIteration(z, fractal, extendedAux[sequence]); break; } case transfBoxOffset: { TransformBoxOffsetIteration(z, fractal, extendedAux[sequence]); break; } case transfFabsAddConstant: { TransformFabsAddConstantIteration(z, fractal); break; } case transfFabsAddConstantV2: { TransformFabsAddConstantV2Iteration(z, fractal); break; } case transfFabsAddMulti: { TransformFabsAddMultiIteration(z, fractal); break; } case transfIterationWeight: { TransformIterationWeightIteration(z, i, fractal); break; } case transfLinCombineCxyz: { TransformLinCombineCxyz(c, fractal); break; } case transfMultipleAngle: { TransformMultipleAngle(z, fractal, extendedAux[sequence]); break; } case transfNegFabsAddConstant: { TransformNegFabsAddConstantIteration(z, fractal); break; } case transfRotation: { TransformRotationIteration(z, fractal); break; } case transfRotationVaryV1: { TransformRotationVaryV1Iteration(z, i, fractal); break; } case transfScale: { TransformScaleIteration(z, fractal, extendedAux[sequence]); break; } case transfScaleVaryV1: { TransformScaleVaryV1Iteration(z, i, fractal, extendedAux[sequence]); break; } case transfScale3D: { TransformScale3DIteration(z, fractal, extendedAux[sequence]); break; } case platonicSolid: { TransformPlatonicSolidIteration(z, fractal); break; } case transfRPower: { TransformPowerR(z, fractal, extendedAux[sequence]); break; } case transfSphereInvC: { TransformSphereInvCIteration(z, c, fractal); break; } case transfSphericalOffset: { TransformSphericalOffsetIteration(z, fractal, extendedAux[sequence]); break; } case transfSphericalFold: { TransformSphericalFoldIteration(z, fractal, extendedAux[sequence]); break; } case transfSphericalPwrFold: { TransformSphericalPwrFoldIteration(z, fractal, extendedAux[sequence]); break; } case transfZvectorAxisSwap: { TransformZvectorAxisSwapIteration(z, fractal ); break; } // 4D --------------------------------------------------------------------------- case quaternion4D: { CVector4 z4D(z, w); Quaternion4DIteration(z4D, i, fractal); z = z4D.GetXYZ(); w = z4D.w; break; } case mandelboxVaryScale4D: { CVector4 z4D(z, w); MandelboxVaryScale4DIteration(z4D, i, fractal, extendedAux[sequence]); z = z4D.GetXYZ(); w = z4D.w; break; } case transfAdditionConstant4D: { CVector4 z4D(z, w); TransformAdditionConstant4DIteration(z4D, fractal); z = z4D.GetXYZ(); w = z4D.w; break; } case transfBoxFold4D: { CVector4 z4D(z, w); TransformBoxFold4DIteration(z4D, fractal, extendedAux[sequence]); z = z4D.GetXYZ(); w = z4D.w; break; } case transfFabsAddConstant4D: { CVector4 z4D(z, w); TransformFabsAddConstant4DIteration(z4D, fractal); z = z4D.GetXYZ(); w = z4D.w; break; } case transfFabsAddConstantV24D: { CVector4 z4D(z, w); TransformFabsAddConstantV24DIteration(z4D, fractal); z = z4D.GetXYZ(); w = z4D.w; break; } case transfIterationWeight4D: { CVector4 z4D(z, w); TransformIterationWeight4DIteration(z4D, i, fractal); z = z4D.GetXYZ(); w = z4D.w; break; } case transfScale4D: { CVector4 z4D(z, w); TransformScale4DIteration(z4D, fractal, extendedAux[sequence]); z = z4D.GetXYZ(); w = z4D.w; break; } case transfSphericalFold4D: { CVector4 z4D(z, w); TransformSphericalFold4DIteration(z4D, fractal, extendedAux[sequence]); z = z4D.GetXYZ(); w = z4D.w; break; } default: z = CVector3(0.0, 0.0, 0.0); break; } } //addition of constant if (fractals.IsAddCConstant(sequence)) { switch (formula) { case aboxMod1: case amazingSurf: //case amazingSurfMod1: { if (fractals.IsJuliaEnabled(sequence)) { CVector3 juliaC = fractals.GetJuliaConstant(sequence) * fractals.GetConstantMultiplier(sequence); z += CVector3(juliaC.y, juliaC.x, juliaC.z); } else { z += CVector3(c.y, c.x, c.z) * fractals.GetConstantMultiplier(sequence); } break; } default: { if (fractals.IsJuliaEnabled(sequence)) { z += fractals.GetJuliaConstant(sequence) * fractals.GetConstantMultiplier(sequence); } else { z += c * fractals.GetConstantMultiplier(sequence); } break; } } } if (fractals.IsHybrid()) { z = SmoothCVector(tempZ, z, fractals.GetWeight(sequence)); } //r calculation r = sqrt(z.x * z.x + z.y * z.y + z.z * z.z + w * w); //escape conditions if (fractals.IsCheckForBailout(sequence)) { if (Mode == calcModeNormal) { if (r > fractals.GetBailout(sequence)) { out->maxiter = false; break; } } else if (Mode == calcModeDeltaDE1) { if (r > fractals.GetBailout(sequence)) { out->maxiter = false; break; } } else if (Mode == calcModeDeltaDE2) { if (i == in.maxN) break; } else if (Mode == calcModeColouring) { double len = 0.0; switch (in.common.fractalColoringAlgorithm) { case fractalColoringStandard: { len = r; break; } case fractalColoringZDotPoint: { len = fabs(z.Dot(in.point)); break; } case fractalColoringSphere: { len = fabs((z - in.point).Length() - in.common.fractalColoringSphereRadius); break; } case fractalColoringCross: { len = dMin(fabs(z.x), fabs(z.y), fabs(z.z)); break; } case fractalColoringLine: { len = fabs(z.Dot(in.common.fractalColoringLineDirection)); break; } } if (fractal->formula != mandelbox || in.common.fractalColoringAlgorithm != fractalColoringStandard) { if (len < minimumR) minimumR = len; } if (r > 1e15) break; } else if (Mode == calcModeOrbitTrap) { CVector3 delta = z - in.common.fakeLightsOrbitTrap; double distance = delta.Length(); if (i >= in.common.fakeLightsMinIter && i <= in.common.fakeLightsMaxIter) orbitTrapTotal += (1.0f / (distance * distance)); if (distance > 1000) { out->orbitTrapR = orbitTrapTotal; break; } } } } //final calculations if (Mode == calcModeNormal) { if (fractals.IsHybrid()) { if(extendedAux[sequence].r_dz > 0) { if (fractals.GetDEFunctionType(0) == fractal::linearDEFunction) { out->distance = r / fabs(extendedAux[sequence].DE); } else if (fractals.GetDEFunctionType(0) == fractal::logarithmicDEFunction) { out->distance = 0.5 * r * log(r) / extendedAux[sequence].r_dz; } } else { out->distance = r; } } else { switch (formula) { case benesi: case benesiPineTree: case benesiT1PineTree: case bristorbrot: case buffalo: case eiffieMsltoe: case fast_mandelbulb_power2: case hypercomplex: case iqBulb: case mandelbulb: case mandelbulb2: case mandelbulb3: case mandelbulb4: case mandelbulb5: case mandelbulb6Beta: case mandelbulbMulti: case mandelbulbVaryPowerV1: case msltoesym2Mod: case msltoesym3Mod: case msltoesym3Mod2: case msltoesym3Mod3: case msltoesym4Mod: case quaternion: case quaternion3D: case xenodreambuie: { if(extendedAux[sequence].r_dz > 0) out->distance = 0.5 * r * log(r) / extendedAux[sequence].r_dz; else out->distance = r; break; } case mandelbox: case smoothMandelbox: case mandelboxVaryScale4D: case generalizedFoldBox: case mandelbox103: case mengerSponge105: case foldBoxMod1: case aboxModKali: case mengerMod1: case aboxMod1: case aboxMod2: case amazingSurf: case amazingSurfMod1: case kalisets1: case aboxVSIcen1: { if(extendedAux[sequence].r_dz > 0) out->distance = r / fabs(extendedAux[sequence].DE); else out->distance = r; break; } case kaleidoscopicIFS: case menger_sponge: { if(extendedAux[sequence].r_dz > 0) out->distance = (r - 2.0) / (extendedAux[sequence].DE); else out->distance = r; break; } default: out->distance = -1.0; break; } } } //color calculation else if (Mode == calcModeColouring) { if (fractals.IsHybrid()) { if (minimumR > 100) minimumR = 100; double mboxColor = 0.0; double mboxDE = 1.0; for (int h = minFractal; h <= maxFractal; h++) { mboxColor += extendedAux[h].color; mboxDE *= extendedAux[h].DE; //mboxDE *= mandelboxAux[h].mboxDE + extendedAux[h].color; } double r2 = r / fabs(mboxDE); if (r2 > 20) r2 = 20; if (mboxColor > 1000) mboxColor = 1000; out->colorIndex = minimumR * 1000.0 + mboxColor * 100 + r2 * 5000.0; } else { switch (formula) { case mandelbox: case smoothMandelbox: case mandelboxVaryScale4D: case generalizedFoldBox: case foldBoxMod1: out->colorIndex = extendedAux[fractalIndex].color * 100.0 + r * defaultFractal->mandelbox.color.factorR + ((in.common.fractalColoringAlgorithm != fractalColoringStandard) ? minimumR * 1000.0 : 0.0); break; case mandelbulb5: case mandelbox103: case mandelbulb6Beta: case benesiTransforms: case mengerSponge105: out->colorIndex = extendedAux[fractalIndex].newR + ((in.common.fractalColoringAlgorithm != fractalColoringStandard) ? minimumR * 1000.0 : 0.0); break; case mengerMod1: case aboxModKali: case aboxMod1: case menger_sponge: case kaleidoscopicIFS: out->colorIndex = minimumR * 1000.0; break; case amazingSurf: case amazingSurfMod1: out->colorIndex = minimumR * 200.0; break; case msltoeDonut: out->colorIndex = extendedAux[fractalIndex].color * 2000.0 / i; break; default: out->colorIndex = minimumR * 5000.0; break; } } } else { out->distance = 0.0; } out->iters = i + 1; out->z = z; // CVector3( z.x, z.y, w); //tim = rdtsc() - tim; perf+= tim; perfCount++; outStream << (double)perf/perfCount - 560.0 << endl; //------------- 3249 ns for all calculation ---------------- }