Easy Ogre Exporter for 3DSMAX

The place for artists, modellers, level designers et al to discuss their approaches for creating content for OGRE.
User avatar
trilobite
Silver Sponsor
Silver Sponsor
Posts: 135
Joined: Thu Jul 13, 2006 9:16 pm
Location: San Juan Capistrano, CA, USA
x 1

Re: Easy Ogre Exporter for 3DSMAX

Post by trilobite »

Wonderful resource. Thanks for making it available.

I am experimenting with the shader exported with my scene. Specifically the ability to render spotlights on the pixel level.
I have two spotlights on a vehicle.
Here is the problem. The spotlights illuminate the scene as expected when the vehicle is facing one direction.
Image

However, when the car is turned around 180 degrees, spotlights don't show.
Image

The spotlights gradually strengthen and weaken as the car circles around.

Maybe somebody with shader expertise can explain this, because shaders are a complete mystery to me. My guess is that it's probably something really simple. I just can see it.

Thanks for the help.

Here is the ".program code that was exported from 3ds max via easy ogre exporter...

Code: Select all

vertex_program exo_explorer_pb_terrain_alpine_valley_1vsAmbGEN0 cg
{
	source pb_terrain_alpine_valley_1.cg
	profiles vs_1_1 arbvp1
	entry_point exo_explorer_pb_terrain_alpine_valley_1vsAmbGEN0
	default_params
	{
		param_named_auto wvpMat worldviewproj_matrix
	}
}

fragment_program exo_explorer_pb_terrain_alpine_valley_1fpAmbGENDIFF0 cg
{
	source pb_terrain_alpine_valley_1.cg
	profiles ps_2_x arbfp1
	entry_point exo_explorer_pb_terrain_alpine_valley_1fpAmbGENDIFF0
	default_params
	{
		param_named_auto ambient ambient_light_colour
		param_named_auto matAmb surface_ambient_colour
		param_named_auto matEmissive surface_emissive_colour
	}
}

vertex_program exo_explorer_pb_terrain_alpine_valley_1vsLightGENNORM01 cg
{
	source pb_terrain_alpine_valley_1.cg
	profiles vs_1_1 arbvp1
	entry_point exo_explorer_pb_terrain_alpine_valley_1vsLightGENNORM01
	default_params
	{
		param_named_auto wMat world_matrix
		param_named_auto wvpMat worldviewproj_matrix
		param_named_auto spotlightDir light_direction_object_space 0
	}
}

fragment_program exo_explorer_pb_terrain_alpine_valley_1fpLightGENDIFF0NORM1 cg
{
	source pb_terrain_alpine_valley_1.cg
	profiles ps_2_x arbfp1
	entry_point exo_explorer_pb_terrain_alpine_valley_1fpLightGENDIFF0NORM1
	default_params
	{
		param_named_auto lightDif0 light_diffuse_colour 0
		param_named_auto lightSpec0 light_specular_colour 0
		param_named_auto camPos camera_position
		param_named_auto matShininess surface_shininess
		param_named_auto matDif surface_diffuse_colour
		param_named_auto matSpec surface_specular_colour
		param_named_auto lightPos0 light_position 0
		param_named_auto lightAtt0 light_attenuation 0
		param_named_auto spotlightParams spotlight_params 0
		param_named_auto iTWMat inverse_transpose_world_matrix
		param_named normalMul float 1
	}
}
Here is the *.cg shader code exported

Code: Select all

void exo_explorer_pb_terrain_alpine_valley_1vsAmbGEN0(float4 position	: POSITION,
	float3 normal : NORMAL,
	float2 uv0 : TEXCOORD0,
	out float4 oPos: POSITION,
	out float2 oUv0 : TEXCOORD0,
	uniform float4x4 wvpMat
)
{
	oPos = mul(wvpMat, position);
	oUv0 = uv0;
}

