예제 #1
0
파일: Shader.cpp 프로젝트: fudy1129/kvs
/*===========================================================================*/
const kvs::RGBColor Shader::Lambert::shadedColor(
    const kvs::RGBColor& color,
    const kvs::Vector3f& vertex,
    const kvs::Vector3f& normal ) const
{
    // Light vector L and normal vector N.
    const kvs::Vector3f L = ( light_position - vertex ).normalized();
    const kvs::Vector3f N = normal.normalized();

    // Intensity values.
    const float Ia = kvsShaderAmbientTerm( Ka );
    const float Id = kvsShaderDiffuseTerm( Kd, N, L );

    return color * ( Ia + Id );
}
예제 #2
0
파일: Shader.cpp 프로젝트: fudy1129/kvs
/*===========================================================================*/
const kvs::RGBColor Shader::BlinnPhong::shadedColor(
    const kvs::RGBColor& color,
    const kvs::Vector3f& vertex,
    const kvs::Vector3f& normal ) const
{
    // Camera vector V, light vector L, halfway vector H and normal vector N.
    const kvs::Vector3f V = ( camera_position - vertex ).normalized();
    const kvs::Vector3f L = ( light_position - vertex ).normalized();
    const kvs::Vector3f H = ( V + L ).normalized();
    const kvs::Vector3f N = normal.normalized();

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

    return ::Shade( color, Ia, Id, Is );
}
예제 #3
0
파일: Shader.cpp 프로젝트: fudy1129/kvs
/*===========================================================================*/
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 );
}
예제 #4
0
파일: Shader.cpp 프로젝트: fudy1129/kvs
/*==========================================================================*/
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;
}
예제 #5
0
파일: Shader.cpp 프로젝트: fudy1129/kvs
/*==========================================================================*/
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;
}
예제 #6
0
파일: Shader.cpp 프로젝트: fudy1129/kvs
/*==========================================================================*/
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;
}