当前位置: 首页>>代码示例>>C++>>正文


C++ Color3类代码示例

本文整理汇总了C++中Color3的典型用法代码示例。如果您正苦于以下问题:C++ Color3类的具体用法?C++ Color3怎么用?C++ Color3使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Color3类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: GetColor

/**
*  @brief
*    Get index of color
*/
int ImagePalette::GetColorIndex(const Color3 &cColor) const
{
	// Do we need to build the color index?
	if (m_mapColors.GetNumOfElements() == 0) {
		// Build color index
		for (uint32 i=0; i<m_nColors; i++) {
			// Map color to index
			const uint32 nColorInt = cColor.ToUInt32();
			m_mapColors.Add(nColorInt, i);
		}
	}

	// Look up color index
	const uint32 nColorInt = cColor.ToUInt32();
	int nIndex = m_mapColors.Get(nColorInt);

	// If nIndex is 0, it can be either invalid or really index 0, so check if the colors are equal
	if (nIndex == 0) {
		// Check if color is valid
		const Color3 cColorLookup = GetColor(0);
		if (cColorLookup != cColor || cColorLookup == Color3::Null) {
			// Invalid index
			nIndex = -1;
		}
	}

	// Return color index
	return nIndex;
}
开发者ID:ByeDream,项目名称:pixellight,代码行数:33,代码来源:ImagePalette.cpp

示例2: OnUpdate

/**
*  @brief
*    Called when the scene node modifier needs to be updated
*/
void SNMLightRandomAnimation::OnUpdate()
{
	// Update timer
	m_fTimer += Timing::GetInstance()->GetTimeDifference()*Speed;

	// Set current scene node scale
	SNLight &cLight = static_cast<SNLight&>(GetSceneNode());

	// Animate color
		  Color3 cColor  = cLight.Color.Get();
	const Color3 cColorT = Color.Get()*((Math::Cos(m_fTimer)+1)/2)*Radius;
	if (GetFlags() & Multiply) {
		// Red
		cColor.r = (GetFlags() & NR) ? FixColor.Get().r : FixColor.Get().r*cColorT.r;
		// Green
		cColor.g = (GetFlags() & NG) ? FixColor.Get().g : FixColor.Get().g*cColorT.g;
		// Blue
		cColor.b = (GetFlags() & NB) ? FixColor.Get().b : FixColor.Get().b*cColorT.b;
	} else {
		// Red
		cColor.r = (GetFlags() & NR) ? FixColor.Get().r : FixColor.Get().r+cColorT.r;
		// Green
		cColor.g = (GetFlags() & NG) ? FixColor.Get().g : FixColor.Get().g+cColorT.g;
		// Blue
		cColor.b = (GetFlags() & NB) ? FixColor.Get().b : FixColor.Get().b+cColorT.b;
	}

	// Clamp the color values between 0.0 and 1.0
	cColor.Saturate();

	// Finally, set the new color of the light
	cLight.Color.Set(cColor);
}
开发者ID:ByeDream,项目名称:pixellight,代码行数:37,代码来源:SNMLightRandomAnimation.cpp

示例3: finalGathering

static Color3 finalGathering(KdTree<Photon> *map , Scene& scene , 
							 Intersection& inter , RNG& rng , const Vector3& wo ,
                             int gatherSamples , int knn , Real maxSqrDis)
{
    Color3 res = Color3(0.0 , 0.0 , 0.0);
    for (int i = 0; i < gatherSamples; i++)
    {
		Real pdf;
        Vector3 wi = sampleCosHemisphere(rng.randVector3() , &pdf);
        Ray ray = Ray(inter.p + wi * EPS , wi);

        Intersection _inter;
        
        Geometry *_g = scene.intersect(ray , _inter);

        if (_g == NULL)
            continue;
        
        Color3 tmp = estimate(map , 0 , knn , scene , _inter , -wi , maxSqrDis);

		BSDF bsdf(wi , _inter , scene);
		Real cosine , bsdfPdf;
        Color3 brdf = bsdf.f(scene , wo , cosine , &bsdfPdf);
		if (brdf.isBlack())
			continue;
		pdf *= bsdfPdf;
        res = res + (tmp | brdf) * (cosine / pdf);
    }
    res = res / gatherSamples;
    return res;
}
开发者ID:winmad,项目名称:Winmad-s-raytracer-v1.0,代码行数:31,代码来源:photonMap.cpp

示例4: res

