Cube maps

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!
Post Reply
scippie
Posts: 26
Joined: Sat Oct 13, 2007 3:35 pm
Location: Belgium
Contact:

Cube maps

Post by scippie »

I know cubemaps aren't yet integrated in irrlicht, but is it possible to fake the same thing with 6 separate textures and still use them in a shader with the texCUBE instruction?

I've tried to do it, setting texture 0 to colormap and 1-6 to cubemap but get weird results and I haven't found out wether that's due to the textures or the way I handle them in the shader.

C++:

Code: Select all

node_bol->setMaterialTexture(0, tex);
for (int i = 0; i < 6; ++i)
	node_bol->setMaterialTexture(i + 1, cubeMap[i]);
node_bol->setMaterialFlag(EMF_LIGHTING, false);
node_bol->setMaterialType((E_MATERIAL_TYPE)myShaderMtrlType2);
Pixel shader:

Code: Select all

sampler2D tex0;
samplerCUBE tex1;
float4 pshmain(VS_OUTPUT In) : COLOR
{
 float4 Color = tex2D(tex0, In.Tex);
 Color = 0.5 * Color + 0.5 * texCUBE(tex1, In.Reflect);
 return Color;
}
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

To me that looks like you've just created 6 textures (the faces of the cube) as individual textures and then in the shader you're treating the first texture (face 1) as a cube map, which obviously isn't going to work and i guess it would read into random memory or something.

I guess you'd have to make the texCUBE function yourself and determine which face texture to read from and which position in the texture.
Image Image Image
scippie
Posts: 26
Joined: Sat Oct 13, 2007 3:35 pm
Location: Belgium
Contact:

Post by scippie »

So, I try to create my own texCUBE implementation with 6 textures. Guess what, irrlicht only supports 4 textures per material (see other thread).

Is there an other way to create cubemap-reflections with irrlicht? Or is this "goodbye"?
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

IrrSpintz has device dependent cube-map textures and the renderers to go with it, perhaps you could steal his implementation
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

I was thinking using only 1 texture and dividing the texcoords up to simlute 6 different ones. When you do the rendering for reflections use viewports to render to seperate parts of the image.
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
scippie
Posts: 26
Joined: Sat Oct 13, 2007 3:35 pm
Location: Belgium
Contact:

Post by scippie »

BlindSide wrote:I was thinking using only 1 texture and dividing the texcoords up to simlute 6 different ones. When you do the rendering for reflections use viewports to render to seperate parts of the image.
Hey, yes, that's a good one.
Quality will however be lower.
But even better, I can use 3 textures with 2 viewports on each texture, which will almost solve the quality issue.

Thanks for a great idea!
Post Reply