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

Re: Version 0.320 - ship rendering, lighting and shaders

#16 Post by strooka »

K,thx but i' ve already Found à Way to create huge amounts of ships. Pd, you will get your Infos Tomorrow.

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

#17 Post by strooka »

here are the results of the heavy load FPS test:
i ran it on a acer laptop with a radeon HD 2600, a intel Core 2 Duo Processor with approxemately 2.2 GHZ frequency and 2Gig RAM. Operating System - Suse Linux 11.2.
the test was made in windowed mode. at a resolution of 800x600.
the code was compiled as debug version.

The results:
0 ships : 88 FPS
50 ships : 54 FPS
100 ships : 39 FPS
150 ships : 30 FPS

the directional light doesn't work yet, i have to work a little bit more on the shader code and test it.

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

#18 Post by pd »

0 ships : 88 FPS
50 ships : 54 FPS
100 ships : 39 FPS
150 ships : 30 FPS
Thanks for testing, I was quite sure it would have an impact. I would expect different results at my system(I get 200-250fps with 0 ships) which has a recent graphics card(geforce gtx 260).

But we can work with 50 ships for now, that's quite a lot already. Also I don't think there's any dynamic LOD calculations happening right now, since I didn't include this ability when exporting the meshes. I could be wrong though and maybe Ogre does this all by itself?

I'm looking forward to the updated shaders.

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

#19 Post by pd »

Any updates? Could you provide a patch of the changes you've made, including the shader files? Screenshots are welcome too.

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

#20 Post by strooka »

There are some Updates:
2 Point Lightning doesnt work yet and i don't want to put more work in it.
Client- Server endcombat Message - defunctional.
Parallax scrolling of Galaxy Background - defunctional since there is à max Range for displaying meshes and there may Be onl 1 Sky Box.
Moving - Not fully implemented yet, but in Common.

I'm concentrating me on moving and Grid Display now.
Animating wont Be invoked right now and i've some Code for displaying meshes made in Code.
Once i have the Grid, i could modify it for ground Combat and Place some mechs on it that i imported and Full it with textures so that it Looks like à Planet.

I have at least Found out an Option for the shader - Why don't increase the ambient color then they would Be much better Seen.

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

#21 Post by strooka »

here is a possible setup for the 2 point lightning:

Image
Image


ship.vert

Code: Select all

// -*- C++ -*-
varying vec3 v_V;
varying vec3 v_N;
uniform vec3 camera_pos;

varying vec3 half_angle;
varying vec3 light_dir;
varying float raw_diffuse;

void main()
{
    vec3 light_pos = vec3(gl_LightSource[0].position);
    vec3 tangent = cross(vec3(0.0, 0.0, 1.0), gl_Normal);
    vec3 binormal = cross(gl_Normal, tangent);
    mat3 tangent_space = mat3(tangent, binormal, gl_Normal);
    vec3 eye_dir = normalize(camera_pos) * tangent_space;

    light_dir = normalize(light_pos) * tangent_space;
    half_angle = normalize(eye_dir + light_dir);
    raw_diffuse = max(dot(normalize(light_pos), gl_Normal), 0.0);

    gl_TexCoord[0].st = vec2(gl_MultiTexCoord0);

    gl_Position = ftransform();
    v_V = (gl_ModelViewMatrix * gl_Vertex).xyz;
    v_N = gl_NormalMatrix * gl_Normal;

    vec3 bcolor = gl_FrontMaterial.specular.bbb;

    gl_BackColor = vec4(bcolor, 1.0);


}
ship.frag

Code: Select all

// -*- C++ -*-
varying vec3 v_V;
varying vec3 v_N;
varying vec3 half_angle;
varying vec3 light_dir;
varying float raw_diffuse;
uniform sampler2D color_texture, glow_texture, normal_texture, specular_gloss_texture;
uniform vec3 star_light_color, skybox_light_color;


void main()
{
    vec2 sg = texture2D(specular_gloss_texture, gl_TexCoord[0].st).rg;
    const float MIN_SPECULAR_EXPONENT = 16.0;
    const float MAX_SPECULAR_EXPONENT = 32.0;
    float specular_exponent =
        MIN_SPECULAR_EXPONENT + sg.r * (MAX_SPECULAR_EXPONENT - MIN_SPECULAR_EXPONENT);
    float gloss = 1.0;//sg.g; // TODO: change this when we get a gloss map

    vec3 normal = texture2D(normal_texture, gl_TexCoord[0].st).xyz * 2.0 - 1.0;

 
    float specular = pow(max(dot(normal, half_angle), 0.0), specular_exponent) * raw_diffuse;

    vec3 diffuse_color = texture2D(color_texture, gl_TexCoord[0].st).rgb;
    vec3 glow_color = texture2D(glow_texture, gl_TexCoord[0].st).rgb;

    float diffuse = max(dot(normal, light_dir), 0.2);

    vec3 N = normalize(v_N);
    vec3 V = normalize(v_V);
    vec3 R = reflect(V, N);
    vec3 L = normalize(vec3(gl_LightSource[0].position));

    vec3 v3ambient = gl_FrontMaterial.ambient.rgb;
    vec3 v3diffuse = gl_FrontMaterial.diffuse.rgb * max(dot(L, N), 0.4);
    vec3 v3specular = gl_FrontMaterial.specular.rgb * pow(max(dot(R, L), 0.0), gl_FrontMaterial.shininess);

    vec3 color = max(glow_color, diffuse_color * v3diffuse + gloss * specular);

    gl_FragColor = vec4(color, 1.0);
}

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