Color3 BidirPathTracing::getLightRadiance(AbstractLight *light , 
	BidirPathState& cameraState , const Vector3& hitPos , 
	const Vector3& rayDir)
{
	int lightCount = scene.lights.size();
	Real lightPickProb = 1.f / lightCount;

	Real directPdfArea , emissionPdf;
	Color3 radiance = light->getRadiance(scene.sceneSphere ,
		rayDir , hitPos , &directPdfArea , &emissionPdf);

	Color3 res(0);

	if (radiance.isBlack())
		return res;

	if (cameraState.pathLength == 1)
		return radiance;

	directPdfArea *= lightPickProb;
	emissionPdf *= lightPickProb;

 	Real wCamera = mis(directPdfArea) * cameraState.dVCM + 
 		mis(emissionPdf) * cameraState.dVC;

	Real weight = 1.f / (1.f + wCamera);

	return radiance * weight;
}
开发者ID:winmad,项目名称:Winmad-s-raytracer-v1.0,代码行数:29,代码来源:bidirPathTracing.cpp

示例5: getDiffuse

Color3 getDiffuse(const Vector3& lightDir , const Vector3& normal , 
	const Color3& lightIntensity , const Color3& diffuse)
{
	Real coe = std::max(0.0 , lightDir ^ normal);
	Color3 res = (lightIntensity | diffuse) * coe;
	res.clamp();
	return res;
}
开发者ID:winmad,项目名称:winmad-s-raytracer,代码行数:8,代码来源:phong.cpp

示例6: getSpecular

Color3 getSpecular(const Vector3& reflecDir , const Vector3& visionDir , 
	const Color3& lightIntensity , const Color3& specular)
{
	Real coe = std::max(0.0 , reflecDir ^ visionDir);
	coe = pow(coe , specularCoefficient);
	Color3 res = (lightIntensity | specular) * coe;
	res.clamp();
	return res;
}
开发者ID:winmad,项目名称:winmad-s-raytracer,代码行数:9,代码来源:phong.cpp

示例7: lerp

float Surfel::ExpressiveParameters::boost(const Color3& diffuseReflectivity) const {
    // Avoid computing the HSV transform in the common case
    if (unsaturatedMaterialBoost == saturatedMaterialBoost) {
        return unsaturatedMaterialBoost;
    }

    const float m = diffuseReflectivity.max();
    const float saturation = (m == 0.0f) ? 0.0f : ((m - diffuseReflectivity.min()) / m);

    return lerp(unsaturatedMaterialBoost, saturatedMaterialBoost, saturation);
}
开发者ID:jackpoz,项目名称:G3D-backup,代码行数:11,代码来源:Surfel.cpp

示例8: clock

/**
 * Raytraces some portion of the scene. Should raytrace for about
 * max_time duration and then return, even if the raytrace is not copmlete.
 * The results should be placed in the given buffer.
 * @param buffer The buffer into which to place the color data. It is
 *  32-bit RGBA (4 bytes per pixel), in row-major order.
 * @param max_time, If non-null, the maximum suggested time this
 *  function raytrace before returning, in seconds. If null, the raytrace
 *  should run to completion.
 * @return true if the raytrace is complete, false if there is more
 *  work to be done.
 */
bool Raytracer::raytrace( unsigned char *buffer, real_t* max_time )
{
    // TODO Add any modifications to this algorithm, if needed.

    static long start_time; // used to show how long time ray tracing cost
    if (0 == current_row)
        start_time = clock();

    static const size_t PRINT_INTERVAL = 64;

    // the time in milliseconds that we should stop
    unsigned int end_time = 0;
    bool is_done = false;

    if ( max_time ) {
        // convert duration to milliseconds
        unsigned int duration = (unsigned int) ( *max_time * 1000 );
        end_time = SDL_GetTicks() + duration;
    }

    // until time is up, run the raytrace. we render an entire row at once
    // for simplicity and efficiency.
    for ( ; !max_time || end_time > SDL_GetTicks(); ++current_row ) {

        if ( current_row % PRINT_INTERVAL == 0 ) {
            printf( "Raytracing (row %u)...\n", current_row );
        }

        // we're done if we finish the last row
        is_done = current_row == height;
        // break if we finish
        if ( is_done )
            break;

        for ( size_t x = 0; x < width; ++x ) {
            // trace a pixel
            Color3 color = trace_pixel( scene, x, current_row, width, height );
            // write the result to the buffer, always use 1.0 as the alpha
            color.to_array( &buffer[4 * ( current_row * width + x )] );
        }
    }

    if ( is_done ) {
        printf( "Done raytracing!\n" );
        printf( "Used %d milliseconds.\n", clock()-start_time );
    }


    return is_done;
}
开发者ID:dtbinh,项目名称:AnimViewer,代码行数:62,代码来源:raytracer.cpp

示例9: cellGcmCgGetNamedParameter

