Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Danny02

Member Since 21 Apr 2010
Offline Last Active May 20 2012 07:19 AM

Topics I've Started

What kind of Shadow technique would you suggest for a RTS game

04 March 2011 - 06:56 PM

Hi, for a while now I'm working on a RTS kind of game.
I come to a point where I want to implement shadows into my renderer, first I thought of simple shadow mapping of course, but in my case the camera is very restricted so properly there are other methods which provide better visuals.

So I have following camera restrictions.
  • fixed height from the ground(maybe I allow zooming in)
  • orthogonal projection
  • fixed rotation(maybe not)
  • isometric view(z:45° x:32°)
  • user can only move the camera on the xy plane
  • only sun as light
My question now, which technique would u choose.
And if you think that shadow mapping is the best choice how do I calculate the view of the sun best. So I get the best results

Really strange GLSL bug

18 January 2011 - 07:45 PM

Hi,
I were experimenting a little with my heighmap generator when stumbling across a very very strange bug.
I'm curious if somebody can help me with this.

So what am I doing. I have 2 Textures one with normals in the RGB and a heigh value in A channel.
I offset the height in the vertex and use the normals in the fragment shader.
Everything was working just right to this point.

Then I thought it would be cool to add a diffuse texture, so I added a new sampler to the fragment shader as I do normally.
Suddenly my vertices won't get displaced anymore(texture lookup returning 0.), but the normals are still used correctly. The diffuse texture is also working just fine.

When I comment out the texture lookup of the diffuse texture suddenly the displacement starts working again.

Sources:
vertex

in vec4 in_position;
in vec2 in_texcoord;
out vec2 normaltc;
out vec2 diffusetc;

uniform mat4 mat_mvp;

uniform sampler2D normal_height;

uniform vec2 texoffset, texscale;

void main() {
    normaltc = in_texcoord;
    diffusetc = in_texcoord * texscale + texoffset ;

    vec4 position = in_position;
    position.z  = 0.5 * clamp(texture(normal_height, in_texcoord).a, 0., 1.);

    gl_Position = mat_mvp * position;
}

fragment

#version 130

in vec2 normaltc;
in vec2 diffusetc;


 out vec4 FragColor;

uniform vec3 light_pos;

uniform sampler2D normal_height;
uniform sampler2D diffuse;

void main() {

    vec3 color = vec3(0.);

    vec3 N = texture(normal_height, normaltc).xyz;
    N.xy = N.xy * 2. - 1.;
    N = normalize(N);

    vec3 D = texture(diffuse, diffusetc).xyz;
 	float NdotL = dot(N, light_pos);
 	if(NdotL >= 0.){
            color +=  NdotL * D;
 	}

    color += vec3(0.1, 0.1, 0.1)*D;
    FragColor = vec4(color, 1.);
}


Any improvments for my Sphere Collision Algorithm

15 May 2010 - 05:46 AM

Today i sat down in wrote me a function which checks if 2 moving Spheres collide or not because I need this for my Game projekt. And I wondered if there are any improvments performance wise which can be done. Ps: I tested it a bit but would be glad if any bugs can be found
public boolean checkCollision(Sphere s1, Sphere s2){
// s2 position relativ to s1
        Vec3f pos = (Vec3f) s2.getPosition().sub(s1.getPosition()); 
// s2 velocity relativ to s1
        Vec3f vel = (Vec3f) s2.getVelocity().sub(s1.getVelocity()); 

        float dot = pos.dot(vel);
        if(dot>0) // if s2 is moving away from s1 no collision
            return false;

// calculates the nearest point from s1 to the moving line of s2
// p: nearest point on the line(s2.p + x * s2.v) to s1
// lenquad gives back the length of a Vector with out pulling the squarroot
        float vellenquad = vel.lenquad(); 
        float x = (-dot)/vellenquad;
        Vec3f p = new Vec3f(); 
//the second argument of add and mul methods is where the result is saved
        pos.add(vel.mul(x, p),p);

        float distquad = p.lenquad(); // distance² from s1 to line: s2.p + x * s2.v

        float mindist = s1.getRadius() + s2.getRadius();
        float mindistquad = mindist * mindist;
        if(distquad>mindistquad)
            return false; // no collision cause the moving line of s2 is never near s1

        double fen = Math.sqrt(mindist - distquad); //pytagoras
        double vellen = Math.sqrt(vellenquad); // length of velocity vector
// x value of the collision, in the line function s2.p + x * s2.v
        double fenx = x - fen/vellen; 
        if(fenx > 1)
            return false; // on a way to collision but not this frame

        // normal vector on which the velocity vector from both sphere gets refelcted after the collision
        Vec3f normal = vel.mul((float)(-fen/vellen));
        normal.add(p, normal);
        normal.mul(s1.getRadius()/mindist, normal);
        
        // exact position where both sphers collide
        Vec3f colpos = normal.add(s1.getPosition());
        
        //percenteg of movment both sphers went before the collision, indicates how much they still have to travel(permoved * s1.vel for excample)
        double permoved = fenx / x; // percentage of the movment of both spheres until collision

        fireEvent(new CollisionEvent(s1, s2, normal, colpos, permoved));

        return true;
    }


PARTNERS