float4 exo_explorer_pb_terrain_alpine_valley_1fpAmbGENDIFF0(float4 position	: POSITION,
	float2 uv0 : TEXCOORD0,
	uniform float3 ambient,
	uniform float4 matAmb,
	uniform float4 matEmissive,
	uniform sampler2D diffuseMap : register(s0)): COLOR0
{
	float4 diffuseTex = tex2D(diffuseMap, uv0);
	float4 retColor = max(matEmissive, float4(ambient, 1) * matAmb);
	retColor *= diffuseTex;
	return retColor;
}

void exo_explorer_pb_terrain_alpine_valley_1vsLightGENNORM01(float4 position	: POSITION,
	float3 normal : NORMAL,
	float3 tangent : TANGENT,
	float2 uv0 : TEXCOORD0,
	float2 uv1 : TEXCOORD1,
	out float4 oPos : POSITION,
	out float3 oNorm : TEXCOORD0,
	out float3 oTang : TEXCOORD1,
	out float3 oBinormal : TEXCOORD2,
	out float3 oSpDir : TEXCOORD3,
	out float4 oWp : TEXCOORD4,
	out float2 oUv0 : TEXCOORD5,
	out float2 oUv1 : TEXCOORD6,
	uniform float4x4 wMat,
	uniform float4x4 wvpMat,
	uniform float4 spotlightDir)
{
	oWp = mul(wMat, position);
	oPos = mul(wvpMat, position);
	oUv0 = uv0;
	oUv1 = uv1;
	oTang = tangent;
	oBinormal = cross(tangent, normal);
	oNorm = normal;
	oSpDir = mul(wMat, spotlightDir).xyz;
}

float4 exo_explorer_pb_terrain_alpine_valley_1fpLightGENDIFF0NORM1(float4 position	: POSITION,
	float3 norm : TEXCOORD0,
	float3 tangent : TEXCOORD1,
	float3 binormal : TEXCOORD2,
	float3 spDir : TEXCOORD3,
	float4 wp : TEXCOORD4,
	float2 uv0 : TEXCOORD5,
	float2 uv1 : TEXCOORD6,
	uniform float3 lightDif0,
	uniform float4 lightPos0,
	uniform float4 lightAtt0,
	uniform float3 lightSpec0,
	uniform float4 matDif,
	uniform float4 matSpec,
	uniform float matShininess,
	uniform float3 camPos,
	uniform float4 invSMSize,
	uniform float4 spotlightParams,
	uniform float4x4 iTWMat,
	uniform float normalMul,
	uniform sampler2D diffuseMap : register(s0),
	uniform sampler2D normalMap : register(s1)): COLOR0
{
	float3 ld0 = normalize(lightPos0.xyz - (lightPos0.w * wp.xyz));
	// attenuation
	half lightDist = length(lightPos0.xyz - wp.xyz) / (lightAtt0.r / lightAtt0.r);
	half la = 1;
	if(lightAtt0.a > 0.0)
	{
		half ila = lightDist * lightDist; // quadratic falloff
		la = 1.0 / (lightAtt0.g + lightAtt0.b * lightDist + lightAtt0.a * ila);
	}
	float3 normalTex = tex2D(normalMap, uv1);
	tangent *= normalMul;
	binormal *= normalMul;
	float3x3 tbn = float3x3(tangent, binormal, norm);
	float3 normal = mul(transpose(tbn), (normalTex.xyz -0.5) * 2); // to object space
	normal = normalize(mul((float3x3)iTWMat, normal));
	float3 diffuse = max(dot(normal, ld0), 0);
	// calculate the spotlight effect
	float spot = (spotlightParams.x == 1 && spotlightParams.y == 0 && spotlightParams.z == 0 && spotlightParams.w == 1 ? 1 : // if so, then it's not a spot light
	   saturate((dot(normalize(-spDir), ld0) - spotlightParams.y) / (spotlightParams.x - spotlightParams.y)));
	float3 camDir = normalize(camPos - wp.xyz);
	float3 halfVec = normalize(ld0 + camDir);
	float3 specular = pow(max(dot(normal, halfVec), 0), matShininess);
	float4 diffuseTex = tex2D(diffuseMap, uv0);
	float3 diffuseContrib = diffuse * lightDif0 * matDif.rgb;
	diffuseContrib *= diffuseTex.rgb;
	float3 specularContrib = specular * lightSpec0 * matSpec.rgb;
	float3 light0C = (diffuseContrib + specularContrib) * la * spot;
	float alpha = matDif.a;
	alpha *= diffuseTex.a;
	return float4(light0C, alpha);
}

