Multiverse Network :: View topic - Effect of normal map
Multiverse - changing the < virtual > world


  FAQ Search Groups Profile Register Login  
Effect of normal map
Goto page Previous  1, 2, 3, 4  Next
 
Post new topic   Reply to topic
Multiverse Network Forum Index -> Modelling Issues and Discussion
View previous topic :: View next topic  
Author Message
Hamilton
Multiverse Moderator


Joined: 20 Feb 2006
Posts: 1043
Location: San Diego, CA USA

PostPosted: Tue Dec 29, 2009 7:16 pm    Post subject: Reply with quote

Going by your example, it would be like this:
Code:
material BaseMaterialTemplate
{
   technique
   {
      scheme Default
      pass
      {
         fog_override false
         alpha_rejection greater 128
         // Vertex program reference
         vertex_program_ref Examples/CompoundVS
         {
            param_named_auto FogSettings fog_params
            param_named_auto WorldViewProj worldviewproj_matrix
            param_named_auto WorldMatrix world_matrix
            param_named_auto LightPosition[0] light_position_object_space 0
            param_named_auto LightPosition[1] light_position_object_space 1
            param_named_auto LightAttenuation[0] light_attenuation 0
            param_named_auto LightAttenuation[1] light_attenuation 1
            param_named_auto EyePosition camera_position_object_space
         }
         fragment_program_ref Examples/CompoundPS_20_NSE
         {
            param_named LMe float4 0 0 0 1
            param_named_auto LMa ambient_light_colour
            param_named_auto LMd[0] light_diffuse_colour 0
            param_named_auto LMd[1] light_diffuse_colour 1
            param_named_auto LMs[0] light_specular_colour 0
            param_named_auto LMs[1] light_specular_colour 1
            param_named shininess float 10
         }
         // Normal map
         texture_unit NormalMap
         {
            texture_alias NormalMap
            texture NormalFileName.dds
            tex_coord_set 0
            filtering anisotropic anisotropic linear
            max_anisotropy 8
         }
         // Specular map
         texture_unit SpecularMap
         {
            texture_alias SpecularMap
            texture SpecularFileName.dds
            tex_coord_set 1
            filtering anisotropic anisortopic linear
            max_anisotropy 8
         }
         // Diffuse map
         texture_unit DiffuseMap
         {
            texture_alias DiffuseMap
            texture DiffuseFileName.dds
            tex_coord_set 2
            filtering anisotropic anisotropic linear
            max_anisotropy 8
         }
         // Emissive map
         texture_unit EmissiveMap
         {
            texture_alias EmissiveMap
            texture EmissiveFileName.dds
            tex_coord_set 3
         }
      }
   }
}


Note some changes:
- I put alpha_rejection greater 128 after the Fog line and removed it from each of the texture maps. That should work just the same with less lines of code.
- I removed the filtering and anisotropy from the Emissive Map section since emissive is something like a glow and does not need the extra resources for it (but put it back in if you like).


2nd Part
Individual Material File Example used on each object:
Code:
material ABCOBJECT : BaseMaterialTemplate
{
   set_texture_alias NormalMap abcobjectNMap.dds
   set_texture_alias DiffuseMap abcobjectDiff.dds
   set_texture_alias SpecularMap abcobjectSpecMap.dds
   set_texture_alias EmissiveMap abcobjectEmisMap.dds
}

_________________
Sign off,
Hamilton

“We used to dream about this stuff. Now, we get to build it. It's pretty neat." - Steve Jobs
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Flapman



Joined: 04 Dec 2008
Posts: 158
Location: Colorado Springs, CO

PostPosted: Tue Dec 29, 2009 7:30 pm    Post subject: Reply with quote

You Rock!!!

Now in theory this really could be used as a template and the default emit map could be set to all black until you needed one. Smile


