Pass Cubic Texuture to cg, and display as 2d texture

Anything and everything that's related to OGRE or the wider graphics field that doesn't fit into the other forums.
Post Reply
white_waluigi
Goblin
Posts: 253
Joined: Sat Sep 28, 2013 3:46 pm
x 10

Pass Cubic Texuture to cg, and display as 2d texture

Post by white_waluigi »

I'm currrently in the process of creating pointlight-shadows for cg.
My current solution is to use 4 dummy lights to genereate the depth- texture in all directions, then put those textures into a cubic texture, get that textzure to cg and use it to get the shadows mapped.
The problem now is, that i can't get the cubemap over to cg.
I'm now trying to display the cubic shadowmap as a normal texture, so i can see if it was transmitted correctly.
But I have now idea, if it got ttransmitted correctly or how to display as a simople 2dtexture

This is the code i use to get the shadow textures to cg:

C++

Code: Select all

//get active pass
Pass* pass = tech->getPass(0);
//get shadowtexture
TextureUnitState* tus = pass->getTextureUnitState("ShadowMap");
assert(tus);
TexturePtr * stp=new TexturePtr[6];
for(int i=0;i<6;i++){
	//lightlist is cleared, only pointlight and 6 dummyspotlights are in there
	stp[i]=sm->getShadowTexture((i+1));
}
//map the cubic texture to shadowmap texturepass
tus->setCubicTexture(stp,true);
Cg:

Code: Select all

arguments:
uniform samplerCUBE ShadowTex : register(s2),
in float4      posi : WPOS


//posi is WPOS
return texCUBE(ShadowTex,float3(posi.x/300.0,posi.y/300.0,posi.z/300.0));
So how can i best check the cubic texture?
And how can i display it as a 2d texture?
frostbyte
Orc Shaman
Posts: 737
Joined: Fri May 31, 2013 2:28 am
x 65

Re: Pass Cubic Texuture to cg, and display as 2d texture

Post by frostbyte »

maybe this would help .... http://www.ogre3d.org/forums/viewtopic.php?f=2&t=40756
A) basicly - the easiest way is to render the damm thing into a box model X 6 and present them stiched together side by side with each box showing a differnt face...
ways of doing that:
1)attach the boxes to scene root node( i alway create another fake root on top of it and attach the camera to the original scene root, so this way i can seperate the camera from the actual scene ... )
2)even easier way- attach the boxes scene nodes directly to the camera parent scene node
3)preffered way - use overlays - basicly you create a diffrent scene with the cubes and render it to an overlayContainer....(search the forum for mrror example )
this way your box entities will be seperated and not be affected by shadowing, camera pos etc....

After attaching the boxes stich/display each box with differnt rotation/position...so they are grouped together into one big happy 2d like texture...

B)maybe you can use MRT with a custom shader...( mmm more work...)

C)use specific cg/opengl/dx instruction to that glCopySubImage2d or what ever but i dont think thats the right path...

D)QUICK AND DIRTY - use the cubic-texture u've created with SKYBOX material( it will be distorted, but youl'e have the basic cube_tex debuging that u want )
actualy - maybe u can use the SKYBOX code and tweak the shdaders a bit...TAKE CARE of the "seperateUV" stuff and issues...

ps: i strongly advice u to use the forum search( preferbly google search bar ) to tackle issues of such kind....
even if this means reading every post containing the words "cubic texture"( like i just did for u... ) you can learn a lot on related subjects and issues.
good to see that ur'e serious...happy coding :)
the woods are lovely dark and deep
but i have promises to keep
and miles to code before i sleep
and miles to code before i sleep..

coolest videos link( two minutes paper )...
https://www.youtube.com/user/keeroyz/videos
white_waluigi
Goblin
Posts: 253
Joined: Sat Sep 28, 2013 3:46 pm
x 10

Re: Pass Cubic Texuture to cg, and display as 2d texture

Post by white_waluigi »

Thx for your tips, but it seams, the problem is, that cg doesn't accept cubeic textures with ogre. I tried this sample: http://www.ogre3d.org/tikiwiki/Accurate ... +influence
And the cubemap in the cg shader was empty. If i use 6 individual textures, they will be send to cg correctly.
And since cg isn't support anymore anyway, i think i will sitch to glsl. Hope it works with that.
And I already got some sample code from this site:
http://forum.devmaster.net/t/shader-eff ... pping/3002
Btw, isn't there a better way, than to create 6 dummy ligghts for the cubic texture? Because, they have to be processed everytime, which takes ressources? So how else could I get a cubic depthmap around the pointlight?
frostbyte
Orc Shaman
Posts: 737
Joined: Fri May 31, 2013 2:28 am
x 65

Re: Pass Cubic Texuture to cg, and display as 2d texture

Post by frostbyte »

i learn as i answer you so dont expect to much of my answers regarding shading techniques....never the less....

Ogre is a general purpose rendering engine and as such it does not support wrapping a scene view to a cubic texture
but as such it is very customizable and you are able to write a custom SceneManager to do that...
it will save you some draw calls, but will waste your time and mental health...( optimization and tight intergration is what makes AAAA such as cryEngine4 )
http://www.ogre3d.org/forums/viewtopic.php?f=3&t=37804

