Exemple #1
0
/*==========================================================================*/
inline float Shader::Phong::attenuation( const kvs::Vector3f& vertex, const kvs::Vector3f& gradient ) const
{
    // Light vector L, normal vector N and reflection vector R.
    const kvs::Vector3f L = ( light_position - vertex ).normalized();
    const kvs::Vector3f N = gradient.normalized();
    const kvs::Vector3f R = 2.0f * N.dot( L ) * N - L;

    const float dd = Math::Max( N.dot( L ), 0.0f );
    const float ds = Math::Max( N.dot( R ), 0.0f );

    /* I = Ia + Id + Is
     *
     * Is = Ip * Ks * cos^s(B) = Ip * Ks * ( R dot N )^s
     */
    const float Ia = Ka;
    const float Id = Kd * dd;
    const float Is = Ks * std::pow( ds, S );

    return Ia + Id + Is;
}
Exemple #2
0
/*===========================================================================*/
const kvs::RGBColor Shader::Phong::shadedColor(
    const kvs::RGBColor& color,
    const kvs::Vector3f& vertex,
    const kvs::Vector3f& normal ) const
{
    // Light vector L, normal vector N and reflection vector R.
    const kvs::Vector3f V = ( camera_position - vertex ).normalized();
    const kvs::Vector3f L = ( light_position - vertex ).normalized();
    const kvs::Vector3f N = normal.normalized();
    const kvs::Vector3f R = 2.0f * N.dot( L ) * N - L;

    // Intensity values.
    const float Ia = kvsShaderAmbientTerm( Ka );
    const float Id = kvsShaderDiffuseTerm( Kd, N, L );
    const float Is = kvsShaderSpecularTerm( ks, S, R, V );

    return ::Shade( color, Ia, Id, Is );
}
Exemple #3
0
/*==========================================================================*/
inline float Shader::Lambert::attenuation( const kvs::Vector3f& vertex, const kvs::Vector3f& gradient ) const
{
    // Light vector L and normal vector N.
    const kvs::Vector3f L = ( light_position - vertex ).normalized();
    const kvs::Vector3f N = gradient.normalized();

    const float dd = kvs::Math::Max( N.dot( L ), 0.0f );

    /* I = Ia + Id
     *
     * Ia = Ka (constant term)
     * Id = Ip *  Kd * cos(A) = Ip * Kd * ( L dot N )
     *
     * Ip : the intensity emitted from the light source.
     */
    const float Ia = Ka;
    const float Id = Kd * dd;

    return Ia + Id;
}
Exemple #4
0
/*==========================================================================*/
inline float Shader::BlinnPhong::attenuation( const kvs::Vector3f& vertex, const kvs::Vector3f& gradient ) const
{
    // Camera vector C, light vector L, halfway vector H and normal vector N.
    const kvs::Vector3f C = ( camera_position - vertex ).normalized();
    const kvs::Vector3f L = ( light_position - vertex ).normalized();
    const kvs::Vector3f H = ( C + L ).normalized();
    const kvs::Vector3f N = gradient.normalized();

    const float dd = kvs::Math::Max( N.dot( L ), 0.0f );
    const float ds = kvs::Math::Max( N.dot( H ), 0.0f );

    /* I = Ia + Id + Is
     *
     * Is = Ip * Ks * cos^s(B) = Ip * Ks * ( H dot N )^s
     */
    const float Ia = Ka;
    const float Id = Kd * dd;
    const float Is = Ks * ::pow( ds, S );

    return Ia + Id + Is;
}