Regarding GL profiling

Member
Posts: 45
Joined: 2008.04
Post: #61
Sorry - but for the new demo I'm seeing the same thing as DoG on my two machines:
iMac4,1 (intel core duo, 2Ghz, ATI X1600), 10.5.7
MacBookPro2,2 (intel core 2 duo, 2.16Ghz, ATI X1600), 10.6

The mouse problem still exists on the iMac regardless of whether I use the logitech wireless mouse or a mighty mouse plugged direct into the keyboard.. Sad
Quote this message in a reply
Hog
Member
Posts: 151
Joined: 2002.09
Post: #62
Same problem on the GeForce 9600M GT
Quote this message in a reply
Sage
Posts: 1,199
Joined: 2004.10
Post: #63
Man, I've really screwed the pooch with this one. Unity looks more and more appealing.
Quote this message in a reply
Member
Posts: 81
Joined: 2007.05
Post: #64
Hmm, there does not look like there is an even distribution of the plants in the last shot. I can sort of see lines of grass. I bet that is on the edge of the polygons. < looks like that is fixed according to posts >

Do you have texture compression turned on? I remember I had some problems with that on nvidia cards.

I also remember for the fragment shader to honor the alpha the texture had to be rgba and not rgb. Once I tried using an rgb ... think it disabled the alpha. I had used an rgb but was trying to do the alpha only with the shader. Its probably rgba but you never know!

Or is it a npot thing with that particular texture?

Still looks cool.
Quote this message in a reply
Sage
Posts: 1,199
Joined: 2004.10
Post: #65
macnib Wrote:Hmm, there does not look like there is an even distribution of the plants in the last shot. I can sort of see lines of grass. I bet that is on the edge of the polygons. < looks like that is fixed according to posts >

Yeah -- I fixed it. In fact, after fixing it the grass looked too evenly distributed, so I added a 3d perlin noise generator to modulate distribution to make it look more natural. Works on My Machine ™


Quote:Do you have texture compression turned on? I remember I had some problems with that on nvidia cards.

No...

Quote:I also remember for the fragment shader to honor the alpha the texture had to be rgba and not rgb. Once I tried using an rgb ... think it disabled the alpha. I had used an rgb but was trying to do the alpha only with the shader. Its probably rgba but you never know!

Or is it a npot thing with that particular texture?

Well, I'm using full rgba textures. DoG's screenshot shows only the alpha channel being rendered, which is troubling. It also doesn't show any of the foliage, just the bushes.
Here's what it should look like:
[Image: Terrain-2009-07-04-02.png]

I'm rendering billboarded grass as well as non-billboarded crossed quads for tall features like bushes, ferns, etc. They're all being drawn in one pass, and proabbly the magic I'm using to make that happen -- a new vertex format, new GLSL -- blows up on some hardware. Strange that aBabyRabbit's seeing trouble on two machine with an x1600 however, since that's what I'm on. Though I am running 10.5.7, which had some GL fixes.


Quote:Still looks cool.

Thanks, but this is very depressing.
Quote this message in a reply
Sage
Posts: 1,199
Joined: 2004.10
Post: #66
I'm going to post some code now, and hopefully somebody will see some red flags.

First, I changed my vertex format to GL_T2F_C4UB_V3F

here's the breakdown:
- T2F: texcoords
- C4UB
-red/green: used to represent extrusion axes for billboarding
-blue: foliage color intensity( randomly modulated for realism)
-alpha: marks the amount that wind should affect the vertex
- V3F: position