void PS3GCMCGEffect::setUniform(const Color3& uniformData, const char* uniformName) const {
  {
    CGparameter parameter = cellGcmCgGetNamedParameter(vertexProgram_, uniformName);
    if (parameter) {
      cellGcmSetVertexProgramParameter(parameter, uniformData.valuePtr());
    }
  }
  {
    CGparameter parameter = cellGcmCgGetNamedParameter(fragmentProgram_, uniformName);
    if (parameter) {
      cellGcmSetFragmentProgramParameter(fragmentProgram_, parameter, uniformData.valuePtr(), fragmentProgramOffset_);
    }
  }
}
开发者ID:gwowen,项目名称:indigo,代码行数:14,代码来源:PS3GCMCGEffect.cpp

示例10: scatter

bool Raytracer::scatter(const SurfaceSample& s, Photon* p) const
{
	bool scatter = false;
	float t = _random.uniform(0, 1);

	// Check Impulses
	SuperBSDF::Ref bsdf = s.material->bsdf();
	SmallArray<SuperBSDF::Impulse, 3> impulseArray;
	bsdf->getImpulses(s.shadingNormal, s.texCoord, p->direction, impulseArray); // todo: check p.direction

	Color3 impulseSum;

	for (int i = 0; i < impulseArray.size(); ++i)
	{
		if (impulseArray[i].coefficient.average() < 0)
		{
			int sures = 234;
		}
		
		//t -= impulseArray[i].coefficient.average();
		impulseSum += impulseArray[i].coefficient;

		if (t - impulseArray[i].coefficient.average() < 0)
		{
			scatter = true;
			p->direction = impulseArray[i].w;
			p->power = p->power * t / impulseArray[i].coefficient.average();
			check(p->power.average());
			break;
		}
	}

	// Check Diffuse
	if (!scatter)
	{
		const Component4 lambertian = bsdf->lambertian();
		//t - (s.lambertianReflect * (1 - impulseSum.average())).average();

		if (t - (s.lambertianReflect * (1 - impulseSum.average())).average() < 0)
		{
			scatter = true;
			p->direction = Vector3::cosHemiRandom(s.shadingNormal);
			//p->power = p->power * (t / (s.lambertianReflect * (1 - impulseSum.average())).average());
			p->power = p->power * (t / (s.lambertianReflect.average()));// * (1 - impulseSum.average())).average());
			check(p->power.average());
		}
	}

	return scatter;
}
开发者ID:chuckiesmals,项目名称:Thesis,代码行数:50,代码来源:Raytracer.cpp

示例11: sample

    ustring sample (const Vec3 &Ng,
                 const Vec3 &omega_out, const Vec3 &domega_out_dx, const Vec3 &domega_out_dy,
                 float randu, float randv,
                 Vec3 &omega_in, Vec3 &domega_in_dx, Vec3 &domega_in_dy,
                 float &pdf, Color3 &eval) const
    {
        Vec3 R, dRdx, dRdy;
        Vec3 T, dTdx, dTdy;
        bool inside;

        fresnel_dielectric(m_eta, m_N,
                           omega_out, domega_out_dx, domega_out_dy,
                           R, dRdx, dRdy,
                           T, dTdx, dTdy,
                           inside);

        if (!inside) {
            pdf = 1;
            eval.setValue(1.0f, 1.0f, 1.0f);
            omega_in = T;
            domega_in_dx = dTdx;
            domega_in_dy = dTdy;
        }

        return Labels::TRANSMIT;
    }
开发者ID:fabiosantoscode,项目名称:emcycles,代码行数:26,代码来源:bsdf_refraction.cpp

示例12: sample

	ustring sample(const Vec3 &Ng,
	               const Vec3 &omega_out, const Vec3 &domega_out_dx, const Vec3 &domega_out_dy,
	               float randu, float randv,
	               Vec3 &omega_in, Vec3 &domega_in_dx, Vec3 &domega_in_dy,
	               float &pdf, Color3 &eval) const
	{
		// we are viewing the surface from the right side - send a ray out with cosine
		// distribution over the hemisphere
		sample_cos_hemisphere(m_N, omega_out, randu, randv, omega_in, pdf);
		if (Ng.dot(omega_in) > 0) {
			// TODO: account for sheen when sampling
			float cosNO = m_N.dot(omega_out);
			float sinNO2 = 1 - cosNO * cosNO;
			float westin = sinNO2 > 0 ? powf(sinNO2, 0.5f * m_edginess) * pdf : 0;
			eval.setValue(westin, westin, westin);
			// TODO: find a better approximation for the diffuse bounce
			domega_in_dx = (2 * m_N.dot(domega_out_dx)) * m_N - domega_out_dx;
			domega_in_dy = (2 * m_N.dot(domega_out_dy)) * m_N - domega_out_dy;
			domega_in_dx *= 125;
			domega_in_dy *= 125;
		}
		else {
			pdf = 0;
		}
		return Labels::REFLECT;
	}
