if some one could help me with the shader

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
nobleqiao
Posts: 5
Joined: Thu Jul 03, 2008 2:01 am
Location: China ChengDu

if some one could help me with the shader

Post by nobleqiao »

This is my code using elvman's HEX EDITOR,however,I can't get the terrain as I have seen from the editor's preview. I have a problem here,
the area that should be rock,there is grass.So is the rock area
here is my code:
in class MyShaderCallBack:public video::IShaderConstantSetCallBack

Code: Select all

coverage=2;
		bool succ1=services->setPixelShaderConstant("coverage",(f32*)(&coverage),1);
		lightmap=3;
		bool succ2=services->setPixelShaderConstant("lightmap",(f32*)(&lightmap),1);
		splat1=0;
		bool succ3=services->setPixelShaderConstant("splat1",(f32*)(&splat1),1);
		splat2=1;
		bool succ4=services->setPixelShaderConstant("splat2",(f32*)(&splat2),1);

All of the fuction above return false
in the main function

Code: Select all

terrain->setMaterialTexture(0, driver->getTexture("media/terrain/splatting_grass.png"));
	terrain->setMaterialTexture(1, driver->getTexture("media/terrain/splatting_rock.png"));
	terrain->setMaterialTexture(2, driver->getTexture("media/test_coverage.bmp"));
	terrain->setMaterialTexture(3, driver->getTexture("media/test_lightmap.bmp"));
the declaration in ps.hlsl

Code: Select all

sampler2D coverage; //coverage
sampler2D lightmap; //lightmap

sampler2D splat1;
sampler2D splat2;
I am a totally beginer,I hope someone could give me a hand.Any help is appreciated.Thx..
Freezing this summer
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

I've not used shaders in irrlicht myself but in raw opengl you pass the texture itself to the shader for a sampler2d (in ogl a texture is just an index really) but you're passing the layer index of the texture, rather than the texture itself, so i think that could be the problem.

But i don't know how to pass textures to shaders, though if you search the forum you can probably find out as i'm sure i've seen this question asked before.
Image Image Image
nobleqiao
Posts: 5
Joined: Thu Jul 03, 2008 2:01 am
Location: China ChengDu

Post by nobleqiao »

JP wrote:I've not used shaders in irrlicht myself but in raw opengl you pass the texture itself to the shader for a sampler2d (in ogl a texture is just an index really) but you're passing the layer index of the texture, rather than the texture itself, so i think that could be the problem.

But i don't know how to pass textures to shaders, though if you search the forum you can probably find out as i'm sure i've seen this question asked before.
Thank U,I have searched the forum before I had to post this topic here.I found some similar problem,but they seem not be solved at all.So I still can't sweep my trouble.Although I really need help,I will keep trying.
Hope the genius can give me a hand.
Freezing this summer
dlangdev
Posts: 1324
Joined: Tue Aug 07, 2007 7:28 pm
Location: Beaverton OR
Contact:

Post by dlangdev »

since you didn't post the entire code in a zip, my answer will vary from bullseye to wtf-is-that-answer.

the order of how you declare the textures are important, pay attention to it.
Image
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

Elvman's editor uses HLSL. From the way you are passing the shader uniform variables to specify the texture index it seems like you are using OpenGL. What's going on here exactly?
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
nobleqiao
Posts: 5
Joined: Thu Jul 03, 2008 2:01 am
Location: China ChengDu

Post by nobleqiao »

dlangdev wrote:since you didn't post the entire code in a zip, my answer will vary from bullseye to wtf-is-that-answer.

the order of how you declare the textures are important, pay attention to it.
This is the terrain editor by elvman I am using:
http://irrlicht.sourceforge.net/phpBB2/ ... hlight=hex
I tried to upload a zip file,but failed.
will you gave me your e-mail?I shall sent the zip file to you.
Freezing this summer
nobleqiao
Posts: 5
Joined: Thu Jul 03, 2008 2:01 am
Location: China ChengDu

Post by nobleqiao »

BlindSide wrote:Elvman's editor uses HLSL. From the way you are passing the shader uniform variables to specify the texture index it seems like you are using OpenGL. What's going on here exactly?
Thank you for your attention.I just began to use shader.Since that ,I really don't know how to manage with it.
I am using HLSL,while I am not sure whether should I pass variables like sampler2D coverage to Terrain_ps.hlsl.For when I didn't pass variables,I also can get a terrain scene.but still with the incorrect textures.


MayBe I got it now,this strange situation was probably caused by the coverage map generated by the HEX EDITOR,I reverse the color of each pixel of the map,then I got the right terrain scene now.(but using the original coverage map as height map to do LOD).
Or,at least my HEX EDITOR by Elvman is not the latest. :wink:
Freezing this summer
Post Reply