out of my mind: you may do some optimization your self...eg drop all material rendering pass, use LOD with low polygon count, use INT buffers instead of FLOAT use MRT and geometry shader etc..
its realy a problem of Resource - and i dont mean the computational type...( time > money ) unless you realy realy enjoy it....( to suffer, that is...)

if what you are asking( please be more specific... ) is is there a better technique to achive that - then my answer is - yes there are many techniqes - each has it pros and cons...its realy about what you want to achive and how much effort( oh the pain...) are you willing to put into it....

As RealTime rendering unlike UNBIASED rendering is all about make-believe you can use many methods as Imperfect shadow maps( https://dl.acm.org/citation.cfm?id=1409082 ) Forward rendering and its varients, pre-pass, etc...http://www.altdev.co/2011/01/18/forward ... l-matters/ http://yosoygames.com.ar/wp/2013/09/cha ... rd-passes/

I think you better first get the thing working and only after it is stable and you are pleased with the reults - start optimizing...

Conclusion, famous last words and Fare-whale...
While reading some good material before jumping into the water wont hurt...http://http.developer.nvidia.com/GPUGem ... _ch12.html
and wandering the net for extra tips will only make you smarter...in the end it's a question of what you want to achive and how far are you willing to go....
As for me, i just sit and wait for the SMART people to do this stuff for me...as i no longer have any desire of dealing with high MATH...or thinking too HARD...
I just enjoy watching NINJA beating the hell out of Sinbad and Penguin doing his cute little dance.... :D
Ok i'm Out of resources so good luck with this...
the woods are lovely dark and deep
but i have promises to keep
and miles to code before i sleep
and miles to code before i sleep..

coolest videos link( two minutes paper )...
https://www.youtube.com/user/keeroyz/videos
white_waluigi
Goblin
Posts: 253
Joined: Sat Sep 28, 2013 3:46 pm
x 10

Re: Pass Cubic Texuture to cg, and display as 2d texture

Post by white_waluigi »

There really seams to be a problem with a passing cubic textures with Ogre.
This material isn't working:

material:

Code: Select all

vertex_program reflectionvp glsl
{
	source reflectionvp.glsl
	entry_point main_vs

}
 
fragment_program reflectionfp glsl
{
	source reflectionfp.glsl
	entry_point main_ps


}
 
material ppPhongNormalCubeMap
{
	technique
	{		 
		pass
		{
			vertex_program_ref reflectionvp
			{				

			}
 
			fragment_program_ref reflectionfp
			{				

			}
 

			texture_unit

			{
														texture_alias ReflectionMap
				tex_address_mode clamp
			}
		}
	}
}
 
 
material ballMaterial : ppPhongNormalCubeMap
{	
	set_texture_alias DiffuseMap		b15.jpeg
	set_texture_alias NormalMap		leather_normal_24b.png
	set_texture_alias SpecularMap		leather_specular_DXT1.png
	set_texture_alias ReflectionMap		tenerifeCubeMap256C10.jpeg
}
fragment:

Code: Select all

uniform samplerCube cubemap;
varying vec3  ReflectDir;
 
void main (void)
{
	vec4 color;
 
	//Cubemap
	color=vec4(textureCube(cubemap,ReflectDir));
	gl_FragColor=color;
 
}
vertex:

Code: Select all

varying vec3 ReflectDir;
 
void main (void)
{
 
	//Enable texture coordinates
	gl_TexCoord[0] = gl_MultiTexCoord0;
	gl_TexCoord[1] = gl_MultiTexCoord1;
	gl_TexCoord[2] = gl_MultiTexCoord2;
	gl_TexCoord[3] = gl_MultiTexCoord3;
 
	//Cubemap
	gl_Position    = ftransform();
	vec3 normal    = normalize(gl_NormalMatrix*gl_Normal);
	vec4 pos       = gl_ModelViewMatrix*gl_Vertex;
	vec3 eyeDir    = pos.xyz;
	ReflectDir     = reflect(eyeDir,normal);
}
isn't working.
Any Idea why? Or is it really just not supported by Ogre3d?
User avatar
c6burns
Beholder
Posts: 1512
Joined: Fri Feb 22, 2013 4:44 am
Location: Deep behind enemy lines
x 138

Re: Pass Cubic Texuture to cg, and display as 2d texture

Post by c6burns »

:shock:

You know there's a dynamic cube map sample, yes? Take some time to analyze Sample_CubeMapping. For starters you probably will want to declare your texture unit to be a cubic texture, as per http://www.ogre3d.org/docs/manual/manua ... 05ftexture
frostbyte
Orc Shaman
Posts: 737
Joined: Fri May 31, 2013 2:28 am
x 65

Re: Pass Cubic Texuture to cg, and display as 2d texture

Post by frostbyte »

As much as every body here want to help share and guide - nobody realy have much spare time... so please... as a general rule...
Use the community Only after trying all suggesteted soultions( Sample code, Forum search, Ogres api , google search ) to your problems( not ogre's )

the code you have shown is incomplete - and thus not very helpful....
where are the scene and textures decleration and processing? :shock:

if you still have problem with passing cubicTex then maybe your hardware does'nt support cubic_textures( you can see if it does in ogre's log when you create the render system ) in that case go with the seperateUV flag, which support old hardware...
the woods are lovely dark and deep
but i have promises to keep
and miles to code before i sleep
and miles to code before i sleep..

coolest videos link( two minutes paper )...
https://www.youtube.com/user/keeroyz/videos
white_waluigi
Goblin
Posts: 253
Joined: Sat Sep 28, 2013 3:46 pm
x 10

Re: Pass Cubic Texuture to cg, and display as 2d texture

Post by white_waluigi »

The Cubemap Sample works on my hardware, and so does everything with cubemaps that doesn't involve shaders. The only thing that doesn't seam to work properly, is passing Cubemaps to the Shader.
So could somone please try this:http://www.ogre3d.org/tikiwiki/Accurate ... +influence
using the 1.9 branch, so I can see, if its realy a problem with my hardware or my drivers.
I have tried a lot allready, but I can neither get cg or glsl to accept cubemaps. So either theres a problem with passing cubemaps inside Ogre 1.9 , because I assume, that sample worked at some point, or my Hard or software.
(I'm using Linux Mint 16 with an Nvidia 770 and the 310 driver(Linux Mint didn't update the reps to 331 yet)).
So yeah could someone try this and tell me if it worked for him using 1.9?
Because I only have the one PC ATM and no WIndows partition.
User avatar
c6burns
Beholder
Posts: 1512
Joined: Fri Feb 22, 2013 4:44 am
Location: Deep behind enemy lines
x 138

