void main1_3(void *arg)
	{
		color Kd = color(diffuse(), diffuse(), diffuse());

		normal Nf = faceforward(normalize(N()), I());
		vector V = -normalize(I());

		while (illuminance(P(), Nf, PI / 2.0f))
		{
			color C = 0.0f;
			SAMPLE_LIGHT_2(color, C, 0.0f,
				C += Cl() * (
					color_() * Kd * (normalize(L()) % Nf) 
					+ cosinePower() * specularColor() * specularbrdf(normalize(L()), Nf, V, 0.1f/*roughness()*/)
					)
				);

			Ci() += C;
		}

		if ( ! less_than( &transparency(), LIQ_SCALAR_ALMOST_ZERO ) )
		{//transparent
			Ci() = Ci() * ( 1.0f - transparency() ) + trace_transparent() * transparency();
		}//else{ opacity }
		setOutputForMaya();
	}
示例#2
0
Color Lambert::eval(const IntersectionInfo& x, const Vector& w_in, const Vector& w_out)
{
	Color diffuse = texture ? texture->sample(x) : this->color;
	Vector N = faceforward(w_in, x.normal);

		  /*color*/  /*BRDF*/   /*Kajiya's cosine term*/
	return diffuse * (1 / PI)     *   dot(w_out, N);
}
	normal ShadingNormal(const normal& i_N)
	{
		normal Nf = i_N;

		//const int sides = 2;
		if( true/*sides == 2*/ )
		{
			Nf = faceforward(Nf, I);
		}
		return Nf;
	}
示例#4
0
void Refl::spawnRay(const IntersectionInfo& x, const Vector& w_in,
						Ray& w_out, Color& out_color, float& pdf)
{
	if (glossiness != 1)
		return BRDF::spawnRay(x, w_in, w_out, out_color, pdf);

	Vector n = faceforward(w_in, x.normal);

	w_out.dir = reflect(w_in, n);
	w_out.start = x.ip + n * 1e-6;
	w_out.flags &= ~RF_DIFFUSE;
	out_color = Color(1, 1, 1) * multiplier;
	pdf = 1;
}
示例#5
0
void Lambert::spawnRay(const IntersectionInfo& x, const Vector& w_in,
						Ray& w_out, Color& out_color, float& pdf)
{
	out_color = texture ? texture->sample(x) : this->color;
	Vector N = faceforward(w_in, x.normal);

	w_out.dir = hemisphereSample(N);
	w_out.flags |= RF_DIFFUSE;
	w_out.start = x.ip + N * 1e-6;

	/*color*/    /*BRDF*/   /*Kajiya's cos term*/
	out_color *= (1 / PI) * dot(w_out.dir, N);

	// 1/2PI since the ray probability is spread over the entire hemisphere:
	pdf = 1 / (2 * PI);
}
示例#6
0
void ShadingPoint::refine_and_offset() const
{
    assert(hit());
    assert(!(m_members & ShadingPoint::HasRefinedPoints));

    // Cache the source geometry.
    cache_source_geometry();

    // Compute the location of the intersection point in assembly instance space.
    ShadingRay::RayType local_ray =
        m_assembly_instance->get_transform().transform_to_local(m_ray);
    local_ray.m_org += local_ray.m_tmax * local_ray.m_dir;

    // Refine the location of the intersection point.
    local_ray.m_org =
        Intersector::refine(
            m_triangle_support_plane,
            local_ray.m_org,
            local_ray.m_dir);

    // Compute the geometric normal to the hit triangle in assembly instance space.
    // Note that it doesn't need to be normalized at this point.
    m_asm_geo_normal = Vector3d(cross(m_v1 - m_v0, m_v2 - m_v0));
    m_asm_geo_normal = m_object_instance->get_transform().transform_normal_to_parent(m_asm_geo_normal);
    m_asm_geo_normal = faceforward(m_asm_geo_normal, local_ray.m_dir);

    // Compute the offset points in assembly instance space.
#ifdef RENDERER_ADAPTIVE_OFFSET
    Intersector::adaptive_offset(
        m_triangle_support_plane,
        local_ray.m_org,
        m_asm_geo_normal,
        m_front_point,
        m_back_point);
#else
    Intersector::offset(
        local_ray.m_org,
        m_asm_geo_normal,
        m_front_point,
        m_back_point);
#endif

    // The refined intersection points are now available.
    m_members |= ShadingPoint::HasRefinedPoints;
}
示例#7
0
Color Refr::shade(const Ray& ray, const IntersectionInfo& info)
{
// ior = eta2 / eta1
	Vector refr;
	if (dot(ray.dir, info.normal) < 0) {
		// entering the geometry
		refr = refract(ray.dir, info.normal, 1 / ior);
	} else {
		// leaving the geometry
		refr = refract(ray.dir, -info.normal, ior);
	}
	if (refr.lengthSqr() == 0) return Color(0, 0, 0);
	Ray newRay = ray;
	newRay.start = info.ip - faceforward(ray.dir, info.normal) * 0.000001;
	newRay.dir = refr;
	newRay.depth++;
	return raytrace(newRay) * multiplier;
}
	void main1(void *arg)
	{
		color Kd = color(diffuse(), diffuse(), diffuse());

		normal Nf = faceforward(normalize(N()), I());
		vector V = -normalize(I());

		while (illuminance(P(), Nf, PI / 2.0f))
		{
			color	C = 0.0f;
			color	last = 0.0f;
			int		num_samples = 0;

			while (sample_light())
			{
				C += Cl() * (
					color_() * Kd * (normalize(L()) % Nf) 
					+ cosinePower() * specularColor() * specularbrdf(normalize(L()), Nf, V, 0.1f/*roughness()*/)
					);

				++ num_samples;

				if ((num_samples % 4) == 0)
				{
					color	current = C * (1.0f / (scalar)num_samples);

					if (converged(current, last)){
						break;
					}
					last = current;
				}
			}

			C *= (1.0f / (scalar)num_samples);
			Ci() += C;
		}

		if ( ! less_than( &transparency(), LIQ_SCALAR_ALMOST_ZERO ) )
		{//transparent
			Ci() = Ci() * ( 1.0f - transparency() ) + trace_transparent() * transparency();
		}//else{ opacity }
		setOutputForMaya();
	}
