Historique des modifications - Message

Message #9041

Sujet: [glow] enfin trouver mais bug


Type Date Auteur Contenu
Dernière modification 05-12-2010 21:11:29 kiricou974
Bonjours voila j'ai enfin trouver un shader de glow.

seul probleme j'arrive pas a l'utiliser mais le shader et fonctionel et mon code aussi ...

voila le shader et ma fonction de callback

shader.frag

Code c++ :


uniform float strength;
uniform vec4 coronaDir;
uniform vec4 view_direction;
uniform sampler2D GlowTex;
uniform float coronaExp;
uniform vec4 lightColor;
uniform float constAtt;
uniform float sqrAtt;
 
// input variables from Vertex Program.
varying vec2 vTexCoord;
 
float saturate( float inValue)
{
   return clamp( inValue, 0.0, 1.0);
}
 
void main(void)
{
   
   vec4 corona  = texture2D(GlowTex, vTexCoord);
   // view directoin is set up for the handedness, we need to flip it for ogl.
   vec3 vdir    = vec3(view_direction.x, view_direction.y, view_direction.z);
   vec3 cdir    = vec3(coronaDir.x, coronaDir.y, coronaDir.z);
 
   // Glow depending on cosine (dotprod) with "corona directon"
   float glow   = saturate(dot(vdir, cdir));
 
   gl_FragColor = strength * pow(glow, coronaExp) * corona * lightColor;  
}


shader.vert

Code c++ :


uniform vec4 pos0;         // location of screen aligned quad
uniform float coronaSize;  // size of screen aligned quad (currently 16.0)
 
// output variables for Fragment Program.
varying vec2 vTexCoord;
 
void main(void)
{
       
   // Grab X and Y eye-space vectors in world-space ...
   
   // NOTE: OpenGL stores matrixes as column major, DirectX stores then row major.
   //       So here, we need to extract the rows we need...the D3D version of this
   //       shader is a touch simplier.
   vec3 dirX = vec3(
                    gl_ModelViewMatrix[0][0],
                    gl_ModelViewMatrix[1][0],
                    gl_ModelViewMatrix[2][0]
                   );
   vec3 dirY = vec3(
                    gl_ModelViewMatrix[0][1],
                    gl_ModelViewMatrix[1][1],
                    gl_ModelViewMatrix[2][1]
                   );
 
   // ... which are used for billboarding
   vec3 pos    = vec3(pos0) + coronaSize * (gl_Vertex.x * dirX + gl_Vertex.y * dirY );
   
   gl_Position = gl_ModelViewProjectionMatrix * vec4(pos,1.0);
   
   vTexCoord   = 0.5 * gl_Vertex.xy + 0.5;
 
   
}


et ma function de callback

Code c++ :


class MyShaderCallBack : public video::IShaderConstantSetCallBack
{
	public :


		MyShaderCallBack ( IrrlichtDevice* _device )
		{
			device = _device;
		}


        virtual void OnSetConstants ( video::IMaterialRendererServices* services , s32 userData )
        {

                video::IVideoDriver* driver = services->getVideoDriver();

                float st = 20;
                services->setVertexShaderConstant("strength", (const float*)&st, 1);

                float st1 = 4;
                services->setVertexShaderConstant("coronaSize", (const float*)&st1, 1);

                // Set camera position
                core::vector3df pos = core::vector3df (-1,0,0);
                services->setVertexShaderConstant ( "coronaDir" , reinterpret_cast<f32*>( &pos ) , 3 );


                // Set camera position
                core::vector3df pos1 = device->getSceneManager()->getActiveCamera()->getPosition();
                services->setVertexShaderConstant ( "view_direction" , reinterpret_cast<f32*>( &pos1 ) , 3 );


                float st2 = 2;
                services->setVertexShaderConstant("coronaExp", (const float*)&st2, 1);


                float st3 = 1;
                services->setVertexShaderConstant("constAtt", (const float*)&st3, 1);

                float st4 = 1;
                services->setVertexShaderConstant("sqrAtt", (const float*)&st4, 1);

                // Set light color
                video::SColorf col(0.0f,255,255,0.0f);
                services->setVertexShaderConstant("lightColor", reinterpret_cast<f32*>(&col), 4);

                //Set pos to glow
                core::vector3df pos11 = core::vector3df (0,0,0);
                services->setVertexShaderConstant ( "pos0" , reinterpret_cast<f32*>( &pos11 ) , 3 );

				// set textures
			    int a = 0;services->setPixelShaderConstant("GlowTex", (f32 *)(&a), 0);
        }

	private :

		IrrlichtDevice* device;
};


et il m'affiche seulement un carrer noir orienter selon la camera.

Merci de bien vouloir essayer le shader pour voir si il a un bug ou pas chez vous
Création du message 05-12-2010 21:06:31 kiricou974
Bonjours voila j'ai enfin trouver un shader de glow.

