Version 0.320 - ship rendering, lighting and shaders

Programmers discuss here anything related to FreeOrion programming. Primarily for the developers to discuss.

Moderator: Committer

Message
Author
User avatar
strooka
Space Kraken
Posts: 165
Joined: Tue Jun 23, 2009 5:34 pm
Location: Bielefeld, Germany

Version 0.320 - ship rendering, lighting and shaders

#1 Post by strooka »

:arrow: Version 0.320 issues go here!

User avatar
pd
Graphics Lead Emeritus
Posts: 1924
Joined: Mon Mar 08, 2004 6:17 pm
Location: 52°16'N 10°31'E

Re: Version 0.320 - ship rendering, lighting and shaders

#2 Post by pd »

Here is a mockup breaking down the lighting and shader.
Image

Lighting:
We are using a 2 point setup, it's simple and effective. This means there is a key light and an opposing fill light. The star is always the key light.
A fill light helps to define the forms, adds mood and helps to integrate the object in its environment. Unlike the key light, there can't be a single fill light, that works for every ship, because where the fill light is positioned depends on the position of the ship in relation to the star. So every ship need's it's own fill light. I'm not sure how you would approach this situation in Ogre, but I can think of two scenarios:

1. every ship get's it's own fill light, that only affects this very ship, and no other game object
2. a shader effect, that simulates a fill light, depending on the shading done by the key light(maybe somehow inverting it?)

Just brightening the shadow side with a color(=ambient light) should be avoided, because it flattens out the form and generally looks bad.

The color of the fill light should be defined using an external text file, probably in the same folder as the skybox textures, because it will be based on the dominating color in each of the skybox texture sets(they will be monochromatic mostly).


Shader:
Four texture maps are used: a color map, a specular map, a glow map and a normal bump map. The mockup shows how each map would look when applied exclusively(using a 50% grey as color).

If you could write a shader, that also supports a transparency map in addition to the other 4 maps, that would be a bonus.

Here's is also a mockup how this should look ingame, when everything is done correctly(scale exaggerated):
Image

User avatar
strooka
Space Kraken
Posts: 165
Joined: Tue Jun 23, 2009 5:34 pm
Location: Bielefeld, Germany

Re: Version 0.320 - ship rendering, lighting and shaders

#3 Post by strooka »

pd as we chatted, i commit you now a basic .material file setting up the shader.
you wanted to set up the shader.
all you have to do is to implement multitexturing, the first map is already implemented.
look here:
Image

it shows the "guardian_normal" texture.

i commit you the files so that you can compile fo to try out editing the .material file.
Attachments
Combat.tar.gz
the combat files
(18.24 KiB) Downloaded 51 times

User avatar
pd
Graphics Lead Emeritus
Posts: 1924
Joined: Mon Mar 08, 2004 6:17 pm
Location: 52°16'N 10°31'E

Re: Version 0.320 - ship rendering, lighting and shaders

#4 Post by pd »

You got something wrong there. I said I can edit shader files, once they are completed - you know, tweaking a number here and there, but that's it. I won't implement anything and I also won't compile the game myself. I'm not a programmer.
Btw, why does your guardian.material look so different compared to tzlaine's ship.material?


If your example is supposed to show the normal bump texture, than something clearly doesn't work, have a look at the bottom right image in the first mockup and notice the details the normal map brings out.


edit: My guess is, we'll need something along the lines of this.

edit2: I actually did some reading on shader(GLSL) programming and found out, that a 2 point lighting setup, can be realized with just one lightsource by inverting the normal. If you need more information on this, message me.

User avatar
strooka
Space Kraken
Posts: 165
Joined: Tue Jun 23, 2009 5:34 pm
Location: Bielefeld, Germany

Re: Version 0.320 - ship rendering, lighting and shaders

#5 Post by strooka »

I don't Know how to setup à 2 Way Lightning setup.
Question: what do you do when there are more than One ships there?
There wouldn't Be à Solution.
However i'll supply in à Few hours à New pic how far i am.
It is all Inside it. I am so far that for à System the Combat will Be started and the Player has the possibility to Place His ships. Altough they cant Be Set right now.
Question: what Solution do you prefer when the Combat Starts- predefined Start points or costomizable by placing your ships?

By the Way: i have Advanced Code with the hotkeymanager and this now. How do i commit my Code to the database?
It seems that geoff doesnt have the Time to add it to the project, and what about putting me on the creators List ?

User avatar
pd
Graphics Lead Emeritus
Posts: 1924
Joined: Mon Mar 08, 2004 6:17 pm
Location: 52°16'N 10°31'E

Re: Version 0.320 - ship rendering, lighting and shaders

