Jump to content
  • Advertisement
Sign in to follow this  
dawchiks

me again! textureing in HLSL. wtf?

This topic is 3617 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 there! for past 3 days im learning hlsl. and i stopped at texturing in hlsl. I've done all what is needed, have the same .fx file as in tutorial, i've been trying to texture that fu***** teapot for 5 hours! But the object is just black! i Downloaded the tutorial, and as much as I saw everything is how it should be. float4x4 worldViewProj; float4 world; float3 lightDir = {-2.0f,5.0f,-.5f}; texture texture0; sampler texSampler = sampler_state { texture = <texture0>; }; struct VS_IN { float4 Position : POSITION; float2 Tex : TEXCOORD0; float3 Normal : NORMAL; }; struct VS_OUTPUT { float4 Position : POSITION; float2 Tex : TEXCOORD0; float3 Light : TEXCOORD1; float3 Normal : TEXCOORD2; }; VS_OUTPUT VS(VS_IN In) { VS_OUTPUT Out = (VS_OUTPUT) 0; Out.Position = mul(In.Position, worldViewProj); Out.Tex = In.Tex.xy; Out.Light = normalize(lightDir); Out.Normal = normalize(mul(In.Normal, world)); return Out; } float4 PS(VS_OUTPUT In) : COLOR { float4 Diffuse = tex2D(texSampler,In.Tex); float Diff = saturate(dot(In.Normal, In.Light)); return Diffuse * Diff; } technique test { pass p0 { vertexshader = compile vs_2_0 VS(); pixelshader = compile ps_2_0 PS(); } } and i use these: Effect->SetMatrix("worldViewProj",&matWVP); Effect->SetMatrix("world",&world); Effect->SetTexture("texture0",tex0); Effect->SetTechnique("test") D3DXCreateEffectFromFile(d3dDev,"fx/test.fx",NULL,NULL,NULL,NULL,&Effect,NULL); D3DXCreateTextureFromFile(d3dDev,"test.bmp",&tex0); help guys. :)

Share this post


Link to post
Share on other sites
Advertisement
If it's black it could be the lighting is not working.
Try returning just the Diffuse from the pixel shader.

If that doesn't work, check the UVs are valid, ie in the 0 to 1 range.

Also try turning on the debug runtimes in the DX control panel, and bump up the debug output level. This will print any warnings in the output window.

Share this post


Link to post
Share on other sites
This would be a perfect opportunity for you to explore the wonderful world of shader debugging wouldn't it? [wink]

Check out PIX for Windows as well as doing some traditional printf-style debugging. Output just the diffuse, or other intermediaries as RabidDog suggested - basic sanity check to see if they contain the numbers you're expecting.

I'd pay particular attention to your light direction. Remember you want the from fragment/vertex to light vector. It's a subtle difference, but very easy to muddle that up given that its conventional to specify a light direction as being from the source...

hth
Jack

Share this post


Link to post
Share on other sites
id Dx panel i cant select any of them. both release and debug ar just grey;
omfg u were right. its all about lighting. without textures lighting is working!
now what to do to get lighting back? hmm. :thx btw :)

Share this post


Link to post
Share on other sites
The default D3DX teapot mesh does not have texture coordinates; if this is the case, since the shader imposes a default value of 0.0f to most missing/undefined values, your texture gets sampled from [0,0] on every pixel.

Further, you assign the texture interface pointer to your effect before you actually obtain the said pointer by calling D3DXCreateTextureFromFile. This is doomed to fail, because before successful creation call, the pointer will be either 0 (which stands for "no texture") or a random value (which can cause access violation in D3D and/or GPU).

EDIT: Just multiply the sampled texture value with the diffuse color.

Share this post


Link to post
Share on other sites
nah its 3ds max exported teapot. and does it has to be like that if object already is textured it will show its texture not the texture i try to apply to it by HLSL? cuz the teapot has Wooden texture what i set as material in 3ds max, and i try to apply other tex. on untextured models i see that tex which i load in VC++;

Share this post


Link to post
Share on other sites
Quote:
Original post by dawchiks
and does it has to be like that if object already is textured it will show its texture not the texture i try to apply to it by HLSL?


This is not apparent from the code that you have shown, but yes, if you have a texture set in the effect already, it will work also.

Share this post


Link to post
Share on other sites
ok i can texture object, but now i cant add lighting.

edit: done ; textured and lighted;

i just added Diffuse2 where Diffuse is texture, and Diffuse2 is color;
then I return this :
return (Diffuse + Diffuse2) * Diff;

and all works :D

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!