#0 

31-07-2010 00:41:06

narugohan
Abonné
Date d'inscription: 24-03-2009
Messages: 113

Bonjour à tous,
j'ai crée un shader cel-shading en GLSL, le voilà :

vertex_shader.vert   

Code:

varying vec3 Normal;
uniform mat4 mWorldViewProj;
uniform mat4 mInvWorld;
uniform mat4 mTransWorld;
uniform vec3 mLightPos;
uniform vec4 mLightColor;

void main(void)
{
    gl_FrontColor = gl_Color;
    Normal = gl_NormalMatrix * gl_Normal;
    gl_TexCoord[0] = gl_MultiTexCoord0;
    gl_Position = ftransform();
 
}

pixel_shader.frag

Code:

uniform vec3 mLightPos;
uniform vec4 mLightColor;
uniform sample    r2D Texture0;
 
varying vec3 Normal;

vec4 CelShading ( vec4 color )
{
    float Intensity = dot( mLightPos , normalize(Normal) );
    float factor = 0.8;
    if ( Intensity < 0.5 ) factor = 0.2;
        color *= vec4 ( factor, factor, factor, 1.0 );
 
    return color;
}

void main (void)
{
    vec4 color = texture2D( Texture0 , vec2( gl_TexCoord[0] ) );
 
    color = CelShading ( color );
 
    gl_FragColor = color;
}

CShaderPerso.h

Code:

namespace irr
{
namespace video
{


class CShaderPerso : public irr::video::IShaderConstantSetCallBack
{
      
private :
        IrrlichtDevice* m_device;

public:

    CShaderPerso( IrrlichtDevice* device )
    {
        m_device = device;
    }
    
    virtual void OnSetConstants(irr::video::IMaterialRendererServices* services, irr::s32 userData)
    {
        video::IVideoDriver* driver = services->getVideoDriver();

        core::matrix4 invWorld = driver->getTransform(video::ETS_WORLD);
        invWorld.makeInverse();
        services->setVertexShaderConstant("mInvWorld", invWorld.pointer(), 16);

        core::matrix4 worldViewProj;
        worldViewProj = driver->getTransform(video::ETS_PROJECTION);
        worldViewProj *= driver->getTransform(video::ETS_VIEW);
        worldViewProj *= driver->getTransform(video::ETS_WORLD);
        services->setVertexShaderConstant("mWorldViewProj", worldViewProj.pointer(), 16);

        core::vector3df pos = irr::core::vector3df(100,50,30);
        services->setVertexShaderConstant ( "mLightPos" , reinterpret_cast<f32*>( &pos ) , 3 );

        video::SColorf col(0.0f,1.0f,1.0f,0.0f);
        services->setVertexShaderConstant("mLightColor", reinterpret_cast<f32*>(&col), 4);

        core::matrix4 world = driver->getTransform(video::ETS_WORLD);
        world = world.getTransposed();
        services->setVertexShaderConstant("mTransWorld", world.pointer(), 16);

    }

};

}
}

Le problème est que la lumière suis la caméra, donc alors que je voudrais qu'elle reste à la position vector3df(100,50,30).
Quelqu'un pourrait m'aider svp, je ne comprend rien car pourtant je récupère bien les bonnes positions

Je vous remercie d'avance

Cordialement

Hors ligne


#1 

31-07-2010 19:23:50

firnafin
Abonné
Date d'inscription: 31-03-2007
Messages: 150

HLSL n'est pas ma tasse de thé , mais il se peut que les coordonnées (100,50,30) que tu passes au GPU soient pour lui considérées dans le repère de la camera , comme si la lumiere etait fils de la cam. Essaye de passer (100,50,30)  multipliée  par worldViewProj. Je propose ca car il me semble que pour le gpu tout les coordonnées sont données selon le "view".

Hors ligne


Options Liens officiels Caractéristiques Statistiques Communauté
Corrections
irrlicht
irrklang
irredit
irrxml
xhtml 1.0
css 2.1
Propulsé par FluxBB
Traduit par FluxBB.fr
881 membres
1427 sujets
11117 messages
Dernier membre inscrit: Bidule
20 invités en ligne
Aucun membre connecté
RSS Feed