Jump to content

  • Log In with Google      Sign In   
  • Create Account

Yours3!f

Member Since 04 Feb 2011
Offline Last Active Yesterday, 06:59 PM

Topics I've Started

want to create an fps

10 November 2014 - 01:07 PM

hi there,

 

I'd like to put together a simple FPS for experimentation. I've already created a renderer so I can load models with textures, animations. I already have a free-fly style camera. The important thing is that I want to do this without a game engine like Unity or UE4. I'd like to learn it inside out...

 

The features I'd like it to have are: 

1) enemies with animations

2) simple AI for enemies (basically find the player and cause damage)

3) some simple static single-floor level representation: the goal here is to make sure that the AI can react to obstacles and the player can't move around freely (think noclip disabled :) )
4) some simple weapon animation

5) ability to shoot the enemies who can die

6) get points for killing enemies, game is over when the player dies

7) simple high-score system so there's some 'goal'

 

I already have some ideas for these features.

1) I can already do skeletal animation, though I've yet to grab some assets (zombie or soldier would be great...) with animations

2) The enemies could move around using a simple A* algorithm (when they can see the player), else they wander around randomly...

3) I don't really know how to do the level representation. So the goal would be to be able to bump into things, so that requires a physics engine, or how is this usually done? 

4) again skeletal animation, reacting to the player's input

5) I think this would be some simple ray tracing (where a bullet would be a ray, the enemies would be represented by collision spheres, boxes etc.) I think I can already do this

6) 7) these are really simple imo, the GUI would be berkelium-based, so I think I can do that.

 

so I'm not really sure about 2, 3, any pointers on those? (or the rest if I'm wrong...)

 

best regards,

Yours3!f

 


ssao self-occlusion problems

01 November 2014 - 04:28 AM

hi there,

 

I'm trying to implement the "Alchemy" ssao technique from this PDF:
http://frederikaalund.com/wp-content/uploads/2013/05/A-Comparative-Study-of-Screen-Space-Ambient-Occlusion-Methods.pdf

I could implement it, but I'm facing severe self-occlusion issues when using per-pixel normals from the g-buffer (with normal maps).
There's no issue when I'm using the reconstructed normals from the depth buffer.

 

Sponza scene, wall viewed from side, per-pixel normals, self-occlusion problems:
http://minus.com/i/BVfKQov3ZxwA

 

per-face normals (reconstructed), no self-occlusion (but no per-pixel ssao either):

http://minus.com/i/b24QSlupk9JZz

 

same thing w/ per-pixel normals, viewed from front:
http://minus.com/i/3s0ctLXDXD56

 

here's the shader I'm using:

#version 430 core

layout(binding=0) uniform sampler2D depth_tex;
layout(binding=1) uniform sampler2D normal_tex;
layout(binding=2) uniform sampler2D random_tex;

uniform float near, far;
uniform mat4 inv_mv, inv_mvp;
uniform vec4 far_plane0;
uniform vec2 far_plane1;
uniform mat3 inv_view;

in vec2 texcoord;

out vec4 color;

#include "common.h"

//a is used to remedy self-occlusion
//b and c is used to control brightness and contrast
float tweak( float ao, float a, float b, float c )
{
  return pow( b * (ao + a), c );
}

void main()
{
  //reconstruct view space position
  vec2 pos_xy = mix( far_plane0.xy, vec2(far_plane0.w, far_plane1.x), texcoord );
  float depth = texture( depth_tex, texcoord ).x;
  float linear_depth = linearize_depth( depth, near, far );
  vec3 vs_pos = linear_depth_to_vs_pos( linear_depth, pos_xy, far );

  //reconstruct world space position
  vec4 ms_pos = inv_mv * vec4( vs_pos, 1 );

  //reconstructed per-face world space normals
  //vec3 ms_normal = -normalize(cross(dFdy(ms_pos.xyz), dFdx(ms_pos.xyz)));

  //per-pixel world space normals
  vec3 ms_normal = inv_view * ( texture( normal_tex, texcoord ).xyz * 2 - 1 );

  const int samples = 64;
  const float radius = 1; //10
  const float projection_factor = 0.75;
  const float bias = 1.0;
  const float sigma = 2.0;
  const float epsilon = 0.00001;
  const float a = 0.0;
  const float b = 1.0;
  const float c = 5.0;

  float projected_radius = radius * projection_factor / -vs_pos.z;

  vec2 inv_random_texsize = 1.0 / textureSize( random_tex, 0 ).xy;

  float ao = 0;

  for( int i = 0; i < samples; ++i )
  {
    vec2 random_dir = texture( random_tex, vec2( texcoord / inv_random_texsize * (i+1) ) ).xy * 2 - 1;

    vec3 asample;
    asample.xy = texcoord + random_dir * projected_radius;
    asample.z = texture( depth_tex, asample.xy ).x;

    //reconstruct world space position of the sample
    vec3 ndc_sample = asample * 2 - 1;
    vec4 tmp = inv_mvp * vec4( ndc_sample, 1 );
    vec3 ms_sample_pos = tmp.xyz / tmp.w;

    //get the difference vector
    vec3 sample_dir = ms_sample_pos - ms_pos.xyz;

    ao +=
    //get the angle between the normal and the vector
    max( 0, dot( sample_dir, ms_normal ) - bias ) /
    //get the squared distance
    ( dot( sample_dir, sample_dir ) + epsilon );
  }

  ao = tweak( max( 0, 1 - 2 * sigma / float( samples ) * ao ), a, b, c );

  color = vec4( ao );
}