arkeon
Goblin
Posts: 272
Joined: Fri Dec 04, 2009 6:02 pm
x 38

Re: Easy Ogre Exporter for 3DSMAX

Post by arkeon »

Hi !

I just tested I think this is the way you create your lights.
try : add a node for each light
create the spot without changing the light direction or prs.
move and rotate the node only.

and tell me :)
OpenSpace 3D Project manager
http://www.openspace3d.com
User avatar
trilobite
Silver Sponsor
Silver Sponsor
Posts: 135
Joined: Thu Jul 13, 2006 9:16 pm
Location: San Juan Capistrano, CA, USA
x 1

Re: Easy Ogre Exporter for 3DSMAX

Post by trilobite »

Yea, worth considering...
However, my spotlights already are on nodes.
Here is the basic setup for one of them...

Code: Select all

				m_pHeadlightLeft = m_pSceneMgr->createLight(m_strTitleHeadlightLeft);
					if (m_pHeadlightLeft)
					{
						m_pNodeHeadlightLeft = (Ogre::SceneNode*)m_pChassisSceneNode->createChild(m_strTitleNodeHeadlightLeft);
						if (m_pNodeHeadlightLeft)
						{
						
						Ogre::Vector3	vecDirection(0.0, 0.0, 1.0);
												
						m_pHeadlightLeft->setType(Ogre::Light::LT_SPOTLIGHT);
						m_pHeadlightLeft->setAttenuation(2000.0f, 1.0f, 0.005f, 0.0);
						m_pHeadlightLeft->setSpotlightRange(Ogre::Degree(30), Ogre::Degree(40));
						m_pHeadlightLeft->setCastShadows(false);
						m_pHeadlightLeft->setDiffuseColour(1.0, 1.0, 1.0);
						m_pNodeHeadlightLeft->attachObject(m_pHeadlightLeft);
						m_pNodeHeadlightLeft->setPosition(Ogre::Vector3(-3.05, 0.0, -4.05));
						m_pNodeHeadlightLeft->setDirection(vecDirection);
						}
					}
I also have two directional lights in the scene (for star and moon). The relative placement of these lights has no influence on the behavior of the spotlights. If they are in the scene or out of the scene, doesn't matter. Spots behave the same. I tried the scene with my own terrain mesh and the one exported from max by your app, same results.

Anyway, not to stress over. You needn't exert yourself for this little problem. Your app has more important things to do.

Ogre is just notoriously hard to get shaders to work properly for my application. I have tried every tutorial on the wiki just to get these little spotlights to render. Some success, but poor results. I have tried examples in Nvidia's cg tutorial, which is very hard to translate over to Ogre's custom language. No luck there either. In addition, the documentation (in books and other web sources) for understanding shader code is so remarkable poor and vague that I am surprised that any newcomer can comprehend them from the docs alone. Listen to me rant... LOL :)

On a previous version of Ogre, I was able to use the RTSS. But Ogre 1.9 broke this for my application. Now if I use RTSS, my custom moon shader is not implemented at all.

Hopefully, Ogre 2.0 will eliminate the need for us to fiddle with shader code (fingers tightly crossed). In the meantime, I'll go back to fixed function pipeline rendering. Gives me nostalgia for 1998 when I started coding up gameshells with the genesis3d engine.

Cheers, and thanks.
arkeon
Goblin
Posts: 272
Joined: Fri Dec 04, 2009 6:02 pm
x 38

Re: Easy Ogre Exporter for 3DSMAX

Post by arkeon »

this is strange I use ogre 1.9 and don't have the problem on spots.
but I didn't try in openGL
OpenSpace 3D Project manager
http://www.openspace3d.com
User avatar
trilobite
Silver Sponsor
Silver Sponsor
Posts: 135
Joined: Thu Jul 13, 2006 9:16 pm
Location: San Juan Capistrano, CA, USA
x 1