Here's where I generate the quads -- this is done once, and stored in a std::vector called _quads:
Code:
void
Foliage::Patch::add( const vec3 &position, const vec3 &normal )
{
    //
    //  Get a random foliage atlas instance to work with
    //

    FoliageProperties::foliage_production_info info;
    _foliage->_properties.vend( _foliage->_rng, info );

    //
    //  A random brightness so foliage isn't all the same size
    //

    GLubyte brightness = GLubyte( _foliage->_rng->rangei( 180, 255 ));
    

    foliage_quad q;
    if ( info.billboard )
    {
        GLubyte width = _foliage->_rng->rangei( 0, 64 ),
                height = _foliage->_rng->rangei( 200, 255 );
        
        q.a = foliage_vertex( vec2( info.texOrigin.x, info.texOrigin.y ),
                             vec4_<GLubyte>( 0   + width, 0, brightness, 0 ),
                             position );
        
        q.b = foliage_vertex( vec2( info.texOrigin.x + info.texSize.x, info.texOrigin.y ),
                             vec4_<GLubyte>( 255 - width, 0, brightness, 0 ),
                             position );
        
        q.c = foliage_vertex( vec2( info.texOrigin.x + info.texSize.x, info.texOrigin.y + info.texSize.y ),
                             vec4_<GLubyte>( 255 - width, height, brightness, 255 ),
                             position );
        
        q.d = foliage_vertex( vec2( info.texOrigin.x, info.texOrigin.y + info.texSize.y ),
                             vec4_<GLubyte>( 0   + width, height, brightness, 255 ),
                             position );

        _quads.push_back( q );
    }
    else
    {  
        float width = _foliage->_rng->rangef( 0.6f, 1.0f ) * info.size.x * 0.5f;
        int vertices = NumFoliageSections * 2,
            offset = vertices*_foliage->_rng->rangei( NumRandomFoliageTwists );

        //
        //  Note regarding the 'color' param
        //  We want to prevent billboarding, so we need to pass for red/green values which
        //  will cause the vertex shader to produce an extrusion of (0,0) -- this happens to be (128,0)
        //

        for ( int i = 0; i < vertices; i+=2 )
        {
            q.a = foliage_vertex( vec2( info.texOrigin.x           , info.texOrigin.y ),
                                  vec4_<GLubyte>( 128,0,brightness,0 ),
                                  position + _foliageTemplatePoints[offset + i + 0] * width);
            
            q.b = foliage_vertex( vec2( info.texOrigin.x + info.texSize.x, info.texOrigin.y ),
                                  vec4_<GLubyte>( 128,0,brightness,0 ),
                                  position + _foliageTemplatePoints[offset + i + 1] * width);
            
            q.c = foliage_vertex( vec2( info.texOrigin.x + info.texSize.x, info.texOrigin.y + info.texSize.y ),
                                  vec4_<GLubyte>( 128,0,brightness,255 ),
                                  position + (_foliageTemplatePoints[offset + i + 1] * width) + (normal*info.size.y));
            
            q.d = foliage_vertex( vec2( info.texOrigin.x           , info.texOrigin.y + info.texSize.y ),
                                  vec4_<GLubyte>( 128,0,brightness,255 ),
                                  position + (_foliageTemplatePoints[offset + i + 0] * width) + (normal*info.size.y));
        
            _quads.push_back( q );
        }
    }

    //
    //  Update our AABB -- note, Foliage doesn't add us to the World until it's finished adding,
    //  So Foliage::Patch::computeAABB won't be called until we're done, so _foliageAABB will be up to date.
    //

    _foliageAABB.add( AABB( position, std::max( info.size.x, info.size.y )));
}

And here's where the drawing/vbo management code:
Code:
void
Foliage::Patch::display( const FrameRenderState &renderState )
{
    const float SortThreshold = 1;

    if ( renderState.lit() && renderState.light.get() == _foliage->_light )
    {
        const vec3 &cameraPosition = renderState.camera->position();
        
        if ( computeVisibility( cameraPosition ))
        {
            bool vboUpdateNeeded = false;
            if ( distance( cameraPosition, _lastCameraPosition ) > SortThreshold )
            {
                sortFoliage( cameraPosition );
                vboUpdateNeeded = true;
            }

            const ShaderRef &shader = _material->shader()->shaderForPass( renderState );
            shader->setUniform( "Normal", _normal );
            shader->setUniform( "Visibility", _visibility );
            
            _material->setupForEntity( renderState, shared_from_this() );

            if ( UseVBOs )
            {  
                glBindBuffer( GL_ARRAY_BUFFER, _vboID );

                if ( vboUpdateNeeded )
                {
                    updateVBO();
                }
                                            
                glInterleavedArrays( foliage_vertex::VBO_FORMAT, 0, NULL );
            }
            else
            {
                glInterleavedArrays( foliage_vertex::VBO_FORMAT, 0, &(_quads.front()) );
            }

            glDrawArrays( GL_QUADS, 0, _quads.size() * 4 );

            if ( UseVBOs )
            {
                glBindBuffer( GL_ARRAY_BUFFER, 0 );
            }              
        }
    }
}