I tried toying with the "a" parameter, but it either killed the ssao result (no visible occlusion, or not enough) or it wasn't enough...

 

I may be facing just a case of bad parameters, but I tried to follow the pdf closely...

 

any ideas on how to overcome this?

 

best regards,

Yours3!f


Texture Storage + Texture Views AND mipmapping

24 September 2014 - 05:36 AM

hi there,

 

how do you do mipmapping with texture storage?
I tried the following on AMD Catalyst 14.7 rc3, but it didn't really seem to work.

//create immutable texture storage
glGenTextures( 1, &orig_tex );
float num_mips = std::log2( float( std::max( orig_tex_width, orig_tex_height ) ) ) + 1;
glBindTexture( GL_TEXTURE_2D, orig_tex );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 4);

//mipmapping doesn't work
glTexStorage2D( GL_TEXTURE_2D, num_mips, GL_RGBA8, orig_tex_width, orig_tex_height );
glTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, im.getSize().x, im.getSize().y, GL_RGBA, GL_UNSIGNED_BYTE, im.getPixelsPtr() );

//mipmapping works, but this is not immutable storage
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA8, orig_tex_width, orig_tex_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixel_data );

glGenerateMipmap( GL_TEXTURE_2D );

/**
.
.
.
/**/

//create texture views for the immutable storage
glGenTextures( 1, &tex );
glTextureView( tex, GL_TEXTURE_2D, orig_tex, GL_RGBA8, 0, num_mips, 0, 1 );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 4);

//"texture view" workaround, as texstorage doesn't work
tex = orig_tex; //...

Best regards,

Yours3!f


depth cubemap texture array setup

16 August 2014 - 09:58 AM

hi there,

 

is this the correct way to set up depth cubemap texture arrays? My problem is that nothing is rendered to the textures...

EDIT: I seem to have been able to render 1 face correctly, I still suspect the setup code.

I get no errors or debug output messages.
I suspect that I should somehow enable each face as usual with the cubemaps, but I couldn't find a way to do that...
 

  GLuint point_shadow_texture;
  glGenTextures(1, &point_shadow_texture);
  glBindTexture(GL_TEXTURE_CUBE_MAP_ARRAY, point_shadow_texture);

  glTexParameteri( GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
  glTexParameteri( GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
  glTexParameteri( GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE );
  glTexParameteri( GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
  glTexParameteri( GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
  glTexImage3D( GL_TEXTURE_CUBE_MAP_ARRAY, 0, GL_DEPTH_COMPONENT32, shadow_texture_size.x, shadow_texture_size.y, lights.size() * 6, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, 0 );

  vector<GLuint> point_shadow_fbos;
  point_shadow_fbos.resize( lights.size() );
  glGenFramebuffers( lights.size(), &point_shadow_fbos[0] );

  for( int c = 0; c < lights.size(); ++c )
  {
    glBindFramebuffer( GL_FRAMEBUFFER, point_shadow_fbos[c] );
    glDrawBuffer( GL_NONE );
    glFramebufferTextureLayer( GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, point_shadow_texture, 0, c );
    frm.check_fbo_status();
  }

  glBindFramebuffer( GL_FRAMEBUFFER, 0 );

usually I set up non-texture-array depth cubemaps like this:

  GLuint cubemap_tex;
  glGenTextures( 1, &cubemap_tex );
  glBindTexture( GL_TEXTURE_CUBE_MAP, cubemap_tex );

  glTexParameteri( GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
  glTexParameteri( GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
  glTexParameteri( GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE );
  glTexParameteri( GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
  glTexParameteri( GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR );

  uvec2 texsize( 1024 );

  for( int c = 0; c < 6; ++c )
    glTexImage2D( GL_TEXTURE_CUBE_MAP_POSITIVE_X + c, 0, GL_DEPTH_COMPONENT24, texsize.x, texsize.y, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, 0 );

  GLuint cubemap_fbo;
  glGenFramebuffers( 1, &cubemap_fbo );
  glBindFramebuffer( GL_FRAMEBUFFER, cubemap_fbo );

  //attach depth cubemap to fbo's depth attachment
  glFramebufferTexture( GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, cubemap_tex, 0 );

  //no color textures attached
  glDrawBuffer( GL_NONE );

  frm.check_fbo_status();

  //unbind
  glBindFramebuffer( GL_FRAMEBUFFER, 0 );

Best regards,

Yours3!f


Instanced font rendering (continued)

03 August 2014 - 11:02 AM

hi there,

 

I extended my font rendering lib so that you can color your characters any way you want them, in any size, highlight each character separately, add underlining, overlining, strikethrough, draw them at any location with correct line heights, gaps, and kerning (some of this is based on freetype-gl: https://github.com/rougier/freetype-gl).
All of this in one draw call, one vao, one texture, one shader, everything instanced, SUPER FAST :D
Licence is MIT, download here, feel free to use: https://github.com/Yours3lf/instanced_font_rendering

It should be super easy to integrate.

Requires GL3.x

 

best regards,

Yours3!f


PARTNERS