Hamilton wrote:
Going by your example, it would be like this:
Code:
material BaseMaterialTemplate
{
   technique
   {
      scheme Default
      pass
      {
         fog_override false
         alpha_rejection greater 128
         // Vertex program reference
         vertex_program_ref Examples/CompoundVS
         {
            param_named_auto FogSettings fog_params
            param_named_auto WorldViewProj worldviewproj_matrix
            param_named_auto WorldMatrix world_matrix
            param_named_auto LightPosition[0] light_position_object_space 0
            param_named_auto LightPosition[1] light_position_object_space 1
            param_named_auto LightAttenuation[0] light_attenuation 0
            param_named_auto LightAttenuation[1] light_attenuation 1
            param_named_auto EyePosition camera_position_object_space
         }
         fragment_program_ref Examples/CompoundPS_20_NSE
         {
            param_named LMe float4 0 0 0 1
            param_named_auto LMa ambient_light_colour
            param_named_auto LMd[0] light_diffuse_colour 0
            param_named_auto LMd[1] light_diffuse_colour 1
            param_named_auto LMs[0] light_specular_colour 0
            param_named_auto LMs[1] light_specular_colour 1
            param_named shininess float 10
         }
         // Normal map
         texture_unit NormalMap
         {
            texture_alias NormalMap
            texture NormalFileName.dds
            tex_coord_set 0
            filtering anisotropic anisotropic linear
            max_anisotropy 8
         }
         // Specular map
         texture_unit SpecularMap
         {
            texture_alias SpecularMap
            texture SpecularFileName.dds
            tex_coord_set 1
            filtering anisotropic anisortopic linear
            max_anisotropy 8
         }
         // Diffuse map
         texture_unit DiffuseMap
         {
            texture_alias DiffuseMap
            texture DiffuseFileName.dds
            tex_coord_set 2
            filtering anisotropic anisotropic linear
            max_anisotropy 8
         }
         // Emissive map
         texture_unit EmissiveMap
         {
            texture_alias EmissiveMap
            texture EmissiveFileName.dds
            tex_coord_set 3
         }
      }
   }
}


Note some changes:
- I put alpha_rejection greater 128 after the Fog line and removed it from each of the texture maps. That should work just the same with less lines of code.
- I removed the filtering and anisotropy from the Emissive Map section since emissive is something like a glow and does not need the extra resources for it (but put it back in if you like).


2nd Part
Individual Material File Example used on each object:
Code:
material ABCOBJECT : BaseMaterialTemplate
{
   set_texture_alias NormalMap abcobjectNMap.dds
   set_texture_alias DiffuseMap abcobjectDiff.dds
   set_texture_alias SpecularMap abcobjectSpecMap.dds
   set_texture_alias EmissiveMap abcobjectEmisMap.dds
}
Back to top
View user's profile Send private message Visit poster's website
Hamilton
Multiverse Moderator


Joined: 20 Feb 2006
Posts: 1043
Location: San Diego, CA USA

PostPosted: Tue Dec 29, 2009 10:20 pm    Post subject: Reply with quote

Thanks. Smile

I found a good article on the Ogre3D Wiki of using Glow effects. I'm making another thread for it as I figure there is going to be some things to iron out to make it work with the MV Client.
_________________
Sign off,
Hamilton

“We used to dream about this stuff. Now, we get to build it. It's pretty neat." - Steve Jobs
Back to top
View user's profile Send private message Send e-mail Visit poster's website
lorenze1



Joined: 20 Aug 2009
Posts: 44
Location: Russian Federation

PostPosted: Wed Dec 30, 2009 2:17 am    Post subject: Reply with quote

Cool
In addition
http://www.ogre3d.org/wiki/index.php/Normal_AO_Specular_Mapping_Shader
and about parallax

[url]http://www.ogre3d.org/wiki/index.php/PerPixel_Lighting_With_Offset(Parallax)_Mapping[/url]
_________________
Gott mit uns.
Sibi imperare maximum imperium est
Back to top
View user's profile Send private message Visit poster's website
Flapman



Joined: 04 Dec 2008
Posts: 158
Location: Colorado Springs, CO

PostPosted: Wed Dec 30, 2009 6:28 am    Post subject: Reply with quote

Thanks guys,

I went ahead and bookmarked the Orge Wiki Site for reference.

Ham, I'll look forward to that thread too. Smile

A
Back to top
View user's profile Send private message Visit poster's website
Hamilton
Multiverse Moderator


Joined: 20 Feb 2006
Posts: 1043
Location: San Diego, CA USA

PostPosted: Wed Dec 30, 2009 12:16 pm    Post subject: Reply with quote

lorenze1 wrote:
Cool
In addition
...

From looking at the Parallax set, that may be the method to use to solve the problem effect of the Normal Map, rather than of the places I was looking at. There are some other associated links with PerPixel Lighting that seems helpful as well. May be very possible to create LOD's for the shaders to allow for high quality up close and low quality farther away, since the material scripts allow for LOD's.
_________________
Sign off,
Hamilton

“We used to dream about this stuff. Now, we get to build it. It's pretty neat." - Steve Jobs
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Hamilton
Multiverse Moderator


Joined: 20 Feb 2006
Posts: 1043
Location: San Diego, CA USA

PostPosted: Wed Dec 30, 2009 12:19 pm    Post subject: Reply with quote

Flapman wrote:
...
Ham, I'll look forward to that thread too. Smile
A