#22 Post by pd »

Could you comment in more detail? It looks to me like full intensity ambient lighting on the shadow side... Could you perhaps show the ship in a 3/4 view, with both light and shadow side(fill light) visible? There should be a terminator/core shadow between those 2 sides. Look at the mockups...

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

#23 Post by strooka »

a starfield:

Code: Select all

	class Random{
	public:
	Random() {}
	
	double randomUniform(double min, double max)
	{
	    double r;
	    r=(double)rand()/RAND_MAX;
	    r=min+r*(max-min);
	    return r;
	}
	
	double randomNormal(double mean, double std)
	{
	    double x1, x2, w, y1;
	    do {
	    x1 = 2.0 * randomUniform(0,1) - 1.0;
	    x2 = 2.0 * randomUniform(0,1) - 1.0;
	    w = x1 * x1 + x2 * x2;
            } while ( w >= 1.0);
	    w = sqrt( (-2.0 * log( w ) ) / w );
	    y1 = x1 * w;
	    y1 = (y1 * std) + mean;
	    return y1;
	}
	
	void randomSphere(double radius=2000)
	{
	    double l=0;
	    for(int j=0;j<3; j++){
	        Table[j] = randomNormal(0,1);
	        l += Table[j]*Table[j];
	    }
	    l = sqrt(l);
	    double r = randomUniform(0,1);
	    r = pow( r, 1/3);
	    for(int j=0;j<3; j++){
	        Table[j] = radius*(r * Table[j] / l);
	    }
	}
	
	double getTable(int i = 0) { return Table[i]; }
	
	private:
	double Table [3];
	};
	
	
	class Starfield{
	public:
	Starfield() {}
	
	void CreateStarfield(Ogre::SceneManager* scene_manager, int number_of_stars = 100)
	{
	    Ogre::ManualObject* manual = scene_manager->createManualObject("manual");
	
	    manual->begin("BaseWhiteNoLighting", Ogre::RenderOperation::OT_POINT_LIST);
	    Random random;
	    for (int i=0; i<number_of_stars; i++)
	    {
		random.randomSphere();
		manual->position(random.getTable(0), random.getTable(1), random.getTable(2));
		manual->colour(Ogre::ColourValue::White);
	    }
	    manual->end();
	
	    scene_manager->getRootSceneNode()->createChildSceneNode()->attachObject(manual);
	}
    };
activation:

Code: Select all

...
    UpdateSkyBox();

    //create a Starfield
    Starfield *p_starfield = new Starfield();
    p_starfield->CreateStarfield(m_scene_manager, 300);


Image

i had to handle with the distance parameters a little bit.. distance 2000 for the stars and 1800 for the grid is optimal, although some planets may exceed the distance of 1800...

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

#24 Post by pd »

Nice work on the starfield! I like it!

I've replaced the planet mesh with the guardian and edited some of the shader files to test your shaders and get the ship in my techdemo.

Using your shaders, ships are indeed lit by ambient light plus some weird light at the bottom(most of the time, it changes depending on the camera angle).

Image

User avatar
kroddn
Static Linker
Posts: 347
Joined: Thu Jun 28, 2007 10:28 am

Re: Version 0.320 - ship rendering, lighting and shaders

#25 Post by kroddn »

I don't want a grouch (is that the right english word?), but your code could be better commented. This is extremely important for an open source.

That stuff looks great :-)

Can I help with performace Tesings? I own some linux systems.

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

#26 Post by pd »

kroddn wrote: That stuff looks great :-)
.
It's a start...

Here are the original ship shaders, which tzlaine had done:

Image

This looks pretty good. Color and normal maps are working excellent. Glow map should ideally show the colors from the color map, but independent of the light source(=even on the dark side). Texture assignment of planets is done via code, so I've used the glow map as a night side texture, which is why is shows only white. Specular has not been assigned. 2 Point lighting is obviously also missing.

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

#27 Post by pd »

Using build 3407 I can finally place ships(thanks a lot tzlaine, Geoff). Here's a first performance test. I'm using a Geforce GTX 260.

60+ ships(each 2200 polygons) + asteroid belt: 188 FPS
Image

This is the same star system, using just 4 ships: 265 FPS
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

#28 Post by strooka »

i want to make lasers. there was an editor for for for it. pd? cn you give the url plz?

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

#29 Post by pd »

http://www.ogre3d.org/wiki/index.php/OG ... cle_Editor

I don't think particles should be used for beam weapons though.

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

#30 Post by pd »

I'd like to show off tzlaines recent shader work - he's on fire lately :)

Image

2 Point Lighting - red star, green background! It's a little dark, but that's easy to fix I imagine.

The green ellipse is the placement area at the outer edge of the system.

I've changed the levels(brightness and contrast basically) and also added some glow around the lights in photoshop as a preview.

Image

Post Reply