Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Murloc992

Member Since 30 Sep 2012
Offline Last Active Oct 13 2014 11:47 AM

Posts I've Made

In Topic: Deferred rendering shader spaces issue

27 September 2014 - 08:57 AM

Was a little bit off from it, but now as I am back, have played a bit with the shader variables, tried multiple things with positions (first thought it was some wrong spaces, apparently not), but I think it's the 4 squares of positions what messes up the look of it. I yet have no idea why final render is split into four parts tho. Could anybody put me on the right track?


In Topic: Deferred rendering shader spaces issue

18 September 2014 - 05:36 AM

Still struggling. Not really sure where I am lost right now. The 4 times split screen looks like it's a position issue, but I am not sure. Maybe my settings are bad or something.. Trying to fix but no avail.


In Topic: Deferred rendering shader spaces issue

17 September 2014 - 05:42 AM

Thank you for your responses. smile.png I have fixed my normals and positions calculations accordingly and now, I presume, they are both in ModelView space, which is required for the implementation of this SSAO approach. This is how my buffers and SSAO look now:

 

fcda583769.png

 

I had to convert the SSAO code from what I think is DirectX shading language to GLSL, so there might be some mistakes by me. What I could be doing wrong, to get such distorted 4-piece screen results? This is my SSAO conversion:

 

Vertex Shader

#version 330
layout (location=0) in vec3 pos;
layout (location=1) in vec2 tex;

out vec4 _pos;
out vec2 _uv;

void main(void)
{
	_pos = vec4(pos,1);
    _uv = tex;
    gl_Position = vec4(pos,1);
}

Fragment shader

#version 330

uniform sampler2D g_buffer_diff;
uniform sampler2D g_buffer_norm;
uniform sampler2D g_buffer_pos;
uniform sampler2D g_random;
uniform sampler2D g_depth;

const float g_screen_size=1280*768;
const float random_size=64*64;
const float g_sample_rad=0.006;
const float g_intensity=1.38;
const float g_scale=0.000002;
const float g_bias=0.07;

in vec4 _pos;
in vec2 _uv;

out vec4 fragColor;

vec3 getPosition(vec2 uv)
{
return texture2D(g_buffer_pos,uv).xyz;
}

vec3 getNormal(vec2 uv)
{
return normalize(texture2D(g_buffer_norm, uv).xyz * 2.0f - 1.0f);
}

vec2 getRandom(vec2 uv)
{
return normalize(texture2D(g_random, g_screen_size * uv / random_size).xy * 2.0f - 1.0f);
}

float doAmbientOcclusion(vec2 tcoord,in vec2 uv, in vec3 p, in vec3 cnorm)
{
vec3 diff = getPosition(tcoord + uv) - p;
vec3 v = normalize(diff);
float d = length(diff)*g_scale;
return max(0.0, dot(cnorm,v)-g_bias)*(1.0/(1.0+d))*g_intensity;
}

void main()
{
vec2 vecs[4];
vecs[0]= vec2(1,0);
vecs[1]= vec2(-1,0);
vecs[2]= vec2(0,1);
vecs[3]= vec2(0,-1);

vec3 p = getPosition(_uv);
vec3 n = getNormal(_uv);
vec2 rand = getRandom(_uv);

float ao = 0.0f;
float rad = g_sample_rad/p.z;

//**SSAO Calculation**//
int iterations = 4;
for (int j = 0; j < iterations; ++j)
{
  vec2 coord1 = reflect(vecs[j],rand)*rad;
  vec2 coord2 = vec2(coord1.x*0.707 - coord1.y*0.707, coord1.x*0.707 + coord1.y*0.707);
  
  ao += doAmbientOcclusion(_uv,coord1*0.25, p, n);
  ao += doAmbientOcclusion(_uv,coord2*0.5, p, n);
  ao += doAmbientOcclusion(_uv,coord1*0.75, p, n);
  ao += doAmbientOcclusion(_uv,coord2, p, n);
}
ao/=iterations*4.0;
//**END**//

//Do stuff here with your occlusion value âaoâ: modulate ambient lighting, write it to a buffer for later //use, etc.
fragColor=vec4(1-ao);
}

I am lost now. sad.png


In Topic: Deferred rendering shader spaces issue

17 September 2014 - 01:49 AM

Wow, that was fast. :)

Thank you very much for getting me on track and clarifying!

 

(Also, saw a very neat trick for alpha you got there! Will definitely try it. :) )

 

Thanks! Will see how it goes, if I struggle anymore or not.


In Topic: [GL3] VAO and VBO question about dynamic/stream buffers

20 December 2012 - 01:00 PM

Thanks for an answer. I know how to stream the buffers with the bind. My question is about how to avoid the bind, or it is unavoidable. :?

PARTNERS