Пример #1
0
bool OSLRenderServices::getmessage(OSL::ShaderGlobals *sg,
                                   ustring source,
                                   ustring name,
                                   TypeDesc type,
                                   void *val,
                                   bool derivatives)
{
  OSLTraceData *tracedata = (OSLTraceData *)sg->tracedata;

  if (source == u_trace && tracedata->init) {
    if (name == u_hit) {
      return set_attribute_int((tracedata->isect.prim != PRIM_NONE), type, derivatives, val);
    }
    else if (tracedata->isect.prim != PRIM_NONE) {
      if (name == u_hitdist) {
        float f[3] = {tracedata->isect.t, 0.0f, 0.0f};
        return set_attribute_float(f, type, derivatives, val);
      }
      else {
        ShaderData *sd = &tracedata->sd;
        KernelGlobals *kg = sd->osl_globals;

        if (!tracedata->setup) {
          /* lazy shader data setup */
          shader_setup_from_ray(kg, sd, &tracedata->isect, &tracedata->ray);
          tracedata->setup = true;
        }

        if (name == u_N) {
          return set_attribute_float3(sd->N, type, derivatives, val);
        }
        else if (name == u_Ng) {
          return set_attribute_float3(sd->Ng, type, derivatives, val);
        }
        else if (name == u_P) {
          float3 f[3] = {sd->P, sd->dP.dx, sd->dP.dy};
          return set_attribute_float3(f, type, derivatives, val);
        }
        else if (name == u_I) {
          float3 f[3] = {sd->I, sd->dI.dx, sd->dI.dy};
          return set_attribute_float3(f, type, derivatives, val);
        }
        else if (name == u_u) {
          float f[3] = {sd->u, sd->du.dx, sd->du.dy};
          return set_attribute_float(f, type, derivatives, val);
        }
        else if (name == u_v) {
          float f[3] = {sd->v, sd->dv.dx, sd->dv.dy};
          return set_attribute_float(f, type, derivatives, val);
        }

        return get_attribute(sd, derivatives, u_empty, type, name, val);
      }
    }
  }

  return false;
}
Пример #2
0
static bool get_primitive_attribute(KernelGlobals *kg,
                                    const ShaderData *sd,
                                    const OSLGlobals::Attribute &attr,
                                    const TypeDesc &type,
                                    bool derivatives,
                                    void *val)
{
  if (attr.type == TypeDesc::TypePoint || attr.type == TypeDesc::TypeVector ||
      attr.type == TypeDesc::TypeNormal || attr.type == TypeDesc::TypeColor) {
    float3 fval[3];
    fval[0] = primitive_attribute_float3(
        kg, sd, attr.desc, (derivatives) ? &fval[1] : NULL, (derivatives) ? &fval[2] : NULL);
    return set_attribute_float3(fval, type, derivatives, val);
  }
  else if (attr.type == TypeFloat2) {
    float2 fval[2];
    fval[0] = primitive_attribute_float2(
        kg, sd, attr.desc, (derivatives) ? &fval[1] : NULL, (derivatives) ? &fval[2] : NULL);
    return set_attribute_float2(fval, type, derivatives, val);
  }
  else if (attr.type == TypeDesc::TypeFloat) {
    float fval[3];
    fval[0] = primitive_attribute_float(
        kg, sd, attr.desc, (derivatives) ? &fval[1] : NULL, (derivatives) ? &fval[2] : NULL);
    return set_attribute_float(fval, type, derivatives, val);
  }
  else {
    return false;
  }
}
Пример #3
0
static bool set_attribute_float(float f, TypeDesc type, bool derivatives, void *val)
{
    float fv[3];

    fv[0] = f;
    fv[1] = 0.0f;
    fv[2] = 0.0f;

    return set_attribute_float(fv, type, derivatives, val);
}
Пример #4
0
bool OSLRenderServices::get_background_attribute(KernelGlobals *kg, ShaderData *sd, ustring name,
        TypeDesc type, bool derivatives, void *val)
{
    /* Ray Length */
    if (name == u_path_ray_length) {
        float f = sd->ray_length;
        return set_attribute_float(f, type, derivatives, val);
    }

    else
        return false;
}
Пример #5
0
bool OSLRenderServices::get_background_attribute(KernelGlobals *kg, ShaderData *sd, ustring name,
                                                 TypeDesc type, bool derivatives, void *val)
{
	if (name == u_path_ray_length) {
		/* Ray Length */
		float f = sd->ray_length;
		return set_attribute_float(f, type, derivatives, val);
	}
	else if (name == u_path_ray_depth) {
		/* Ray Depth */
		int f = sd->ray_depth;
		return set_attribute_int(f, type, derivatives, val);
	}
	else if (name == u_ndc) {
		/* NDC coordinates with special exception for otho */
		OSLThreadData *tdata = kg->osl_tdata;
		OSL::ShaderGlobals *globals = &tdata->globals;
		float3 ndc[3];

		if((globals->raytype & PATH_RAY_CAMERA) && sd->object == ~0 && kernel_data.cam.type == CAMERA_ORTHOGRAPHIC) {
			ndc[0] = camera_world_to_ndc(kg, sd, sd->ray_P);

			if(derivatives) {
				ndc[1] = camera_world_to_ndc(kg, sd, sd->ray_P + sd->ray_dP.dx) - ndc[0];
				ndc[2] = camera_world_to_ndc(kg, sd, sd->ray_P + sd->ray_dP.dy) - ndc[0];
			}
		}
		else {
			ndc[0] = camera_world_to_ndc(kg, sd, sd->P);

			if(derivatives) {
				ndc[1] = camera_world_to_ndc(kg, sd, sd->P + sd->dP.dx) - ndc[0];
				ndc[2] = camera_world_to_ndc(kg, sd, sd->P + sd->dP.dy) - ndc[0];
			}
		}

		return set_attribute_float3(ndc, type, derivatives, val);
	}
	else
		return false;
}
Пример #6
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;
}
Пример #7
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) {
		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) {