seul probleme j'arrive pas a l'utiliser mais le shader et fonctionel et mon code aussi ...

voila le shader et ma fonction de callback

shader.frag

Code c++ :


uniform float strength;
uniform vec4 coronaDir;
uniform vec4 view_direction;
uniform sampler2D GlowTex;
uniform float coronaExp;
uniform vec4 lightColor;
uniform float constAtt;
uniform float sqrAtt;
 
// input variables from Vertex Program.
varying vec2 vTexCoord;
 
float saturate( float inValue)
{
   return clamp( inValue, 0.0, 1.0);
}
 
void main(void)
{
   
   vec4 corona  = texture2D(GlowTex, vTexCoord);
   // view directoin is set up for the handedness, we need to flip it for ogl.
   vec3 vdir    = vec3(view_direction.x, view_direction.y, view_direction.z);
   vec3 cdir    = vec3(coronaDir.x, coronaDir.y, coronaDir.z);
 
   // Glow depending on cosine (dotprod) with "corona directon"
   float glow   = saturate(dot(vdir, cdir));
 
   gl_FragColor = strength * pow(glow, coronaExp) * corona * lightColor;  
}


shader.vert

Code c++ :


uniform vec4 pos0;         // location of screen aligned quad
uniform float coronaSize;  // size of screen aligned quad (currently 16.0)
 
// output variables for Fragment Program.
varying vec2 vTexCoord;
 
void main(void)
{
       
   // Grab X and Y eye-space vectors in world-space ...
   
   // NOTE: OpenGL stores matrixes as column major, DirectX stores then row major.
   //       So here, we need to extract the rows we need...the D3D version of this
   //       shader is a touch simplier.
   vec3 dirX = vec3(
                    gl_ModelViewMatrix[0][0],
                    gl_ModelViewMatrix[1][0],
                    gl_ModelViewMatrix[2][0]
                   );
   vec3 dirY = vec3(
                    gl_ModelViewMatrix[0][1],
                    gl_ModelViewMatrix[1][1],
                    gl_ModelViewMatrix[2][1]
                   );
 
   // ... which are used for billboarding
   vec3 pos    = vec3(pos0) + coronaSize * (gl_Vertex.x * dirX + gl_Vertex.y * dirY );
   
   gl_Position = gl_ModelViewProjectionMatrix * vec4(pos,1.0);
   
   vTexCoord   = 0.5 * gl_Vertex.xy + 0.5;
 
   
}


et ma function de callback

Code c++ :


class MyShaderCallBack : public video::IShaderConstantSetCallBack
{
	public :


		MyShaderCallBack ( IrrlichtDevice* _device )
		{
			device = _device;
		}


        virtual void OnSetConstants ( video::IMaterialRendererServices* services , s32 userData )
        {

                video::IVideoDriver* driver = services->getVideoDriver();

                float st = 20;
                services->setVertexShaderConstant("strength", (const float*)&st, 1);

                float st1 = 4;
                services->setVertexShaderConstant("coronaSize", (const float*)&st1, 1);

                // Set camera position
                core::vector3df pos = core::vector3df (-1,0,0);
                services->setVertexShaderConstant ( "coronaDir" , reinterpret_cast<f32*>( &pos ) , 3 );


                // Set camera position
                core::vector3df pos1 = device->getSceneManager()->getActiveCamera()->getPosition();
                services->setVertexShaderConstant ( "view_direction" , reinterpret_cast<f32*>( &pos1 ) , 3 );


                float st2 = 2;
                services->setVertexShaderConstant("coronaExp", (const float*)&st2, 1);


                float st3 = 1;
                services->setVertexShaderConstant("constAtt", (const float*)&st3, 1);

                float st4 = 1;
                services->setVertexShaderConstant("sqrAtt", (const float*)&st4, 1);

                // Set light color
                video::SColorf col(0.0f,255,255,0.0f);
                services->setVertexShaderConstant("lightColor", reinterpret_cast<f32*>(&col), 4);

                //Set pos to glow
                core::vector3df pos11 = core::vector3df (0,0,0);
                services->setVertexShaderConstant ( "pos0" , reinterpret_cast<f32*>( &pos11 ) , 3 );

				// set textures
			    int a = 0;services->setPixelShaderConstant("GlowTex", (f32 *)(&a), 0);
        }

	private :

		IrrlichtDevice* device;
};


et il m'affiche seulement un carrer noir orienter selon la camera.

Merci de bien vouloir essayer le shader pour voir si il a un bug ou pas chez vous

Retour

Options Liens officiels Caractéristiques Statistiques Communauté
Préférences cookies
Corrections
irrlicht
irrklang
irredit
irrxml
Propulsé par Django
xhtml 1.0
css 2.1
884 membres
1440 sujets
11337 messages
Dernier membre inscrit: Saidov17
228 invités en ligne
membre en ligne: -
RSS Feed