You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Christi258
Posts: 62 Joined: Wed Feb 06, 2013 12:11 pm
Post
by Christi258 » Thu Apr 10, 2014 12:52 pm
Hi all,
I have a problem with my Vertex Shader. I want to read out a texture in the vertex shader. The only available funktion is tex2Dlod (
http://msdn.microsoft.com/en-us/library ... 85%29.aspx ).
I use it this way:
Code: Select all
float4x4 ViewProj;
float4x4 World;
sampler2D HMap;
struct VS_INPUT
{
float4 pos : POSITION;
float3 Normal : NORMAL0;
float2 tex : TEXCOORD0;
};
VS_OUTPUT vMain( VS_INPUT inp )
{
VS_OUTPUT outp;
outp.tex = inp.tex;
outp.pos = mul( inp.pos, World);
outp.pos.y += tex2Dlod( HMap, float4(inp.tex.xy, 0.0, 0.0) ).g * 20;
outp.pos = mul( outp.pos, ViewProj);
return outp;
}
But it always returns 0.
What goes wrong?
Granyte
Posts: 849 Joined: Tue Jan 25, 2011 11:07 pm
Contact:
Post
by Granyte » Fri Apr 11, 2014 12:56 am
Wich version of irrlicht are you using ? And to wich texture layer are you sending your texture to?
Vertex texture are a 1.8 feature for dx
Christi258
Posts: 62 Joined: Wed Feb 06, 2013 12:11 pm
Post
by Christi258 » Fri Apr 11, 2014 11:35 am
I use irrlicht 1.8.1
loading the texture:
Code: Select all
IMeshSceneNode *node = smgr->addMeshSceneNode(mesh);
ITexture *tex = driver->getTexture("noise.bmp");
node->setMaterialTexture(0, tex);
IShaderConstantSetCallBack:
Code: Select all
s32 TextureLayerID = 0;
services->setVertexShaderConstant("HMap", &TextureLayerID, 1);
Granyte
Posts: 849 Joined: Tue Jan 25, 2011 11:07 pm
Contact:
Post
by Granyte » Fri Apr 11, 2014 3:49 pm
If you are using dx the setVertexShaderConstant is not necessary and could even be what is causing the issue
and to what vertex shader version do you compile?
Christi258
Posts: 62 Joined: Wed Feb 06, 2013 12:11 pm
Post
by Christi258 » Sat Apr 12, 2014 11:04 am
I compile in 3.0. (The first version that supports tex2Dlod()).
But even if I comment out the setVertexShaderConstant the tex2Dlod returns 0.
Granyte
Posts: 849 Joined: Tue Jan 25, 2011 11:07 pm
Contact:
Post
by Granyte » Sat Apr 12, 2014 5:05 pm
That is odd what texture format and what gpu are you using some older gpu did not support all texture format in vertex shader
After that ill need to write a test app
Christi258
Posts: 62 Joined: Wed Feb 06, 2013 12:11 pm
Post
by Christi258 » Sun Apr 13, 2014 6:39 pm
Color Format is ECF_A8R8G8B8 it has a size of 512x512 pixels.
Graphic card: NVIDIA GeForce GTX 560 Ti
hendu
Posts: 2600 Joined: Sat Dec 18, 2010 12:53 pm
Post
by hendu » Sun Apr 13, 2014 8:05 pm
Do you absolutely require DX? It works fine in GL
Christi258
Posts: 62 Joined: Wed Feb 06, 2013 12:11 pm
Post
by Christi258 » Sun Apr 13, 2014 8:22 pm
That's one possibility, but I rather would know, where the problem lays.
Granyte
Posts: 849 Joined: Tue Jan 25, 2011 11:07 pm
Contact:
Post
by Granyte » Sun Apr 13, 2014 11:17 pm
Alright i suggest you post the entire code to the test app and the texture.
vertex texture works fine in dx9 but i have been the only one using them
Granyte
Posts: 849 Joined: Tue Jan 25, 2011 11:07 pm
Contact:
Post
by Granyte » Wed Apr 16, 2014 12:45 am
I suspected this but I really needed to get home and compile to test
You need to compile the pixel shader to PS 3.0 when using VS 3.0
so change
s32 material = gpuPS->addHighLevelShaderMaterialFromFiles( "shader.hlsl", "vMain", EVST_VS_3_0,
"shader.hlsl", "pMain", EPST_PS_2_0, callback);
to
s32 material = gpuPS->addHighLevelShaderMaterialFromFiles( "shader.hlsl", "vMain", EVST_VS_3_0,
"shader.hlsl", "pMain", EPST_PS_3_0, callback);
and it works fine
Christi258
Posts: 62 Joined: Wed Feb 06, 2013 12:11 pm
Post
by Christi258 » Wed Apr 16, 2014 7:43 am
Sorry, but no.
Is the problem my graphic card?
Granyte
Posts: 849 Joined: Tue Jan 25, 2011 11:07 pm
Contact:
Post
by Granyte » Wed Apr 16, 2014 8:09 am
do you see nothing when moving toward the light?
not even the light at all?
because currently you appear under the mesh and you need to move toward the light until it appear
you gpu should be more then capable of handeling this a 560 ti is a dx11 capable gpu so unless NVidia torched their dx9 support and ran there should be no issue at all
the last thing I can think of is that I compiled against the trunk because I was to lasy to dig my 1.8.0 coppy so ill cheq if it works when compiled against 1.8 and 1.8.1
this is the version I got to work it require vc redistributable 2012 as I only have vs2013 on my machine
https://www.dropbox.com/s/1a9cggcot5djq4w/WaveTest2.rar
Christi258
Posts: 62 Joined: Wed Feb 06, 2013 12:11 pm
Post
by Christi258 » Wed Apr 16, 2014 3:34 pm
Well, if I try yours, everything is fine