Re: Pass Cubic Texuture to cg, and display as 2d texture

Post by c6burns »

Sample_Ocean uses a cubic texture with combined UVW in a shader. It's how the water gets a sky reflection. Same with some of the materials in Sample_Water.
frostbyte
Orc Shaman
Posts: 737
Joined: Fri May 31, 2013 2:28 am
x 65

Re: Pass Cubic Texuture to cg, and display as 2d texture

Post by frostbyte »

i realy love to help - but have my own stuff to do...
it doesn't seem likely that is a hardware problem...( nvidia 770...wow :roll: )
you can always try and use WINE with Ogres window version ...if nothing works for you...
if u find that the problem is with ogre( which i hardly believe is the case ) please make a jira ticket...
the woods are lovely dark and deep
but i have promises to keep
and miles to code before i sleep
and miles to code before i sleep..

coolest videos link( two minutes paper )...
https://www.youtube.com/user/keeroyz/videos
User avatar
c6burns
Beholder
Posts: 1512
Joined: Fri Feb 22, 2013 4:44 am
Location: Deep behind enemy lines
x 138

Re: Pass Cubic Texuture to cg, and display as 2d texture

Post by c6burns »

frostbyte wrote:you can always try and use WINE with Ogres window version ...if nothing works for you...
lol ...
or just dont use cg...
OP ruled out CG as the issue. Dollars to dimes his material setup just isn't correct.
frostbyte
Orc Shaman
Posts: 737
Joined: Fri May 31, 2013 2:28 am
x 65

Re: Pass Cubic Texuture to cg, and display as 2d texture

Post by frostbyte »

i'm not going to lose money over this....so the bet is off... 8)
the woods are lovely dark and deep
but i have promises to keep
and miles to code before i sleep
and miles to code before i sleep..

coolest videos link( two minutes paper )...
https://www.youtube.com/user/keeroyz/videos
white_waluigi
Goblin
Posts: 253
Joined: Sat Sep 28, 2013 3:46 pm
x 10

Re: Pass Cubic Texuture to cg, and display as 2d texture

Post by white_waluigi »

Yes, Ocean Sample semas to work, try to isolate my error, will update as soon as i do.
white_waluigi
Goblin
Posts: 253
Joined: Sat Sep 28, 2013 3:46 pm
x 10

Re: Pass Cubic Texuture to cg, and display as 2d texture

Post by white_waluigi »

Ok, this code works. It autmaticly loads the 6 cubescene textures and puts them into a cubic texture. setCubicTexture only seams to work using one texture, containing 6 textures.
So It seams like the way to go is put all the 6 depth mapping textures into one TEX_TYPE_CUBE_MAP, which will be given to setCubicTexture, which will redirect it to the shader.
So how can I put 6 texture pointor into one TEX_TYPE_CUBE_MAP texture pointer?

Code: Select all

   Ogre::TexturePtr * ptrs=new Ogre::TexturePtr[6];
	Ogre::TexturePtr  ptr= Ogre::TextureManager::getSingleton().load(
			"cubescene.jpg", // Name of texture
	            "General", // Name of resource group in which the texture should be created
	            Ogre::TEX_TYPE_CUBE_MAP
	          );


   ptrs[0]=ptr;


   Ogre::TextureUnitState * text= ogreHead->getSubEntity(1)->getMaterial()->getTechnique(0)->getPass(0)->getTextureUnitState(0);

	text->setCubicTexture(ptrs,true);
Post Reply