Jump to content
  • Advertisement
Sign in to follow this  
maya18222

HLSL Texture sampler

This topic is 3834 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, I exported this from RenderMonkey using the export HLSL menu option, and below is what i got. but im wondering about the texture sample that was created.

texture MyTxr1_Tex
<
   string ResourceName = "D:\\Programming\\HLSL\\BOOK - Shaders\\Source_Code\\Chapter_4\\Fieldstone.tga";
>;

sampler Texture0 = sampler_state
{
   Texture = (MyTxr1_Tex);
};

this is what render monkey automatically wrote. But should it be like that? a directory to file? shouldn't it being a location in memory? I couldn't get the texture to display in anything else but render monkey and am wondering if this is the problem. Am i right in thinking you have to supply and extern to a D3DXTexture? and if so, what happens when you dont use a directx function to load your images? below is the whole file
//**************************************************************//
//  Effect File exported by RenderMonkey 1.6
//
//  - Although many improvements were made to RenderMonkey FX  
//    file export, there are still situations that may cause   
//    compilation problems once the file is exported, such as  
//    occasional naming conflicts for methods, since FX format 
//    does not support any notions of name spaces. You need to 
//    try to create workspaces in such a way as to minimize    
//    potential naming conflicts on export.                    
//    
//  - Note that to minimize resulting name collisions in the FX 
//    file, RenderMonkey will mangle names for passes, shaders  
//    and function names as necessary to reduce name conflicts. 
//**************************************************************//

//--------------------------------------------------------------//
// MyEffectGroup
//--------------------------------------------------------------//
//--------------------------------------------------------------//
// MyEffect
//--------------------------------------------------------------//
//--------------------------------------------------------------//
// Pass 0
//--------------------------------------------------------------//


float4x4 view_proj_matrix : WorldViewProj;

struct VS_OUTPUT 
{
   float4 Pos:     POSITION;
   float2 Txr1:    TEXCOORD0;
};

VS_OUTPUT MyEffectGroup_MyEffect_Pass_0_Vertex_Shader_vs_main( 
   float4 inPos: POSITION, 
   float2 Txr1: TEXCOORD0
)
{
   VS_OUTPUT Out;

   // Output our transformed and projected vertex
   // position and texture coordinate
   Out.Pos = mul(inPos, view_proj_matrix);
   Out.Txr1 = Txr1;

   return Out;
}


texture MyTxr1_Tex
<
   string ResourceName = "D:\\Programming\\HLSL\\BOOK - Shaders\\Source_Code\\Chapter_4\\Fieldstone.tga";
>;

sampler Texture0 = sampler_state
{
   Texture = (MyTxr1_Tex);
};




float4 MyEffectGroup_MyEffect_Pass_0_Pixel_Shader_ps_main( 
	float4 inDiffuse: COLOR0, 
	float2 inTxr1: TEXCOORD0
) : COLOR0
{
   //  Output the color taken from our texture
    float3 texColor = tex2D(Texture0,inTxr1).rgb;
    return float4(texColor, 1); 
}




//--------------------------------------------------------------//
// Technique Section for MyEffectGroup
//--------------------------------------------------------------//
technique MyEffect
{
   pass Pass_0
   {
      VertexShader = compile vs_1_1 MyEffectGroup_MyEffect_Pass_0_Vertex_Shader_vs_main();
      PixelShader = compile ps_2_0 MyEffectGroup_MyEffect_Pass_0_Pixel_Shader_ps_main();
   }

}


Share this post


Link to post
Share on other sites
Advertisement
Your assumption is correct. You need something like:

// in your shader=============
texture g_txScene : TEXTURE; // texture for scene rendering

//-----------------------------------------------------------------------------
// Texture samplers
//-----------------------------------------------------------------------------
sampler tree0 =
sampler_state
{
Texture = <g_txScene>;
MinFilter = Linear;
MagFilter = Linear;
MipFilter = Linear;
};


// in your .cpp =================
// where tree3 is LPDIRECT3DTEXTURE9 or equivalent
g_pEffect->SetTexture("g_txScene",tree3);

And it's loading LPDIRECT3DTEXTURE9 (or equivalent) where you'll use the filepath.

Share this post


Link to post
Share on other sites
Annotations for textures or any other HLSL type don't do anything on their own, they're just extra information embedded in the effect file. When you load the effect in your app it won't load that texture from the file or anything like that, you'd have to manually query that annotation and then use the filename to load the texture. However having a texture filename in an effect isn't particularly useful for most cases, since it's very likely you'll be using the same effect with many different textures. So in that case you can just remove the annotation completely.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!