Re: Easy Ogre Exporter for 3DSMAX

Post by trilobite »

arkeon wrote:this is strange I use ogre 1.9 and don't have the problem on spots.
but I didn't try in openGL
Right. 1.9 and RTSS puts out nice spotlights. Works perfectly. BUT, my little cg shader of the phases of the moon doesn't work while RTSS is implemented. Moon is just a static bitmap from the fallback technique. I think RTSS takes over every surface in the map and applies its magic to it, even if you don't want it to. I went over this for quite a few rounds on these forums last year. Upshot was that if I wanted both, I should write my own shaders for spotlights -- which I have failed at doing. So, I must choose, spotlights OR moon phases. Moon phases win out.
It is very silly, isn't it?

Like I said, no biggy. Don't stress. Not your problem, and it's not that big a problem anyway. If it was just a little tweak in your shader code, that would have been nice. Not wanting to hijack this thread...

Thanks.

PS. if anybody knows where I can find clean and simple shader code for spotlights for Ogre, please chime in. But please don't refer me to the list of tutorials in the Ogre wiki. I tried all of them already.
User avatar
c6burns
Beholder
Posts: 1512
Joined: Fri Feb 22, 2013 4:44 am
Location: Deep behind enemy lines
x 139

Re: Easy Ogre Exporter for 3DSMAX

Post by c6burns »

trilobite wrote:Ogre is just notoriously hard to get shaders to work properly for my application. I have tried every tutorial on the wiki just to get these little spotlights to render. Some success, but poor results. I have tried examples in Nvidia's cg tutorial, which is very hard to translate over to Ogre's custom language.
I don't understand ... Ogre has a cg plugin. Or you can use GLSL or HLSL ... there is no custom shading language.

Anyway this code looks weird to me. Why the C-style cast of a Node* to a SceneNode*? createChildSceneNode will do a static_cast for you. Also why checking the pointers returned from createLight and createChild ... AFAIK they will raise an exception should something go wrong. They don't return NULL pointers. You can shorten it all to this:

Code: Select all

m_pHeadlightLeft = m_pSceneMgr->createLight(m_strTitleHeadlightLeft);
m_pNodeHeadlightLeft = m_pChassisSceneNode->createChildSceneNode(m_strTitleNodeHeadlightLeft);
// do stuff here
I know the spotlight code in EOE's cg works. Just to be sure I made a simple app that creates a car scenenode, a child headlight scenenode, and attaches to that child a spotlight. I cut and paste from your example and filled in the rest myself. Every frame I yaw the car scenenode and the headlight responds as expected, so I'm not sure what is going wrong for you. I am using 1.9 and tested GL and DX9.

If the only problem switching to 1.9 is your moon shader, maybe you can make another thread detailing the issue and I'll help if I can :)
User avatar
trilobite
Silver Sponsor
Silver Sponsor
Posts: 135
Joined: Thu Jul 13, 2006 9:16 pm
Location: San Juan Capistrano, CA, USA
x 1

Re: Easy Ogre Exporter for 3DSMAX

Post by trilobite »

Thanks for the coding suggestions. This application got its start in 2006. So, some of the code and tricks are holdovers from earlier times. Updated now.

Thanks also for testing the exported shaders and insisting that it works. That got me experimenting on my end with different settings.
I discovered that while setting up the material in 3ds Max 2015, if I assigned a bitmap or a normal bump (with attached normal bitmap) to the "bump" input node on the material -- then the exported shader exhibited the problem I am describing.
This happened if the bump input was just a regular old bitmap (not a normal map) too.

If I remove the bump input to the material in max, then the exported shader displays very nicely as expected. Here is an example of the result...

Image

Nice little specular effect there as well in the above shot.
So, I'm happy. At the moment, the trick for me is to NOT have any bump input in the max material.

Thanks to arkeon for this awesome utility, and thanks to c6burns for helping out with this problem.
arkeon
Goblin
Posts: 272
Joined: Fri Dec 04, 2009 6:02 pm
x 38

Re: Easy Ogre Exporter for 3DSMAX

Post by arkeon »

good :)