void
Foliage::Patch::createVBO( void )
{
    if ( !_vboID )
    {
        glError();
        glGenBuffers( 1, &_vboID );
        glBindBuffer( GL_ARRAY_BUFFER, _vboID );
        glBufferData( GL_ARRAY_BUFFER,
                      _quads.size() * sizeof( foliage_quad ),
                      NULL, /*&(_quads.front() ), */ // we upload in ::updateVBO
                      GL_DYNAMIC_DRAW );
        glError();
    }
}

void
Foliage::Patch::updateVBO( void )
{
    glBufferSubData( GL_ARRAY_BUFFER, 0, _quads.size() * sizeof( foliage_quad ), &(_quads.front() ));
}

And, now some GLSL:
lit_d.vs
Code:
#include <Shaders/Shadow/shadow_directional.vs>
#include "lit_common.vs"

///////////////////////////////////////////////////////////////////////

uniform vec4 Diffuse;

///////////////////////////////////////////////////////////////////////

varying vec3 DiffuseTerm;

///////////////////////////////////////////////////////////////////////

void main(void)
{
    lit_common();
    directional_shadow_setup();

    // Basic lighting
    DiffuseTerm = (Diffuse * max( dot(N,gl_LightSource[0].position.xyz), 0.0 )).rgb;
}

lit_d.fs
Code:
#include <Shaders/Shadow/shadow_directional.fs>
#include <Shaders/Materials/Common/fog.fs>

///////////////////////////////////////////////////////////////////////

uniform sampler2D ColorMap;
uniform float Visibility;
uniform vec4 Ambient;

///////////////////////////////////////////////////////////////////////

varying vec3 N, ECPos, DiffuseTerm;
varying float Intensity;

///////////////////////////////////////////////////////////////////////

void main()
{
    vec3 n = N; // here to prevent complaints
    vec4 color = texture2D( ColorMap, gl_TexCoord[0].st );

    vec3 fragColor = Intensity * color.rgb * (Ambient.rgb + (shadow_coefficient_low(ECPos) * DiffuseTerm));

    gl_FragColor = Visibility * vec4( fog_apply_lit( fragColor ), color.a );    
}

foliage_setup.vs -- billboarding code
Code:
uniform vec2 Size;
uniform float Time;
uniform vec3 WindDirection;
uniform float WavePeriod, WaveMagnitude;
uniform vec3 CameraPosition;

vec3 foliage_setup()
{
    //
    //    Billboard: note, dim will be (0,0) for quads which don't need billboarding
    //
    
    vec4 vertex = gl_Vertex;
    vec2 dim = vec2(((gl_Color.x * 2.0) - 1.0) * 0.5, gl_Color.y );
    vec2 scale = dim * Size;

    vec3 directionToCamera = normalize( CameraPosition - gl_Vertex.xyz );
    vec3 axis = normalize( cross( gl_Normal, directionToCamera ));
    vertex.xyz += (scale.x*axis) + (scale.y*gl_Normal);
    
    //
    //    Apply waves, and note that the color is used to offset the wave timing, so foliage doesn't all wave in unison,
    //    which would be creepy, as in children-of-the-corn-creepy. gl_Color.w marks the 'top' vertices so we only wave them
    //
    
    vertex.xyz += WindDirection * WaveMagnitude * gl_Color.w * sin( (Time + gl_Color.z * 16.0) * WavePeriod );


    //
    //    Note that we return ECPos
    //

    gl_Position = gl_ModelViewProjectionMatrix * vertex;        
    return ( gl_ModelViewMatrix * vertex ).xyz;
}

and finally some common code to lit foliage vertex shaders:
lit_common.vs
Code:
#include "foliage_setup.vs"
#include <Shaders/Materials/Common/fog.vs>

///////////////////////////////////////////////////////////////////////

uniform vec3 Normal;

///////////////////////////////////////////////////////////////////////

varying vec3 N, ECPos;
varying float Intensity;

///////////////////////////////////////////////////////////////////////

void lit_common(void)
{
    gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
    Intensity = gl_Color.z;

    N = normalize(gl_NormalMatrix * Normal);
    ECPos = foliage_setup();
    
    fog_setup(ECPos);
}
Quote this message in a reply
Member
Posts: 81
Joined: 2007.05
Post: #67
ok, I tested your software on my quad pro mac. There are three video cards. I made a clean account. The 8800GT is in the primary slot. Just my standard test. Smile

---

NVidia 8800GT

FPS 40-60 SPS 120 <-- primary slot.

Had black and white textures for the plants

----