#6 Post by pd »

strooka wrote:I don't Know how to setup à 2 Way Lightning setup.
Question: what do you do when there are more than One ships there?
There wouldn't Be à Solution.
I think I've covered this. Either each ship get's it's own lightsource, that works only on that particular ship. Or, and that's probably the better solution in terms of resource efficiency, a shader "trick" has to be found. Also note my more recent edit2 about inverting surface normals. I thought you were the guy interested in graphics programming?

Anyway, here is some more info on this:
To mimic OpenGL's two-sided lighting behavior, you need to invert the surface normal and perform the same computations as defined in the preceding section using the back-facing material properties. You can probably do it more cleverly than this, but it might look like this:

Code: Select all

normal = -normal;

// Clear the light intensity accumulators

amb  = vec4 (0.0);

diff = vec4 (0.0);

spec = vec4 (0.0);



// Loop through enabled lights, compute contribution from each

for (i = 0; i < NumEnabledLights; i++)

{

    if (gl_LightSource[i].position.w == 0.0)

        DirectionalLight(i, normal, amb, diff, spec);

    else if (gl_LightSource[i].spotCutoff == 180.0)

        PointLight(i, eye, ecPosition3, normal, amb, diff, spec);

    else

        SpotLight(i, eye, ecPosition3, normal, amb, diff, spec);

}



color = gl_BackLightModelProduct.sceneColor +

        amb * gl_BackMaterial.ambient +

        diff * gl_BackMaterial.diffuse;



if (SeparateSpecular)

    gl_BackSecondaryColor = vec4 (spec *

                                  gl_BackMaterial.specular, 1.0);

else

    color += spec * gl_BackMaterial.specular;



gl_BackColor = color;
There is no need to perform clamping on the values assigned to gl_BackSecondaryColor and gl_BackColor because these will be clamped automatically by definition.
Question: what Solution do you prefer when the Combat Starts- predefined Start points or costomizable by placing your ships?
There has to be a way to place ships before combat eventually, but for now, just load a couple of ships somewhere. It doesn't really matter at this point.
By the Way: i have Advanced Code with the hotkeymanager and this now. How do i commit my Code to the database?
It seems that geoff doesnt have the Time to add it to the project, and what about putting me on the creators List ?
I don't decide these things. If the code meets Geoff's standards and does what it is supposed to do, I'm sure he will commit it or provide SVN access.

p.s. Check your pm's.

User avatar
strooka
Space Kraken
Posts: 165
Joined: Tue Jun 23, 2009 5:34 pm
Location: Bielefeld, Germany

Re: Version 0.320 - ship rendering, lighting and shaders

#7 Post by strooka »

ok, here is, what i've found out and readied up yet:
Image
it shows placing of a ship in 3d combat mode while playing the game.

User avatar
pd
Graphics Lead Emeritus
Posts: 1924
Joined: Mon Mar 08, 2004 6:17 pm
Location: 52°16'N 10°31'E

Re: Version 0.320 - ship rendering, lighting and shaders

#8 Post by pd »

Fascinating :) Can I get a closeup and also see the unlit side?

User avatar
strooka
Space Kraken
Posts: 165
Joined: Tue Jun 23, 2009 5:34 pm
Location: Bielefeld, Germany

Re: Version 0.320 - ship rendering, lighting and shaders

#9 Post by strooka »

Shields
Image

User avatar
pd
Graphics Lead Emeritus
Posts: 1924
Joined: Mon Mar 08, 2004 6:17 pm
Location: 52°16'N 10°31'E

Re: Version 0.320 - ship rendering, lighting and shaders

#10 Post by pd »

I don't like it. You should have asked for a mockup... Instead of using a scaled up version of the ship mesh it's probably better to use either an ellipsoid or a seperate simplified shield mesh, fitted around the ship. The shield shader could be build similar to an atmosphere shader, being more visible as the surface normal turns away(fresnel effect).

Anyway, I noticed the specular map isn't part of the ship's shader. Are you going to add it? Also how is the 2 point lighting comming along? How about the FPS test? Let's first get the basics down, before we play with effects.

User avatar
strooka
Space Kraken
Posts: 165
Joined: Tue Jun 23, 2009 5:34 pm
Location: Bielefeld, Germany

Re: Version 0.320 - ship rendering, lighting and shaders

#11 Post by strooka »

i have written a cg program that computes a simplified shape around the ship. but then i have problems with transparency. i'll go back to this problem later.

since there are already 1000 asteroids in object space and it is running still fast, i think there won't be a problem to add 250 more objects.

