Jump to content
  • Advertisement
Sign in to follow this  
renanrosa

Light in Texture with Texture Blending FX File (applicachia.com of the Chris)

This topic is 2982 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi guys, ... I have this effect file:
//////////////////
// File: TextureBlending.fx
// Author: Chris Smith
//////////////////

float4x4 	worldViewProj;
float 	 	UVMapTerra1;
float 	 	UVMapGrama1;
float 	 	UVMapAgua1;

texture 	texturaTerra1;
texture 	texturaGrama1;
texture 	texturaAgua1;
texture 	blendmapTexture;

float3 LightDir = float3(1,1,1);

sampler2D texturaTerra1Sampler = sampler_state
{

    Texture = (texturaTerra1);
    MIPFILTER = LINEAR;
    MAGFILTER = LINEAR;
    MINFILTER = LINEAR;
};

sampler2D texturaGrama1Sampler = sampler_state
{
    Texture = (texturaGrama1);
    MIPFILTER = LINEAR;
    MAGFILTER = LINEAR;
    MINFILTER = LINEAR;
};

sampler2D texturaAgua1Sampler = sampler_state
{
    Texture = (texturaAgua1);
    MIPFILTER = LINEAR;
    MAGFILTER = LINEAR;
    MINFILTER = LINEAR;
};

sampler2D blendmapTextureSampler = sampler_state
{
    Texture = (blendmapTexture);
    MIPFILTER = LINEAR;
    MAGFILTER = LINEAR;
    MINFILTER = LINEAR;
};

struct A2V
{ 
    float4 position : POSITION0;
    float2 texCoord : TEXCOORD0;
	float3 Normal   : NORMAL0;
};

struct V2P
{
    float4 position  		: POSITION0;
    float2 texCoordTerra1  	: TEXCOORD0;
    float2 texCoordGrama1 	: TEXCOORD1;
	float2 texCoordAgua1	: TEXCOORD2;
    float2 texCoordBlendMap : TEXCOORD3;
	float3 Normal           : TEXCOORD4;
};

void VS( in A2V IN, out V2P OUT) 
{
    OUT.position  			= 	mul(IN.position, worldViewProj);
    OUT.texCoordTerra1  	= 	IN.texCoord*UVMapTerra1;
    OUT.texCoordGrama1 		= 	IN.texCoord*UVMapGrama1;
	OUT.texCoordAgua1 		= 	IN.texCoord*UVMapAgua1;
    OUT.texCoordBlendMap 	= 	IN.texCoord;
	OUT.Normal              =   IN.Normal;
}

vector PS( in V2P IN) : COLOR
{
	
    vector TexColorTerra1 	= tex2D( texturaTerra1Sampler, IN.texCoordTerra1 );
    vector TexColorGrama1 	= tex2D( texturaGrama1Sampler, IN.texCoordGrama1 );
	vector TexColorAgua1 	= tex2D( texturaAgua1Sampler,  IN.texCoordAgua1 );
	
    vector BlendMap  		= tex2D( blendmapTextureSampler, IN.texCoordBlendMap );
    
	float DotNL = saturate(dot(IN.Normal, normalize(LightDir)));
	float4 Color = (TexColorTerra1 * BlendMap.r) + (TexColorGrama1 * BlendMap.g) + (TexColorAgua1 * BlendMap.b);
	return Color * DotNL;
}


technique TexBlend
{
	
    pass p0
    {		
        vertexshader = compile vs_2_0 VS();
		pixelshader = compile ps_2_0 PS();
		
    }
}

and 1 mesh .x file (terrain), and i set the effect:
TexBlendEffectMapa1->SetTechnique( "TexBlend" );
	TexBlendEffectMapa1->SetMatrix( "worldViewProj", &(ObjCamera->getMatrixTempWorld() * ObjCamera->getMatrixView() * ObjCamera->getMatrixTempProj() ) );
	TexBlendEffectMapa1->SetTexture( "texturaTerra1", texturaTerra1 );
	TexBlendEffectMapa1->SetTexture( "texturaGrama1", texturaGrama1 );
	TexBlendEffectMapa1->SetTexture( "texturaAgua1", texturaAgua1 );
	TexBlendEffectMapa1->SetTexture( "blendmapTexture", BlendTextureMapa1 );
	TexBlendEffectMapa1->SetFloat( "UVMapTerra1", 16 );
	TexBlendEffectMapa1->SetFloat( "UVMapGrama1", 16 ); // 80 lol
	TexBlendEffectMapa1->SetFloat( "UVMapAgua1", 16 );
	
	//começa a passar o shader
	UINT Pass, Passes;
	TexBlendEffectMapa1->Begin(&Passes, 0);
	
	for (Pass = 0; Pass < Passes; Pass++)
	{
		TexBlendEffectMapa1->BeginPass(Pass);
		MeshTerrain->DrawSubset(0);
		TexBlendEffectMapa1->EndPass();
	}
	
	TexBlendEffectMapa1->End();


but when I set light (D3DLIGHT9) the light did not appear. What do I need to do? how i set the light (enabled light)? without this effect the light appear :( help me thank guys :)

Share this post


Link to post
Share on other sites
Advertisement
If you're using vertex and pixel shaders, then you can't use fixed-function lighting. You either have to use one or the other.

Those shaders you're using have some sort of lighting built-in, using the "LightDir" parameter. You should set that if you want to change the direction of the light source, or add some more parameters if you want to control things like the light color.

Share this post


Link to post
Share on other sites
Quote:
Original post by MJP
If you're using vertex and pixel shaders, then you can't use fixed-function lighting. You either have to use one or the other.

Those shaders you're using have some sort of lighting built-in, using the "LightDir" parameter. You should set that if you want to change the direction of the light source, or add some more parameters if you want to control things like the light color.


thank for answer :)
but... how do this? :$

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!