ATI 2600 XT

Again, black and white textures for the plants. Going to ignore the fps because this card is not in the primary slot.

-----

NVidia 7300 GT

Ignoring fps because not primary slot.

Again, Textures for plants are black and white.

There is another serious issue on this card. It wants to draw black polygons from the center of the screen radially outwards. Sometimes these fill 3/4 of the screen.

Once in a while, I'll see some black on the foggy covered terrain in the background. So, this looks odd. Typically on the edge of the hill and sky.

------

Controls are a serious issue. Its easy to roll over the car. When it rolls over the camera rolls over too and the program is essentially stuck.

I hit a rock at the edge of the top of the valley. Both the rock and the car went into the air. Then high up in the air both stopped and got stuck in the air with the camera upside down.

So, there are some serious camera position issues.

-----

Controls felt a little sluggish.

-----

Otherwise, if I drive conservatively, it does give me a feeling of being in another world. And the scene for the most part looks good.

-----

I would get the foliage thing worked out. But I think the controls are the top priority if you intend to make this a game.

When I make my games, I always do the boring stuff first. Like menus, scores, loading. That way the cool stuff is last and your really motivated doing the cool stuff in the end.
Quote this message in a reply
Sage
Posts: 1,199
Joined: 2004.10
Post: #68
Man, that's depressing -- it doesn't work on any of your machines. Though, regarding the situation where black triangles radiated from the center out -- that is something I saw a lot of when developing the cascading shadow map implementation. Apparently, the 7300 can't do CSM the way I'm trying to make it happen -- which is in and of itself rather crude owing to lack of GL_TEXTURE_ARRAY_EXT

Regarding "gameplay" -- I appreciate the feedback, harsh as it is. Honest words are useful! That being said, this was meant more as a quick throwaway for developing foliage. I happened to have the simple car simulator from earlier python scripting integration tests, and I thought "why not just throw the car in". Rasp
Quote this message in a reply
Member
Posts: 81
Joined: 2007.05
Post: #69
It would be cool, if when your driving in the cave, there could be a light shaft from the ceiling to the floor. ( I recall there is an opening from above ) Maybe put some plants and trees up above and they can cast a shadow into the cave too. Put in a pool of water down there on one side with the light shining on it and drive by it all. Probably would be spectacular. Smile
Quote this message in a reply
Sage
Posts: 1,199
Joined: 2004.10
Post: #70
macnib Wrote:It would be cool, if when your driving in the cave, there could be a light shaft from the ceiling to the floor. ( I recall there is an opening from above ) Maybe put some plants and trees up above and they can cast a shadow into the cave too. Put in a pool of water down there on one side with the light shining on it and drive by it all. Probably would be spectacular. Smile

Yeah, it probably would be spectacular. However, right now I'll be content with getting this working on more than one computer than just mine.Blink
Quote this message in a reply
Sage
Posts: 1,199
Joined: 2004.10
Post: #71
Hey, can people try again?

http://shamyl.zakariya.net/etc/gl/TerrainDemo.zip

I realized an awful mistake -- my build system lets me take some shortcuts for GLSL packaged in my bundled frameworks. And as a result, the bundled framework in Terrain.app didn't have the up-to-date GLSL in it -- since my app is shortcutting the lookup locations to my working directory.

I still don't know why Fenris' is seeing DDHidLib blow up, but hopefully this will fix some of the rendering bugs ( except for the 7300 )
Quote this message in a reply
Member
Posts: 45
Joined: 2008.04
Post: #72
lol, one of those days huh... You might want check your packaging yet again- that new download definitely doesn't work as your SRE framework just contains aliases Wink
Quote this message in a reply
Sage
Posts: 1,199
Joined: 2004.10
Post: #73
aBabyRabbit Wrote:lol, one of those days huh... You might want check your packaging yet again- that new download definitely doesn't work as your SRE framework just contains aliases Wink

Unbelievable. Could you try again?
Quote this message in a reply
Member
Posts: 59
Joined: 2007.12
Post: #74
Works beautifully here. MBP early 2008 with a 8600m gt. Would make for a great game once you tweak the physics&camera. Smile
Quote this message in a reply
Sage
Posts: 1,199
Joined: 2004.10
Post: #75
Man, finally! Awesome.

I've decided to take macnib's suggestions, even though this really is just a tech demo with a throwaway car sim. The camera control really nags me.
Quote this message in a reply
Post Reply