コード例 #1
0
bool OSLRenderServices::get_object_standard_attribute(KernelGlobals *kg, ShaderData *sd, ustring name,
        TypeDesc type, bool derivatives, void *val)
{
    /* todo: turn this into hash table? */

    /* Object Attributes */
    if (name == u_object_location) {
        float3 f = object_location(kg, sd);
        return set_attribute_float3(f, type, derivatives, val);
    }
    else if (name == u_object_index) {
        float f = object_pass_id(kg, sd->object);
        return set_attribute_float(f, type, derivatives, val);
    }
    else if (name == u_geom_dupli_generated) {
        float3 f = object_dupli_generated(kg, sd->object);
        return set_attribute_float3(f, type, derivatives, val);
    }
    else if (name == u_geom_dupli_uv) {
        float3 f = object_dupli_uv(kg, sd->object);
        return set_attribute_float3(f, type, derivatives, val);
    }
    else if (name == u_material_index) {
        float f = shader_pass_id(kg, sd);
        return set_attribute_float(f, type, derivatives, val);
    }
    else if (name == u_object_random) {
        float f = object_random_number(kg, sd->object);
        return set_attribute_float(f, type, derivatives, val);
    }

    /* Particle Attributes */
    else if (name == u_particle_index) {
        uint particle_id = object_particle_id(kg, sd->object);
        float f = particle_index(kg, particle_id);
        return set_attribute_float(f, type, derivatives, val);
    }
    else if (name == u_particle_age) {
        uint particle_id = object_particle_id(kg, sd->object);
        float f = particle_age(kg, particle_id);
        return set_attribute_float(f, type, derivatives, val);
    }
    else if (name == u_particle_lifetime) {
        uint particle_id = object_particle_id(kg, sd->object);
        float f= particle_lifetime(kg, particle_id);
        return set_attribute_float(f, type, derivatives, val);
    }
    else if (name == u_particle_location) {
        uint particle_id = object_particle_id(kg, sd->object);
        float3 f = particle_location(kg, particle_id);
        return set_attribute_float3(f, type, derivatives, val);
    }
#if 0	/* unsupported */
    else if (name == u_particle_rotation) {
        uint particle_id = object_particle_id(kg, sd->object);
        float4 f = particle_rotation(kg, particle_id);
        return set_attribute_float4(f, type, derivatives, val);
    }
#endif
    else if (name == u_particle_size) {
        uint particle_id = object_particle_id(kg, sd->object);
        float f = particle_size(kg, particle_id);
        return set_attribute_float(f, type, derivatives, val);
    }
    else if (name == u_particle_velocity) {
        uint particle_id = object_particle_id(kg, sd->object);
        float3 f = particle_velocity(kg, particle_id);
        return set_attribute_float3(f, type, derivatives, val);
    }
    else if (name == u_particle_angular_velocity) {
        uint particle_id = object_particle_id(kg, sd->object);
        float3 f = particle_angular_velocity(kg, particle_id);
        return set_attribute_float3(f, type, derivatives, val);
    }

    /* Geometry Attributes */
    else if (name == u_geom_numpolyvertices) {
        return set_attribute_int(3, type, derivatives, val);
    }
    else if ((name == u_geom_trianglevertices || name == u_geom_polyvertices)
#ifdef __HAIR__
             && sd->segment == ~0) {
#else
            ) {
#endif
        float3 P[3];
        triangle_vertices(kg, sd->prim, P);

        if(!(sd->flag & SD_TRANSFORM_APPLIED)) {
            object_position_transform(kg, sd, &P[0]);
            object_position_transform(kg, sd, &P[1]);
            object_position_transform(kg, sd, &P[2]);
        }

        return set_attribute_float3_3(P, type, derivatives, val);
    }
    else if(name == u_geom_name) {
        ustring object_name = kg->osl->object_names[sd->object];
        return set_attribute_string(object_name, type, derivatives, val);
    }

#ifdef __HAIR__
    /* Hair Attributes */
    else if (name == u_is_curve) {
        float f = (sd->segment != ~0);
        return set_attribute_float(f, type, derivatives, val);
    }
    else if (name == u_curve_thickness) {
        float f = curve_thickness(kg, sd);
        return set_attribute_float(f, type, derivatives, val);
    }
    else if (name == u_curve_tangent_normal) {
        float3 f = curve_tangent_normal(kg, sd);
        return set_attribute_float3(f, type, derivatives, val);
    }
#endif
    else
        return false;
}
コード例 #2
0
ファイル: osl_services.cpp プロジェクト: Moguri/blender
bool OSLRenderServices::get_object_standard_attribute(KernelGlobals *kg, ShaderData *sd, ustring name,
                                                      TypeDesc type, bool derivatives, void *val)
{
	/* todo: turn this into hash table? */

	/* Object Attributes */
	if(name == u_object_location) {
		float3 f = object_location(kg, sd);
		return set_attribute_float3(f, type, derivatives, val);
	}
	else if(name == u_object_index) {
		float f = object_pass_id(kg, sd->object);
		return set_attribute_float(f, type, derivatives, val);
	}
	else if(name == u_geom_dupli_generated) {
		float3 f = object_dupli_generated(kg, sd->object);
		return set_attribute_float3(f, type, derivatives, val);
	}
	else if(name == u_geom_dupli_uv) {
		float3 f = object_dupli_uv(kg, sd->object);
		return set_attribute_float3(f, type, derivatives, val);
	}
	else if(name == u_material_index) {
		float f = shader_pass_id(kg, sd);
		return set_attribute_float(f, type, derivatives, val);
	}
	else if(name == u_object_random) {
		float f = object_random_number(kg, sd->object);
		return set_attribute_float(f, type, derivatives, val);
	}

	/* Particle Attributes */
	else if(name == u_particle_index) {
		int particle_id = object_particle_id(kg, sd->object);
		float f = particle_index(kg, particle_id);
		return set_attribute_float(f, type, derivatives, val);
	}
	else if(name == u_particle_age) {
		int particle_id = object_particle_id(kg, sd->object);
		float f = particle_age(kg, particle_id);
		return set_attribute_float(f, type, derivatives, val);
	}
	else if(name == u_particle_lifetime) {
		int particle_id = object_particle_id(kg, sd->object);
		float f = particle_lifetime(kg, particle_id);
		return set_attribute_float(f, type, derivatives, val);
	}
	else if(name == u_particle_location) {
		int particle_id = object_particle_id(kg, sd->object);
		float3 f = particle_location(kg, particle_id);
		return set_attribute_float3(f, type, derivatives, val);
	}
#if 0	/* unsupported */
	else if(name == u_particle_rotation) {
		int particle_id = object_particle_id(kg, sd->object);
		float4 f = particle_rotation(kg, particle_id);
		return set_attribute_float4(f, type, derivatives, val);
	}
#endif
	else if(name == u_particle_size) {
		int particle_id = object_particle_id(kg, sd->object);
		float f = particle_size(kg, particle_id);
		return set_attribute_float(f, type, derivatives, val);
	}
	else if(name == u_particle_velocity) {
		int particle_id = object_particle_id(kg, sd->object);
		float3 f = particle_velocity(kg, particle_id);
		return set_attribute_float3(f, type, derivatives, val);
	}
	else if(name == u_particle_angular_velocity) {
		int particle_id = object_particle_id(kg, sd->object);
		float3 f = particle_angular_velocity(kg, particle_id);
		return set_attribute_float3(f, type, derivatives, val);
	}
	
	/* Geometry Attributes */
	else if(name == u_geom_numpolyvertices) {
		return set_attribute_int(3, type, derivatives, val);
	}
	else if((name == u_geom_trianglevertices || name == u_geom_polyvertices)
#ifdef __HAIR__
		     && sd->type & PRIMITIVE_ALL_TRIANGLE)
#else
		)
#endif
	{
		float3 P[3];

		if(sd->type & PRIMITIVE_TRIANGLE)
			triangle_vertices(kg, sd->prim, P);
		else
			motion_triangle_vertices(kg, sd->object, sd->prim, sd->time, P);

		if(!(sd->flag & SD_TRANSFORM_APPLIED)) {
			object_position_transform(kg, sd, &P[0]);
			object_position_transform(kg, sd, &P[1]);
			object_position_transform(kg, sd, &P[2]);
		}

		return set_attribute_float3_3(P, type, derivatives, val);
	}
	else if(name == u_geom_name) {