I went ahead and posted it in the Client Script section since technically shaders are scripts...
http://update.multiverse.net/forum/viewtopic.php?t=6273&theme=multiverse

But, shaders are also related to models.

What would be the best section for Shaders (both for the model objects and Post Renderings (compositors))?
_________________
Sign off,
Hamilton

“We used to dream about this stuff. Now, we get to build it. It's pretty neat." - Steve Jobs
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Hamilton
Multiverse Moderator


Joined: 20 Feb 2006
Posts: 1043
Location: San Diego, CA USA

PostPosted: Thu Dec 31, 2009 1:20 pm    Post subject: Reply with quote

The following code may help to bring more out of the Normal Mapping. However at this time I have not tested it as the machine I'm working with does not support 2.0 Shaders (it is a laptop only for productivity). I'll try it out later, but if anyone wants to take a shot of it today...


In the DiffuseBump.cg file (in the GpuPrograms folder), search for the Fragment Program you are using for the given model.
Example (copy one of the following below that you are using and paste to Find it in the file):
CompoundPS_20_N
CompoundPS_20_NS
CompoundPS_20_NSE

Then Search for the following code:
It should be located right after the first brace "{"
Code:
float3 normal = normalize(expand(tex2D(NormalMap, IN.texCoord).rgb));


Replace that code with the following lines of code (Copy and Replace):
Code:
float3 normal = tex2D(NormalMap, IN.texCoord);
normal.xy = 2*normal.xy - 1;
normal.z = sqrt(1.0 - dot(normal.xy,normal.xy));


Save and execute the test.
Hopefully with the doubling and the square root, should have greater effect.
_________________
Sign off,
Hamilton

“We used to dream about this stuff. Now, we get to build it. It's pretty neat." - Steve Jobs
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Hamilton
Multiverse Moderator


Joined: 20 Feb 2006
Posts: 1043
Location: San Diego, CA USA

PostPosted: Sat Jan 02, 2010 1:08 pm    Post subject: Reply with quote

I ran several different tests with the Normal Equations posted above and found very little if any difference. I'll post some of the results later in the day.

There is also a problem with the Emissive Fragment Program (CompoundPS_20_NSE), which even when using a mostly black texture file will still cause the mesh to become lighter (less shadowing effect). When making a correction to an equation, the whole mesh, save for the areas to glow, turns black. Seems that in order for Emissive to work properly on a complete mesh, that both the texture file and code need some work.

As of right now, the correction of the code (CompoundPS_20_NSE) is done as follows:
Original
Code:
float4 color = emissiveTex + LMa * diffuseTex;

Correction
Code:
float4 color = (emissiveTex + LMa) * diffuseTex;


For the Emissive Texture File:
Use the Diffuse Texture File, then make two layers (need a paint or photo editor program):
Layer 1 - Areas that are to glow
Layer 2 - Complete Black Layer with what seems to be an Opacity of 31% (not certain yet, still tweaking)
Layer 3 - Original Diffuse Texture Image

Then merge/flatten the image file as the Emissive file.



If this is hard to follow, just wait a bit when I start posting some images.
_________________
Sign off,
Hamilton

“We used to dream about this stuff. Now, we get to build it. It's pretty neat." - Steve Jobs
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Flapman



Joined: 04 Dec 2008
Posts: 158
Location: Colorado Springs, CO

PostPosted: Sat Jan 02, 2010 5:03 pm    Post subject: Reply with quote

That is pretty interesting. So as I can see from what you are describing, unless there is a need for glow, stay away form it....kidding. Smile

In any case, no need to include emissive in the master texture file unless it is really needed right?

Thanks for testing all this.

Hamilton wrote:
I ran several different tests with the Normal Equations posted above and found very little if any difference. I'll post some of the results later in the day.

There is also a problem with the Emissive Fragment Program (CompoundPS_20_NSE), which even when using a mostly black texture file will still cause the mesh to become lighter (less shadowing effect). When making a correction to an equation, the whole mesh, save for the areas to glow, turns black. Seems that in order for Emissive to work properly on a complete mesh, that both the texture file and code need some work.

As of right now, the correction of the code (CompoundPS_20_NSE) is done as follows:
Original
Code:
float4 color = emissiveTex + LMa * diffuseTex;

Correction
Code:
float4 color = (emissiveTex + LMa) * diffuseTex;


For the Emissive Texture File:
Use the Diffuse Texture File, then make two layers (need a paint or photo editor program):
Layer 1 - Areas that are to glow
Layer 2 - Complete Black Layer with what seems to be an Opacity of 31% (not certain yet, still tweaking)
Layer 3 - Original Diffuse Texture Image

Then merge/flatten the image file as the Emissive file.