yes the shader do not manage grey bump maps only normal maps.
OpenSpace 3D Project manager
http://www.openspace3d.com
arkeon
Goblin
Posts: 272
Joined: Fri Dec 04, 2009 6:02 pm
x 38

Re: Easy Ogre Exporter for 3DSMAX

Post by arkeon »

Hi !

EOE 2.2 is available !

I added a new option to generate one pass shaders with 3 lights.
Previous shader generation was only for multipass shaders that can make the scene a lot slower.
OpenSpace 3D Project manager
http://www.openspace3d.com
User avatar
suny2000
Halfling
Posts: 88
Joined: Sun Sep 06, 2009 12:36 pm
x 18

Re: Easy Ogre Exporter for 3DSMAX

Post by suny2000 »

Thanks for your exporter. I love it!
I have one question:
I'm using Fresnel in my .cg materials, because in my opinion this is really useful to create good looking shaders. I'm using your exporter and I'm creating my materials using the .material values you are exporting from the scene.

Do you think there could be a way to export another value from max (maybe the specular "soften" value, which is more or less a kind of obscure Fresnel) and convert it to an ogre material value ?
S.
http://bulostudio.com: website and devlog of a small indie studio working on SHMUP CREATOR
https://twitter.com/bulostudio : follow me on twitter!
arkeon
Goblin
Posts: 272
Joined: Fri Dec 04, 2009 6:02 pm
x 38

Re: Easy Ogre Exporter for 3DSMAX

Post by arkeon »

Hmm why not

can you modify the shader corresponding to this ratio value so I could see what you need exactly ?
OpenSpace 3D Project manager
http://www.openspace3d.com
arkeon
Goblin
Posts: 272
Joined: Fri Dec 04, 2009 6:02 pm
x 38

Re: Easy Ogre Exporter for 3DSMAX

Post by arkeon »

Hello!

EOE 2.3 is available :
- use "metal" material type to disable fresnel reflection
- use "Soften" material parameter to adjust fresnel power
- shader optim on uv coords (2 coords per TEXTURE(n))
- correction on uv index of normal map texture
- correction on 3 light shaders
- setup updated
OpenSpace 3D Project manager
http://www.openspace3d.com
User avatar
suny2000
Halfling
Posts: 88
Joined: Sun Sep 06, 2009 12:36 pm
x 18

Re: Easy Ogre Exporter for 3DSMAX

Post by suny2000 »

Sorry to not answering before, I was too busy :(

Thanks a lot Arkeon for your new version. I'll try it next week.
And one again, thanks for your work, your exporter is great and works like a charm :)

S.
http://bulostudio.com: website and devlog of a small indie studio working on SHMUP CREATOR
https://twitter.com/bulostudio : follow me on twitter!
twilightzoney
Gnoblar
Posts: 6
Joined: Mon Jun 29, 2015 6:46 am

Re: Easy Ogre Exporter for 3DSMAX

Post by twilightzoney »

I've installed the latest EOE for Max and it seems it ruins/resets the 2nd UV channel for some reason. Is there any plans on fixing this at all?

How it should look.
2015-06-27_2110.png
How it comes out after being exported.
2015-06-27_2111.png
Which is weird I didn't start having this issue till I updated to the lastest one.

I've tested on Max 2012 and 2015
You do not have the required permissions to view the files attached to this post.
arkeon
Goblin
Posts: 272
Joined: Fri Dec 04, 2009 6:02 pm
x 38

Re: Easy Ogre Exporter for 3DSMAX

Post by arkeon »

Hello,

are you sure this is related to EOE ?
I didn't change anything on UV coords for a long time.

how did you imported the "exported" file ?
OpenSpace 3D Project manager
http://www.openspace3d.com
twilightzoney
Gnoblar
Posts: 6
Joined: Mon Jun 29, 2015 6:46 am

Re: Easy Ogre Exporter for 3DSMAX

Post by twilightzoney »

We have our engine use the Ogre Pipeline and convert the Ogre Meshes to another format which we can reimport into max. But the issue is we haven't changed our code for converting anything. So I doubt it is that

I've had some of my friends retry this as well and we all got the same results. And even done it with simple geometry such as a box and did a new 2nd uv channel and it still got this issue.

