Historique des modifications - Message

Message #10849

Sujet: Avoir la main verte


Type Date Auteur Contenu
Dernière modification 17-10-2012 06:59:09 johnplayer
J'ai trouvé! Moi aussi j'avais un probleme avec la variable alpha, il me disait qu'elle n'était pas affecté mais pourtant ça marchait correctement quand même. Voilà le correctif:
Le nouveau "dx.hlsl"
uniform float4x4 mWorldViewProj;

// Vertex shader output structure
struct VS_OUTPUT
{
	float4 Position  : POSITION;   // vertex position 
	float2 TexCoord0 : TEXCOORD0;  // tex 0 coords
};


VS_OUTPUT vertexMain( in float4 vPosition : POSITION, float2 texCoord0 : TEXCOORD0 )
{
	VS_OUTPUT Output;
	
	Output.Position = mul(vPosition, mWorldViewProj);
	Output.TexCoord0 = texCoord0;
	
	return Output;
}



uniform sampler2D texsol : register(s0);
uniform sampler2D texherbe : register(s1);
uniform float alpha_herbe;
	
// Pixel shader output structure
struct PS_OUTPUT
{
    float4 RGBColor : COLOR0;  // Pixel color    
};
	
PS_OUTPUT pixelMain( VS_OUTPUT Input ) 
{ 
    PS_OUTPUT Output;
		
    float4 col0 = tex2D(texsol, Input.TexCoord0);
    float4 col1 = tex2D(texherbe, Input.TexCoord0); 
	
    float alphafinal = alpha_herbe * col1.a;
	
    Output.RGBColor.rgb = col0.rgb*(1.f-alphafinal) + col1.rgb*alphafinal;
    Output.RGBColor.a = col0.a;

		
    return Output;
	
}

NOTE : j'ai modifié le calcul de la couleur dans le cas que tu voudrais un hexagone transparent. La transparence de l'hexagone est générée par la valeur alpha de la texture 0.

Le nouveau "OnsetConstants()"
	virtual void OnSetConstants(IMaterialRendererServices* services, s32 userData)
	{
	    // on récupère un pointeur sur VideoDriver
        IVideoDriver* driver = services->getVideoDriver();

        // Matrice WorldViewProj
        core::matrix4 mWorldViewProj;
        mWorldViewProj = driver->getTransform(ETS_PROJECTION);
        mWorldViewProj *= driver->getTransform(ETS_VIEW);
        mWorldViewProj *= driver->getTransform(ETS_WORLD);
        // on l'envoie au GPU
        services->setVertexShaderConstant("mWorldViewProj", mWorldViewProj.pointer(), 16);

        // On envoie la valeur alpha_herbe au GPU
        services->setPixelShaderConstant("alpha_herbe", &alpha_herbe, 1);

    }

Voici un lien vers une nouvelle archive. Elle contient le nouveau shader et le callback qui va avec:
lien
Création du message 17-10-2012 06:44:07 johnplayer
J'ai trouvé! Moi aussi j'avais un probleme avec la variable alpha, il me disait qu'elle n'était pas affecté mais pourtant ça marchait correctement quand même. Voilà le correctif:
Le nouveau "dx.hlsl"
uniform float4x4 mWorldViewProj;

// Vertex shader output structure
struct VS_OUTPUT
{
	float4 Position  : POSITION;   // vertex position 
	float2 TexCoord0 : TEXCOORD0;  // tex 0 coords
};


VS_OUTPUT vertexMain( in float4 vPosition : POSITION, float2 texCoord0 : TEXCOORD0 )
{
	VS_OUTPUT Output;
	
	Output.Position = mul(vPosition, mWorldViewProj);
	Output.TexCoord0 = texCoord0;
	
	return Output;
}



uniform sampler2D texsol : register(s0);
uniform sampler2D texherbe : register(s1);
uniform float alpha_herbe;
	
// Pixel shader output structure
struct PS_OUTPUT
{
    float4 RGBColor : COLOR0;  // Pixel color    
};
	
PS_OUTPUT pixelMain( VS_OUTPUT Input ) 
{ 
    PS_OUTPUT Output;
		
    float4 col0 = tex2D(texsol, Input.TexCoord0);
    float4 col1 = tex2D(texherbe, Input.TexCoord0); 
	
    float alphafinal = alpha_herbe * col1.a;
	
    Output.RGBColor.rgb = col0.rgb*(1.f-alphafinal) + col1.rgb*alphafinal;
    Output.RGBColor.a = col0.a;

		
    return Output;
	
}

NOTE : j'ai modifié le calcul de la couleur dans le cas que tu voudrais un hexagone transparent. La transparence de l'hexagone est générée par la valeur alpha de la texture 0.

Le nouveau "OnsetConstants()"
	virtual void OnSetConstants(IMaterialRendererServices* services, s32 userData)
	{
	    // on récupère un pointeur sur VideoDriver
        IVideoDriver* driver = services->getVideoDriver();

        // Matrice WorldViewProj
        core::matrix4 mWorldViewProj;
        mWorldViewProj = driver->getTransform(ETS_PROJECTION);
        mWorldViewProj *= driver->getTransform(ETS_VIEW);
        mWorldViewProj *= driver->getTransform(ETS_WORLD);
        // on l'envoie au GPU
        services->setVertexShaderConstant("mWorldViewProj", mWorldViewProj.pointer(), 16);

        // On envoie la valeur alpha_herbe au GPU
        services->setPixelShaderConstant("alpha_herbe", &alpha_herbe, 1);

    }

Voici un lien vers une nouvelle archive. Elle contient le nouveau shader et le callback qui va avec:
lien

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
150 invités en ligne
membre en ligne: -
RSS Feed