If this is hard to follow, just wait a bit when I start posting some images.
Back to top
View user's profile Send private message Visit poster's website
Hamilton
Multiverse Moderator


Joined: 20 Feb 2006
Posts: 1043
Location: San Diego, CA USA

PostPosted: Fri Jan 08, 2010 10:34 am    Post subject: Reply with quote

Well I thought I would get those images put up about a week ago, but wanted to get a shader without using the Normal Map to work properly. I thought it would just take some hours, not a week... well minus other interruptions in life. Now that has been figured out, I will be getting those images up shortly.

Some notes:
- Getting the Normal to have more effect/impact looks like it will require more use of lights and render passes. This would improve the quality but will degrade FPS (frame per second). I'm putting together a three light with two pass shader based on the Parallax example to see if that will improve things.

- The problem with the Emissive mapping of making the model lighter can be solved in two manners it seems. Either by using a black overlay in the photo/image editor of about 25% to 33% for the emissive texture or adjusting the following equation to produce less color:
Original Code:
Code:
float4 color = emissiveTex + LMa * diffuseTex;

1st Attempted Adjustment:
Code:
float4 color = (emissiveTex + LMa) * diffuseTex;

2nd Attempted Adjustment:
Code:
float4 color = (emissiveTex + LMa) * diffuseTex * 0.66;


The 0.66 reduces the overall Color by 34%. Note this equation is a preparatory equation of making the Color from the Emissive Texture File, Ambient Lighting and Diffuse Texture File.
Further down in the code, the Color is readjusted by the use of lights, normal and specular mapping. So although there is a 34% reduction in color in the preparatory equation, it does not impact the output of the overall color by 34%.


- I'll be providing the codes (which they are modified MV shader codes mostly, nothing spectacular on my part) to allow for the use of both Static and Skinned Models for use of:
--- Diffuse Only (but looks like the default Diffuse material file (software shader) provides the best performance)
--- Diffuse and Normal
--- Diffuse and Specular
--- Diffuse and Emissive
--- Diffuse, Normal and Specular
--- Diffuse, Normal and Emissive
--- Diffuse, Normal, Specular and Emissive

- Then hopefully the Ambient, Shadow and Parallax Shader
- And finally Material Shader LOD (Level of Detail) capability, that is to downgrade the quality of the shader based on visual range. The material script already supports this via LOD command. I would only be providing the example templates.
_________________
Sign off,
Hamilton

“We used to dream about this stuff. Now, we get to build it. It's pretty neat." - Steve Jobs
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Hamilton
Multiverse Moderator


Joined: 20 Feb 2006
Posts: 1043
Location: San Diego, CA USA

PostPosted: Fri Jan 08, 2010 11:14 am    Post subject: Reply with quote

Provided below are some screenshots I took while dealing with those shaders. Hopefully it will provide some help. The images below are thumbnails to avoid slowing down these forums. Just click on the thumbnail to view the original image.

Note: Shininess is set to 25 for all images

Reference File:
This is the Default Software Shader to be used as a Reference for the rest.


Original Diffuse and Normal Shader:


Modified Diffuse and Normal Shader:
This is changing the equation of the Normal to use double and SQRT, as you can see there was no change. I performed other tests with filtering, but had the same results.


Diffuse and Normal Shader LLL 16:
Filtering of Linear Linear Linear and max_anisotropy set to 16


Diffuse and Normal Shader AAL 16:
Filtering of Anisotropic Anisotropic Linear and max_anisotropy set to 16
There is a slight difference... the best place to look is on the top surface of the lower left missile pod.

_________________
Sign off,
Hamilton

“We used to dream about this stuff. Now, we get to build it. It's pretty neat." - Steve Jobs
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Hamilton
Multiverse Moderator


Joined: 20 Feb 2006
Posts: 1043
Location: San Diego, CA USA

PostPosted: Fri Jan 08, 2010 11:43 am    Post subject: Reply with quote

The following is of the Emissive Shader

Note: Shininess is set to 25 for all images

Reference Image:
Original Diffuse, Normal and Specular Shader
The goal here is to keep the model as is, but make that blue sensor (in the middle of the missile launcher) brighter.
Filtering of Anisotropic Anisotropic Linear and max_anisotropy set to 16


Original Diffuse, Normal, Specular, Emissive Shader:
Notice that even when using an all black with a blue glow for the emissive texture file, the model is lighter overall. The Blue Glow for the sensor is there... but now the whole model is brighter!
Filtering of Anisotropic Anisotropic Linear and max_anisotropy set to 16