I could send you a piece of the mesh that has it happen if you want to check. Since I'm honestly not sure what the issue is if you guys haven't done anything with it for a while.
Last edited by twilightzoney on Mon Jun 29, 2015 7:25 pm, edited 1 time in total.
arkeon
Goblin
Posts: 272
Joined: Fri Dec 04, 2009 6:02 pm
x 38

Re: Easy Ogre Exporter for 3DSMAX

Post by arkeon »

I don't know for OgreMax but If you used OgreMax to export the max file once it can break some default values in the max file and add helpers on skeletons or materials that break standard export and do not allow to open the max file if the ogre max is not installed (I already ran into that issue several years ago, I don't know for current versions).

Try to make a new scene, merge the max file into it and do not include OgreMax helpers and config.
Save as a cleaned new scene file and try to export again. we should be fixed if the issue is from ogre max or not.

Yes send me the object with textures so I could also check the output.
OpenSpace 3D Project manager
http://www.openspace3d.com
twilightzoney
Gnoblar
Posts: 6
Joined: Mon Jun 29, 2015 6:46 am

Re: Easy Ogre Exporter for 3DSMAX

Post by twilightzoney »

Heres the object I have. And I also checked and I saw no helpers or anything of OgreMax in my scene I just figured it was conflicting just by being installed at all. I've uninstalled them though now.


Heres one of the meshes.
Object.7z
You do not have the required permissions to view the files attached to this post.
arkeon
Goblin
Posts: 272
Joined: Fri Dec 04, 2009 6:02 pm
x 38

Re: Easy Ogre Exporter for 3DSMAX

Post by arkeon »

can you send texture with it So I could check visually (I have no way to import it back)
OpenSpace 3D Project manager
http://www.openspace3d.com
arkeon
Goblin
Posts: 272
Joined: Fri Dec 04, 2009 6:02 pm
x 38

Re: Easy Ogre Exporter for 3DSMAX

Post by arkeon »

Ok for me it export well.
it's just you don't have any texture on the UV2 channel so the exporter can ignore it for mesh optimization. (I don't remember well how I made this)

just try to add a texture on uv2 channel and export again
OpenSpace 3D Project manager
http://www.openspace3d.com
twilightzoney
Gnoblar
Posts: 6
Joined: Mon Jun 29, 2015 6:46 am

Re: Easy Ogre Exporter for 3DSMAX

Post by twilightzoney »

Ahh I don't remember having to do that before at all. But if that does work that way I'll set that up then.
twilightzoney
Gnoblar
Posts: 6
Joined: Mon Jun 29, 2015 6:46 am

Re: Easy Ogre Exporter for 3DSMAX

Post by twilightzoney »

I set a map to the second channel and did a scene export but it still removes and redos the 2nd UV Channel for me. Is there something I'm doing wrong here?
2015-07-01_1507.png
Its just really weird since I've never had this issue in the past. I don't suppose you keep archived versions of older plugins? Since I'm really not sure what the issue is.
You do not have the required permissions to view the files attached to this post.
Last edited by twilightzoney on Wed Jul 01, 2015 9:09 pm, edited 1 time in total.
arkeon
Goblin
Posts: 272
Joined: Fri Dec 04, 2009 6:02 pm
x 38

Re: Easy Ogre Exporter for 3DSMAX

Post by arkeon »

I don't know it should work ^^
I'll add this to test again on my todo list
OpenSpace 3D Project manager
http://www.openspace3d.com
twilightzoney
Gnoblar
Posts: 6
Joined: Mon Jun 29, 2015 6:46 am

Re: Easy Ogre Exporter for 3DSMAX

Post by twilightzoney »

I am using Max 2015 if that means anything at least.
arkeon
Goblin
Posts: 272
Joined: Fri Dec 04, 2009 6:02 pm
x 38

Re: Easy Ogre Exporter for 3DSMAX

Post by arkeon »

This is ok on my side

the same checkboard with 2 UV channels
Image

I think you should check your model converter.
OpenSpace 3D Project manager
http://www.openspace3d.com