开发者ID:vanangamudi,项目名称:blender-main,代码行数:26,代码来源:bsdf_westin.cpp

示例13: SetColor

/**
*  @brief
*    Set color
*/
void ImagePalette::SetColor(uint32 nIndex, const Color3 &cColor)
{
	// Do we have to resize the palette?
	if (nIndex >= m_nColors)
		Resize(nIndex);

	// Set color
	if (m_pData) {
		m_pData[nIndex*3+0] = cColor.GetRInt();
		m_pData[nIndex*3+1] = cColor.GetGInt();
		m_pData[nIndex*3+2] = cColor.GetBInt();
	}

	// Rebuild color index
	RebuildColorIndex();
}
开发者ID:ByeDream,项目名称:pixellight,代码行数:20,代码来源:ImagePalette.cpp

示例14: sampleScattering

bool BidirPathTracing::sampleScattering(BSDF& bsdf , 
	const Vector3& hitPos , BidirPathState& pathState)
{
	Real bsdfDirPdf , cosWo;
	int sampledBSDFType;
	Color3 bsdfFactor = bsdf.sample(scene , rng.randVector3() ,
		pathState.dir , bsdfDirPdf , cosWo , &sampledBSDFType);

	if (bsdfFactor.isBlack())
		return 0;

	Real bsdfRevPdf = bsdfDirPdf;
	if ((sampledBSDFType & BSDF_SPECULAR) == 0)
		bsdfRevPdf = bsdf.pdf(scene , pathState.dir , 1);

	Real contProb = bsdf.continueProb;
	if (rng.randFloat() > contProb)
		return 0;

	bsdfDirPdf *= contProb;
	bsdfRevPdf *= contProb;

	// Partial sub-path MIS quantities
	// the evaluation is completed when the actual hit point is known!
	// i.e. after tracing the ray, out of the procedure
	if (sampledBSDFType & BSDF_SPECULAR)
	{
		pathState.specularVertexNum++;

		pathState.dVCM = 0.f;
		pathState.dVC *= mis(cosWo);
	}
	else
	{
		pathState.specularPath &= 0;

		pathState.dVC = mis(1.f / bsdfDirPdf) * (pathState.dVCM +
			pathState.dVC * mis(bsdfRevPdf));
		pathState.dVCM = mis(1.f / bsdfDirPdf);
	}

	pathState.origin = hitPos;
	pathState.throughput = (pathState.throughput | bsdfFactor) *
		(cosWo / bsdfDirPdf);

	return 1;
}
开发者ID:winmad,项目名称:Winmad-s-raytracer-v1.0,代码行数:47,代码来源:bidirPathTracing.cpp

示例15: get_viewing_frustum

void Raytracer::trace_packet(PacketRegion region, float refractive, unsigned char *buffer)
{
    Int2 ll = region.ll;
    Int2 lr = region.lr;
    Int2 ul = region.ul;
    Int2 ur = region.ur;

    IsectInfo infos[rays_per_packet];
    bool intersected[rays_per_packet];
    Packet packet;
    get_viewing_frustum(ll, lr, ul, ur, packet.frustum);
    Vector3 eye = scene->camera.get_position();
    Int2 pixels[rays_per_packet];
    int r = 0; // counter for rays in packet

    for (int y = ll.y; y <= ul.y; y++)
    {
        for (int x = ll.x; x <= lr.x; x++)
        {
            Int2 pixel(x, y);
            packet.rays[r].eye = eye;
            packet.rays[r].dir = get_viewing_ray(pixel);
            pixels[r] = pixel;
            intersected[r] = false;
            r++;
        }
    }

    for (size_t i = 0; i < scene->num_geometries(); i++)
    {
        scene->get_geometries()[i]->intersect_packet(packet, infos, intersected);
    }

    for (int i = 0; i < rays_per_packet; i++)
    {
        if (intersected[i])
        {
            Color3 color = trace_pixel_end(0, packet.rays[i], refractive, infos[i]);
            color.to_array(&buffer[4 * (pixels[i].y * width + pixels[i].x)]);
        }
        else
        {
            Color3 color = scene->background_color;
            color.to_array(&buffer[4 * (pixels[i].y * width + pixels[i].x)]);
        }
    }
}
开发者ID:nslo,项目名称:raytracer,代码行数:47,代码来源:raytracer.cpp


注:本文中的Color3类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。