void STKMeshSceneNode::drawSolidPass2(const GLMesh &mesh, ShadedMaterial type) { switch (type) { case SM_SPHEREMAP: drawSphereMap(mesh, ModelViewProjectionMatrix, TransposeInverseModelView); break; case SM_SPLATTING: drawSplatting(mesh, ModelViewProjectionMatrix); break; case SM_ALPHA_REF_TEXTURE: drawObjectRefPass2(mesh, ModelViewProjectionMatrix, mesh.TextureMatrix); break; case SM_GRASS: drawGrassPass2(mesh, ModelViewProjectionMatrix, windDir); break; case SM_RIMLIT: drawObjectRimLimit(mesh, ModelViewProjectionMatrix, TransposeInverseModelView, core::matrix4::EM4CONST_IDENTITY); break; case SM_UNLIT: drawObjectUnlit(mesh, ModelViewProjectionMatrix); break; case SM_CAUSTICS: { const float time = irr_driver->getDevice()->getTimer()->getTime() / 1000.0f; const float speed = World::getWorld()->getTrack()->getCausticsSpeed(); float strength = time; strength = fabsf(noise2d(strength / 10.0f)) * 0.006f + 0.001f; vector3df wind = irr_driver->getWind() * strength * speed; caustic_dir.X += wind.X; caustic_dir.Y += wind.Z; strength = time * 0.56f + sinf(time); strength = fabsf(noise2d(0.0, strength / 6.0f)) * 0.0095f + 0.001f; wind = irr_driver->getWind() * strength * speed; wind.rotateXZBy(cosf(time)); caustic_dir2.X += wind.X; caustic_dir2.Y += wind.Z; drawCaustics(mesh, ModelViewProjectionMatrix, caustic_dir, caustic_dir2); break; } case SM_DETAILS: drawDetailledObjectPass2(mesh, ModelViewProjectionMatrix); break; case SM_UNTEXTURED: drawUntexturedObject(mesh, ModelViewProjectionMatrix); break; case SM_DEFAULT: drawObjectPass2(mesh, ModelViewProjectionMatrix, mesh.TextureMatrix); break; default: assert(0 && "Wrong shaded material"); break; } }
float interpNoise2d(float x, float y) { float ix = (int)(floor(x)); float iy = (int)(floor(y)); float fx = x - floor(x); float fy = y - floor(y); float v00 = noise2d(ix, iy); float v10 = noise2d(ix + 1, iy); float v01 = noise2d(ix, iy + 1); float v11 = noise2d(ix + 1, iy + 1); float u0 = cosinInterp(v00, v10, fx); float u1 = cosinInterp(v01, v11, fx); return cosinInterp(u0, u1, fy); }
BiomeV6Type MapgenV6::getBiome(int index, v3POS p) { // Just do something very simple as for now /*double d = noise2d_perlin( 0.6+(float)p2d.X/250, 0.2+(float)p2d.Y/250, seed+9130, 3, 0.50);*/ float d, h; if (m_emerge->env->m_use_weather_biome) { d = (m_emerge->env->getServerMap().updateBlockHeat(m_emerge->env, p, nullptr, &heat_cache) - m_emerge->params.np_biome_heat.offset) / m_emerge->params.np_biome_heat.scale; h = (m_emerge->env->getServerMap().updateBlockHumidity(m_emerge->env, p, nullptr, &humidity_cache) - m_emerge->params.np_biome_humidity.offset) / m_emerge->params.np_biome_humidity.scale; } else { d = noise_biome->result[index]; h = noise_humidity->result[index]; } if (spflags & MGV6_SNOWBIOMES) { float blend = (spflags & MGV6_BIOMEBLEND) ? noise2d(p.X, p.Y, seed) / 40 : 0; if (d > MGV6_FREQ_HOT + blend) { if (h > MGV6_FREQ_JUNGLE + blend) return BT_JUNGLE; else return BT_DESERT; } else if (d < MGV6_FREQ_SNOW + blend) { if (h > MGV6_FREQ_TAIGA + blend) return BT_TAIGA; else return BT_TUNDRA; } else { return BT_NORMAL; } } else { if (d > freq_desert) return BT_DESERT; if ((spflags & MGV6_BIOMEBLEND) && (d > freq_desert - 0.10) && ((noise2d(p.X, p.Y, seed) + 1.0) > (freq_desert - d) * 20.0)) return BT_DESERT; if ((spflags & MGV6_JUNGLES) && h > 0.75) return BT_JUNGLE; else return BT_NORMAL; } }
double C3DPerlinNoise::generateNoise2D(double x, double y) { x *= _frequency; y *= _frequency; int ix = (int)x; int iy = (int)y; double sx = x - ix; double sy = y - iy; ix += _seed; iy += _seed; double r00 = noise2d(ix, iy); double r10 = noise2d(ix + 1, iy); double r01 = noise2d(ix, iy + 1); double r11 = noise2d(ix + 1, iy + 1); double r0 = interpolate(r00, r10, sx); double r1 = interpolate(r01, r11, sx); return interpolate(r0, r1, sy) * _factorScale + _factorAdd; }
BiomeV6Type MapgenV6::getBiome(int index, v2s16 p) { // Just do something very simple as for now /*double d = noise2d_perlin( 0.6+(float)p2d.X/250, 0.2+(float)p2d.Y/250, seed+9130, 3, 0.50);*/ float d = noise_biome->result[index]; float h = noise_humidity->result[index]; if (spflags & MGV6_SNOWBIOMES) { float blend = (spflags & MGV6_BIOMEBLEND) ? noise2d(p.X, p.Y, seed) / 40 : 0; if (d > FREQ_HOT + blend) { if (h > FREQ_JUNGLE + blend) return BT_JUNGLE; else return BT_DESERT; } else if (d < FREQ_SNOW + blend) { if (h > FREQ_TAIGA + blend) return BT_TAIGA; else return BT_TUNDRA; } else { return BT_NORMAL; } } else { if (d > freq_desert) return BT_DESERT; if ((spflags & MGV6_BIOMEBLEND) && (d > freq_desert - 0.10) && ((noise2d(p.X, p.Y, seed) + 1.0) > (freq_desert - d) * 20.0)) return BT_DESERT; if ((spflags & MGV6_JUNGLES) && h > 0.75) return BT_JUNGLE; else return BT_NORMAL; } }
virtual void affect(u32 now, scene::SParticle* particlearray, u32 count) { const float time = irr_driver->getDevice()->getTimer()->getTime() / 10000.0f; core::vector3df dir = irr_driver->getWind(); dir *= m_speed * std::min(noise2d(time, m_seed), -0.2f); for (u32 n = 0; n < count; n++) { scene::SParticle& cur = particlearray[n]; cur.pos += dir; } // for n<count } // affect
static core::vector3df getWind() { const core::vector3df pos = irr_driver->getVideoDriver()->getTransform(video::ETS_WORLD).getTranslation(); const float time = irr_driver->getDevice()->getTimer()->getTime() / 1000.0f; GrassShaderProvider *gsp = (GrassShaderProvider *)irr_driver->getCallback(ES_GRASS); float m_speed = gsp->getSpeed(), m_amplitude = gsp->getAmplitude(); float strength = (pos.X + pos.Y + pos.Z) * 1.2f + time * m_speed; strength = noise2d(strength / 10.0f) * m_amplitude * 5; // * 5 is to work with the existing amplitude values. // Pre-multiply on the cpu return irr_driver->getWind() * strength; }
float noise_sum_2d(float x, float y, noise_sum* n) { float scale = n->scale; float v = 0; unsigned count = n->count; noise* noise = &n->n; for(unsigned i = 0; i < count; i++) { float tx = scale * x; float ty = scale * y; //float ttx = (tx * (count - i) + ty * i) / count; //float tty = (ty * (count - i) + tx * i) / count; //v += noise2d(ttx, tty, noise); //scale *= -1.5; v += noise2d(tx, ty, noise); scale *= -2; } return v / count; //Matrix version. It's too slow. /* float mStore[8]; memcpy(mStore, n->m, 8 * sizeof(float)); float* m = mStore; float* nm = mStore + 4; for(unsigned i = 0; i < count; i++) { float tx = n->xp * i + m[0] * x + m[1] * y; float ty = n->yp * i + m[2] * x + m[3] * y; v += noise2d(ty, tx, noise); //Multiply m by the original matrix (we want m^i in the next iteration). nm[0] = m[0] * n->m[0] + m[1] * n->m[2]; nm[1] = m[0] * n->m[1] + m[1] * n->m[3]; //TODO nm2, nm3. if(m == mStore) { m = mStore + 4; nm = mStore; } else { m = mStore; nm = mStore + 4; } } return v / count; */ }
BiomeType MapgenV6::getBiome(int index, v2s16 p) { // Just do something very simple as for now /*double d = noise2d_perlin( 0.6+(float)p2d.X/250, 0.2+(float)p2d.Y/250, seed+9130, 3, 0.50);*/ float d = noise_biome->result[index]; if (d > freq_desert) return BT_DESERT; if ((flags & MGV6_BIOME_BLEND) && (d > freq_desert - 0.10) && ((noise2d(p.X, p.Y, seed) + 1.0) > (freq_desert - d) * 20.0)) return BT_DESERT; return BT_NORMAL; }
float TURB_Turbulence2d( float *table, float x, float y, long octaves ) { float t, s; t = 0.0; s = 0.5; while( octaves-- ) { t += noise2d(x,y)*s; s*=0.5; x*=2.0; y*=2.0; } if( t>1.0 ) t=1.0; if( t<0.0 ) t=0.0; return( t ); }