示例#9
0
Color Refl::shade(const Ray& ray, const IntersectionInfo& info)
{
	Vector n = faceforward(ray.dir, info.normal);

	if (glossiness == 1) {
		Ray newRay = ray;
		newRay.start = info.ip + n * 0.000001;
		newRay.dir = reflect(ray.dir, n);
		newRay.depth++;

		return raytrace(newRay) * multiplier;
	} else {
		Random& rnd = getRandomGen();
		Color result(0, 0, 0);
		int count = numSamples;
		if (ray.depth > 0)
			count = 2;
		for (int i = 0; i < count; i++) {
			Vector a, b;
			orthonormalSystem(n, a, b);
			double x, y, scaling;

			rnd.unitDiscSample(x, y);
			//
			scaling = tan((1 - glossiness) * PI/2);
			x *= scaling;
			y *= scaling;

			Vector modifiedNormal = n + a * x + b * y;

			Ray newRay = ray;
			newRay.start = info.ip + n * 0.000001;
			newRay.dir = reflect(ray.dir, modifiedNormal);
			newRay.depth++;

			result += raytrace(newRay) * multiplier;
		}
		return result / count;
	}
}
示例#10
0
Color Phong::shade(const Ray& ray, const IntersectionInfo& info)
{

	Color diffuse = texture ? texture->sample(info) : this->color;

	Color result(0, 0, 0);
	for (auto& light: scene.lights) {
		int N = 1;
		Color sum (0, 0, 0);
		for (int i = 0; i < 1; i++) {
			Vector lightPos;
			Color lightColor;
			light->getNthSample(i, info.ip, lightPos, lightColor);
			Vector v2 = info.ip - lightPos; // from light towards the intersection point
			Vector v1 = faceforward(ray.dir, info.normal); // orient so that surface points to the light
			v2.normalize();
			double lambertCoeff = dot(v1, -v2);
			Color fromLight = getLightContrib(info, lightPos, lightColor);

			Vector r = reflect(v2, v1);
			Vector toCamera = -ray.dir;
			double cosGamma = dot(toCamera, r);
			double phongCoeff;
			if (cosGamma > 0)
				phongCoeff = pow(cosGamma, specularExponent);
			else
				phongCoeff = 0;

			sum += diffuse * lambertCoeff * fromLight
				  + (phongCoeff * specularMultiplier * fromLight);

		}
		result += sum / N;
	}
	result += scene.settings.ambientLight * diffuse;
	return result;

}
示例#11
0
Color Lambert::shade(const Ray& ray, const IntersectionInfo& info)
{
	Color diffuse = texture ? texture->sample(info) : this->color;

	Color result(0, 0, 0);
	for (auto& light: scene.lights) {
		int N = light->getNumSamples();
		Color sum (0, 0, 0);
		for (int i = 0; i < 1; i++) {
			Vector lightPos;
			Color lightColor;
			light->getNthSample(i, info.ip, lightPos, lightColor);
			Vector v2 = info.ip - lightPos; // from light towards the intersection point
			Vector v1 = faceforward(ray.dir, info.normal); // orient so that surface points to the light
			v2.normalize();
			double lambertCoeff = dot(v1, -v2);
			sum += diffuse * lambertCoeff * getLightContrib(info, lightPos, lightColor);
		}
		result += sum / N;
	}
    result += scene.settings.ambientLight * diffuse;
	return result;

}
void PointBasedLightingShader::compileShader(void)
	{
	const GLLightTracker& lt=*(contextData.getLightTracker());
	const GLClipPlaneTracker& cpt=*(contextData.getClipPlaneTracker());
	
	std::string vertexShaderDefines;
	std::string vertexShaderFunctions;
	std::string vertexShaderMain;
	
	if(usePlaneDistance)
		{
		/* Create the plane distance mapping uniforms: */
		vertexShaderMain+="\
			uniform vec4 planeDistancePlane;\n\
			uniform sampler1D planeDistanceMap;\n\
			\n";
		}
	
	/* Create the main vertex shader starting boilerplate: */
	vertexShaderMain+="\
		void main()\n\
			{\n\
			/* Compute the vertex position in eye coordinates: */\n\
			vec4 vertexEc=gl_ModelViewMatrix*gl_Vertex;\n\
			\n\
			/* Compute the normal vector in eye coordinates: */\n\
			vec3 normalEc=normalize(gl_NormalMatrix*gl_Normal);\n\
			\n\
			/* Let the normal vector always point towards the eye: */\n\
			normalEc=faceforward(normalEc,normalEc,vertexEc.xyz);\n\
			\n";
	
	/* Get the material components: */
	if(usePlaneDistance)
		{
		#ifdef LIDARVIEWER_VISUALIZE_WATER
		
		vertexShaderMain+="\
			/* Calculate the distance from the water surface: */\n\
			float planeDist=dot(planeDistancePlane,gl_Vertex);\n\
			vec4 ambient,diffuse;\n\
			if(planeDist<=0.5)\n\
				{\n\
				/* Get the material properties from the plane distance texture: */\n\
				ambient=texture1D(planeDistanceMap,planeDist);\n\
				diffuse=ambient;\n\
				}\n\
			else\n\
				{\n";
		
		if(usePointColors)
			{
			vertexShaderMain+="\
				/* Get the material properties from the current color: */\n\
				ambient=gl_Color;\n\
				diffuse=gl_Color;\n";
			}
		else
			{
			vertexShaderMain+="\
				/* Get the material properties from the material state: */\n\
				ambient=gl_FrontMaterial.ambient;\n\
				diffuse=gl_FrontMaterial.diffuse;\n";
			}
		
		vertexShaderMain+="\
				}\n";
		
		#else
		
		vertexShaderMain+="\
			/* Get the material properties from the plane distance texture: */\n\
			float planeDist=dot(planeDistancePlane,gl_Vertex);\n\
			vec4 ambient=texture1D(planeDistanceMap,planeDist);\n\
			vec4 diffuse=ambient;\n";
		
		#endif
		}
	else if(usePointColors)
		{
		vertexShaderMain+="\
			/* Get the material properties from the current color: */\n\
			vec4 ambient=gl_Color;\n\
			vec4 diffuse=gl_Color;\n";
		}
	else
		{
		vertexShaderMain+="\
			/* Get the material properties from the material state: */\n\
			vec4 ambient=gl_FrontMaterial.ambient;\n\
			vec4 diffuse=gl_FrontMaterial.diffuse;\n";
		}
	vertexShaderMain+="\
			vec4 specular=gl_FrontMaterial.specular;\n\
			float shininess=gl_FrontMaterial.shininess;\n\
			\n";
	
	/* Continue the main vertex shader: */
	vertexShaderMain+="\
			/* Calculate global ambient light term: */\n\
			vec4 ambientDiffuseAccum=gl_LightModel.ambient*ambient;\n\
			vec4 specularAccum=vec4(0.0,0.0,0.0,0.0);\n\
			\n\
			/* Accumulate all enabled light sources: */\n";
	
	/* Create light application functions for all enabled light sources: */
	for(int lightIndex=0;lightIndex<lt.getMaxNumLights();++lightIndex)
		if(lt.getLightState(lightIndex).isEnabled())
			{
			/* Create the light accumulation function: */
			vertexShaderFunctions+=lt.createAccumulateLightFunction(lightIndex);
			
			/* Call the light application function from the shader's main function: */
			vertexShaderMain+="\
				accumulateLight";
			char liBuffer[12];
			vertexShaderMain.append(Misc::print(lightIndex,liBuffer+11));
			vertexShaderMain+="(vertexEc,normalEc,ambient,diffuse,specular,shininess,ambientDiffuseAccum,specularAccum);\n";
			}