Code: Select all

        modified_material = ship_material->clone(modified_material_name);
        modified_material->getTechnique(0)->getPass(0)->getTextureUnitState(0)->
            setTextureName(ship.Design()->Model() + "_Color.png");
        modified_material->getTechnique(0)->getPass(0)->getTextureUnitState(1)->
            setTextureName(ship.Design()->Model() + "_Glow.png");
        modified_material->getTechnique(0)->getPass(0)->getTextureUnitState(2)->
            setTextureName(ship.Design()->Model() + "_Normal.png");
        modified_material->getTechnique(0)->getPass(0)->getTextureUnitState(3)->
            [b]setTextureName(ship.Design()->Model() + "_Specular.png");[/b]
the map is part of the material, as you see.

i don't think that we should use all highlights with that effect.

User avatar
pd
Graphics Lead Emeritus
Posts: 1924
Joined: Mon Mar 08, 2004 6:17 pm
Location: 52°16'N 10°31'E

Re: Version 0.320 - ship rendering, lighting and shaders

#12 Post by pd »

strooka wrote: since there are already 1000 asteroids in object space and it is running still fast, i think there won't be a problem to add 250 more objects.
The asteroids are rendered using Paged Geometry, which is originally intended for huge amounts of trees. We can't use this for ships. Besides, the asteroid meshes have just a fraction of the polygon count of a ship.

Please do some FPS tests.
the map is part of the material, as you see.
I don't see it in the screenshots and that's what counts to me. Check out my mockup/renderings. The specular map masks out the reflection of the lightsource, which gives it a nice metalic effect. To get something similar to the mockups, you would probably also increase the specular intensity(gloss?). It looks quite dull at the moment.
The code snipet you've posted doesn't actually do anything, besides asigning textures to techniques. Where is the part, that determines how the texture influences speculars?
I don't think that we should use all highlights with that effect.
What are you talking about?


Please realize that this is a team effort. There should be a lot more communication, especially between both of us, since your current work involves a big visual part.

User avatar
strooka
Space Kraken
Posts: 165
Joined: Tue Jun 23, 2009 5:34 pm
Location: Bielefeld, Germany

Re: Version 0.320 - ship rendering, lighting and shaders

#13 Post by strooka »

I don't think that we should use all highlights with that effect.

What are you talking about?
i meant, when hilighting an object, for example when it is selected, i prefer a simple alpha factor yellow paint of the object.
I don't see it in the screenshots and that's what counts to me. Check out my mockup/renderings. The specular map masks out the reflection of the lightsource, which gives it a nice metalic effect. To get something similar to the mockups, you would probably also increase the specular intensity(gloss?). It looks quite dull at the moment.
The code snipet you've posted doesn't actually do anything, besides asigning textures to techniques. Where is the part, that determines how the texture influences speculars?
the code shows that the specular map is loaded. and i ve seen it like in your demo. i could change the refletion mask to make it more shiny.

fps tests are in the current stadium of the program not possible cause i have to make a savegame where are about 250 ships in combat, and solving the combat is dysfunctional, cause the end combat signal isn't properly computed.

if someone has a savegame with huge amounts of ships plz post it here.

User avatar
pd
Graphics Lead Emeritus
Posts: 1924
Joined: Mon Mar 08, 2004 6:17 pm
Location: 52°16'N 10°31'E

Re: Version 0.320 - ship rendering, lighting and shaders

#14 Post by pd »

strooka wrote: i meant, when hilighting an object, for example when it is selected, i prefer a simple alpha factor yellow paint of the object.
Well, there are numerous way's we could highlight selected objects. It's probably a good idea to explore in mockups. I've added this to 0.322. I'll write an introduction to both 0.322 and 0.321 when 0.320 is done.
i could change the refletion mask to make it more shiny.
That's one of the reasons I asked for closeups earlier. I need to evaluate your results and provide feedback, but I can't do this, if you don't provide images. But making it shinier is probably a good idea.
fps tests are in the current stadium of the program not possible cause i have to make a savegame where are about 250 ships in combat, and solving the combat is dysfunctional, cause the end combat signal isn't properly computed.

if someone has a savegame with huge amounts of ships plz post it here.
Wouldn't it be much easier to do this, if the techdemo and client were still separate?

User avatar
Bigjoe5
Designer and Programmer
Posts: 2058
Joined: Tue Aug 14, 2007 6:33 pm
Location: Orion

Re: Version 0.320 - ship rendering, lighting and shaders

#15 Post by Bigjoe5 »

strooka wrote:if someone has a savegame with huge amounts of ships plz post it here.
You can go into "starting_fleets.txt" and make it so each player starts with any desired number/design of ships.
Warning: Antarans in dimensional portal are closer than they appear.

Post Reply