Diffuse, Normal, Specular, Emissive Shader w/Alpha:
So how about just making most of the Emissive Texture file transparent (Alpha Channeling)? Well this is what happened...
Filtering of Linear Linear Linear and max_anisotropy set to 16


Diffuse, Normal, Specular, Emissive Shader w/Alpha Reject:
And when plugging in the Alpha Reject 128 into the material code...
Filtering of Linear Linear Linear and max_anisotropy set to 16

But at least the sensor is a blue glow...

Modified Diffuse, Normal, Specular, Emissive Shader:
This is what happened when adjusting/fixing the Color Equation to:
Code:
float4 color = (emissiveTex + LMa) * diffuseTex;

Filtering of Linear Linear Linear and max_anisotropy set to 16

That didn't work... the whole model but the sensor is black...

Modified Diffuse, Normal, Specular, Emissive Shader w/30% Black Overlay:
Using the same adjusted/fixed equation, the Emissive Map was changed. I used the Diffuse Texture File and added a Black 30% overlay (or you could say, darkened it by 30%. Then added the blue glow on top of it.
Filtering of Linear Linear Linear and max_anisotropy set to 16

Its close to the original DNS Shader, but not exactly there yet.

So I'm thinking the 0.66 multiplier added to the Color equation should solve it and remove the need of a Black Overlay.



The reason for getting the DNSE Shader to match as close as possible to the DNS shader (as well as others) is for the use of LOD's. For example, I want the model to appear without the blue sensor glow past 25 meters, but still want the Normal and Specular. Since it is just such a small item that requires another texture file, it is not that important at ranges. Thus performance will improve the farther the missile launcher is away.
So when the missile launcher changes shaders from DNS to DNSE (or opposite) there is very little noticeable effect.
_________________
Sign off,
Hamilton

“We used to dream about this stuff. Now, we get to build it. It's pretty neat." - Steve Jobs
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Flapman



Joined: 04 Dec 2008
Posts: 158
Location: Colorado Springs, CO

PostPosted: Fri Jan 08, 2010 10:16 pm    Post subject: Reply with quote

Very cool examples Ham. I learned a lot there. I'll have to come back to this and really try to digest it so I figure out will create the best effect for me.

Thanks for doing all that testing.

I guess what I need to figure out is how this relates to my material files and setting them up properly. Would I redo my Material Template file? Would I have templates (one for non emissive models and one for those that are)?

All in all I like the last example:
Modified Diffuse, Normal, Specular, Emissive Shader w/30% Black Overlay:

If I can make that the standard for all the models, that would be cool. I would just need to learn how. Smile
Back to top
View user's profile Send private message Visit poster's website
Hamilton
Multiverse Moderator


Joined: 20 Feb 2006
Posts: 1043
Location: San Diego, CA USA

PostPosted: Sat Jan 09, 2010 1:29 pm    Post subject: Reply with quote

Not a problem, I'll be providing a wiki entry of explaining and how to use the shaders. I've got the Static Mesh Shaders completed and tested, now need to test the Skinned shaders.

I have redone the DiffuseBump.cg and Multiverse.program files for better organization and of some corrections.

For example, I found out what was causing the Emissive problem and from a standard programing sense, there seems to be nothing wrong with it. What has happened is that the order of the equations of maps was not in proper order. It appears that the Emissive Map was the Diffuse Map (as well as missing the parentheses for the color equation). I can't explain it other than a mismatch of the Texture Coordinates.
Original Code in the DNSE:
Code:
float4 emissiveTex = tex2D(EmissiveMap, IN.texCoord);
float4 diffuseTex = tex2D(DiffuseMap, IN.texCoord); // rgba
float4 color = emissiveTex + LMa * diffuseTex;

Correction:
Code:
float4 diffuseTex = tex2D(DiffuseMap, IN.texCoord); // rgba
float4 emissiveTex = tex2D(EmissiveMap, IN.texCoord);
float4 color = (emissiveTex + LMa) * diffuseTex;


(Click on the image for a larger view)

Examples
Default DNSE Shader


Swapping the order of the Emissive and Diffuse


And then correcting the Color Equation with ()



And just for you Flapman, I've changed that number of 0.66 in the color equation to use as a variable named Amplifier. It will be in the Material file, so you can make adjustments. Below is setting the Amplifier to 2 (a multiplier of 2).

_________________
Sign off,
Hamilton

“We used to dream about this stuff. Now, we get to build it. It's pretty neat." - Steve Jobs
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Multiverse Network Forum Index -> Modelling Issues and Discussion All times are GMT - 7 Hours
Goto page Previous  1, 2, 3, 4  Next
Post new topic   Reply to topic
Page 3 of 4

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2002 phpBB Group