• Advertisement
  • Popular Tags

  • Popular Now

  • Advertisement
  • Similar Content

    • By Epicghost 505
      Hello,
      We are looking for people to be apart of a team, to help create a horror game we are looking for 3d modelers, coders, artist, animators, fx artist, level designers, and audio design, there will be a payment plan once release of game                                                                                                                                                                                                                                                                                              if your interested come join our discord                                                                                                                                                                                                                                                                         We hope to see you there
      https://discord.gg/6rcc6xr
      -Epicghost505
    • By lxjk
      Hi guys,
      There are many ways to do light culling in tile-based shading. I've been playing with this idea for a while, and just want to throw it out there.
      Because tile frustums are general small compared to light radius, I tried using cone test to reduce false positives introduced by commonly used sphere-frustum test.
      On top of that, I use distance to camera rather than depth for near/far test (aka. sliced by spheres).
      This method can be naturally extended to clustered light culling as well.
      The following image shows the general ideas

       
      Performance-wise I get around 15% improvement over sphere-frustum test. You can also see how a single light performs as the following: from left to right (1) standard rendering of a point light; then tiles passed the test of (2) sphere-frustum test; (3) cone test; (4) spherical-sliced cone test
       

       
      I put the details in my blog post (https://lxjk.github.io/2018/03/25/Improve-Tile-based-Light-Culling-with-Spherical-sliced-Cone.html), GLSL source code included!
       
      Eric
    • By Octane_Test
      I am developing a mini golf game in Scenekit. I have applied dynamic physics body to the ball and static physics body to the grass surface and the brick walls show in this image.
      Issue:
      When I apply the force to the ball, the ball’s linear and angular speeds change as shown in the graphs.  The ball’s speeds don’t reduce to zero (so that the ball can stop) but remains constant after certain value.
      Ball linear speed graph
      Ball angular speed graph
      Analysis Tests:
      When I increase the values to both the rolling friction and the friction, the ball speed is reduced quickly but remains constant after certain value (similar to the above graphs). When I increase the values of the linear damping and the angular damping, the ball speed behavior is same as the point #1. When I set the gravity value to -9.8 m/s2, the ball’s linear speed remains constant after 0.1 m/s. If I reduce the gravity value to -5 m/s2, the ball’s linear speed remains constant after 0.05 m/s. The friction, linear friction, linear damping and angular damping are same throughout the motion of the ball.
      There is 1 millimeter overlapping between the ball and the surface of the golf course.
      Questions:
      From the analysis test #3, I think the gravity is causing the constant ball speed issue. Is my assumption correct? If yes, how can I fix the issue? I can’t remove the gravity field as without the gravity field the ball will not roll along the grass and it will slide. Why the friction and the damping properties are not affecting the ball speed after certain value?
      Are there any other physics properties can cause such issue?
      From the analysis test #5, are there any chances that the ball is receiving upward push to correct the position of the ball?
      Solutions:
      If I increase the physics timestep from 60 FPS to 200 FPS, the issue is resolved. I am not able to understand how this change can fix this issue? After reducing the gravity value to -1 m/s2 and physics simulation speed to 4 (4 times fast physics simulation), the issue is fixed. Again, I am not able to understand how this change fix the issue? I would appreciate any suggestions and thoughts on this topic. Thank you.
    • By stale
      I'm continuing to learn more about terrain rendering, and so far I've managed to load in a heightmap and render it as a tessellated wireframe (following Frank Luna's DX11 book). However, I'm getting some really weird behavior where a large section of the wireframe is being rendered with a yellow color, even though my pixel shader is hard coded to output white. 

      The parts of the mesh that are discolored changes as well, as pictured below (mesh is being clipped by far plane).

      Here is my pixel shader. As mentioned, I simply hard code it to output white:
      float PS(DOUT pin) : SV_Target { return float4(1.0f, 1.0f, 1.0f, 1.0f); } I'm completely lost on what could be causing this, so any help in the right direction would be greatly appreciated. If I can help by providing more information please let me know.
  • Advertisement
  • Advertisement

3D Sun shafts via postprocess artefacts

Recommended Posts

Hi all!

I try to use the Sun shafts effects via post process in my 3DEngine, but i have some artefacts on final image(Please see attached images).

The effect contains the following passes:

1) Depth scene pass;

2) "Shafts pass" Using DepthPass Texture + RGBA BackBuffer texture.

3) Shafts pass texture +  RGBA BackBuffer texture.

Shafts shader for 2 pass:

//
uniform sampler2D FullSampler; // RGBA Back Buffer
uniform sampler2D DepthSampler;

varying vec2 tex;

#ifndef saturate
float saturate(float val)
{
    return clamp(val, 0.0, 1.0);
}
#endif

void main(void)
{
    vec2 uv = tex;
    float sceneDepth = texture2D(DepthSampler, uv.xy).r;
    vec4  scene        = texture2D(FullSampler, tex);
    float fShaftsMask     = (1.0 - sceneDepth);
    gl_FragColor = vec4( scene.xyz * saturate(sceneDepth), fShaftsMask );
}

final shader:

//
uniform sampler2D FullSampler; // RGBA Back Buffer
uniform sampler2D BlurSampler; // shafts sampler
varying vec4 Sun_pos;
const vec4    ShaftParams = vec4(0.1,2.0,0.1,2.0);

varying vec2 Tex_UV;

#ifndef saturate 
float saturate(float val)
{
    return clamp(val, 0.0, 1.0);
}
#endif

vec4 blendSoftLight(vec4 a, vec4 b)
{
  vec4 c = 2.0 * a * b + a * a * (1.0 - 2.0 * b);
  vec4 d = sqrt(a) * (2.0 * b - 1.0) + 2.0 * a * (1.0 - b);
   
  // TODO: To look in Crysis what it the shit???
  //return ( b < 0.5 )? c : d;
  return any(lessThan(b, vec4(0.5,0.5,0.5,0.5)))? c : d;
}

void main(void)
{
    vec4 sun_pos = Sun_pos;
    vec2    sunPosProj = sun_pos.xy;
    //float    sign = sun_pos.w;
    float    sign = 1.0;

    vec2    sunVec = sunPosProj.xy - (Tex_UV.xy - vec2(0.5, 0.5));
    float    sunDist = saturate(sign) * saturate( 1.0 - saturate(length(sunVec) * ShaftParams.y ));

    sunVec *= ShaftParams.x * sign;

    vec4 accum;
    vec2 tc = Tex_UV.xy;

    tc += sunVec;
    accum = texture2D(BlurSampler, tc);
    tc += sunVec;
    accum += texture2D(BlurSampler, tc) * 0.875;
    tc += sunVec;
    accum += texture2D(BlurSampler, tc) * 0.75;
    tc += sunVec;
    accum += texture2D(BlurSampler, tc) * 0.625;
    tc += sunVec;
    accum += texture2D(BlurSampler, tc) * 0.5;
    tc += sunVec;
    accum += texture2D(BlurSampler, tc) * 0.375;
    tc += sunVec;
    accum += texture2D(BlurSampler, tc) * 0.25;
    tc += sunVec;
    accum += texture2D(BlurSampler, tc) * 0.125;

    accum  *= 0.25 * vec4(sunDist, sunDist, sunDist, 1.0);
    
     accum.w += 1.0 - saturate(saturate(sign * 0.1 + 0.9));

    vec4    cScreen = texture2D(FullSampler, Tex_UV.xy);      
    vec4    cSunShafts = accum;

    float fShaftsMask = saturate(1.00001 - cSunShafts.w) * ShaftParams.z * 2.0;
        
    float fBlend = cSunShafts.w;

    vec4 sunColor = vec4(0.9, 0.8, 0.6, 1.0);

    accum =  cScreen + cSunShafts.xyzz * ShaftParams.w * sunColor * (1.0 - cScreen);
    accum = blendSoftLight(accum, sunColor * fShaftsMask * 0.5 + 0.5);

    gl_FragColor = accum;
}

Demo project:

Demo Project

Shaders for postprocess Shaders/SunShaft/

What i do wrong ?

Thanks!
 

sun_shafts.png

sun_shafts2.png

Edited by Andrey OGL_D3D

Share this post


Link to post
Share on other sites
Advertisement

From those images it seem to work correctly, but you should either take more samples or blur the result after the radial blur. You can also do the radial blur pass in a lower resolution which can help with performance and the banding as well. I couldn't really understand your process as you explained so here is what I do:

1.) Draw the sun against scene depth buffer to a render target, depth test on to discard occluded sun pixels

2.) Radial blur on a low-res (0.5x) texture

3.) Draw the result on top with additive blending

Share this post


Link to post
Share on other sites
8 hours ago, Matt_Aufderheide said:

It looks like its working correctly, you just need more samples to get it smoother I think...

 

6 hours ago, turanszkij said:

but you should either take more samples or blur the result after the radial blur.

Matt_Aufderheide, turanszkij Thanks! But how to calculate of the correct number of samples ? i think we can use the dimension of Render Target for calculation of number of samples.

 

6 hours ago, turanszkij said:

From those images it seem to work correctly, but you should either take more samples or blur the result after the radial blur. You can also do the radial blur pass in a lower resolution which can help with performance and the banding as well. I couldn't really understand your process as you explained so here is what I do:

1.) Draw the sun against scene depth buffer to a render target, depth test on to discard occluded sun pixels

2.) Radial blur on a low-res (0.5x) texture

3.) Draw the result on top with additive blending

Yes, but this is other Sun shafts technique? I think this technique are described there: herehere, also here ?

Share this post


Link to post
Share on other sites
5 hours ago, Andrey OGL_D3D said:

Matt_Aufderheide, turanszkij Thanks! But how to calculate of the correct number of samples ? i think we can use the dimension of Render Target for calculation of number of samples.

You don't have to calculate the correct number of samples, just tweak it until it looks good. I am using 35 samples, but rendering to half-resolution. This gives great results, but probably should take less samples. Also make sure you are using a linear texture filter when sampling.

5 hours ago, Andrey OGL_D3D said:

Yes, but this is other Sun shafts technique? I think this technique are described there: herehere, also here ?

It is the same technique, but for some reason all of them say to draw the scene depth buffer after the sun, but you probably already have a depth buffer by the time you are doing this effect, so best to just reuse that. By the radial blur I meant the shader that calculates vector from pixel to sun and samples along the direction.

Share this post


Link to post
Share on other sites
43 minutes ago, turanszkij said:

You don't have to calculate the correct number of samples, just tweak it until it looks good. I am using 35 samples, but rendering to half-resolution. This gives great results, but probably should take less samples. Also make sure you are using a linear texture filter when sampling.

Ok, Thanks again. I will try it and check linear filter.

44 minutes ago, turanszkij said:

It is the same technique, but for some reason all of them say to draw the scene depth buffer after the sun, but you probably already have a depth buffer by the time you are doing this effect, so best to just reuse that. By the radial blur I meant the shader that calculates vector from pixel to sun and samples along the direction

Yes, i have separate depth scene pass without Sun, now i understand, thanks

Share this post


Link to post
Share on other sites

Hi all!

After some modiifcation of shader i have the result for 16 samples:

image.thumb.png.5f35d407bc2589104f73b92d9640431c.png

the result for 32 samples:

image.thumb.png.7e1ae09735a907dd12598ad41c3d88a8.png

also i try to change ShaftParams:

const vec4    ShaftParams = vec4(0.05, 1.0, 0.1, 2.0);

But i have still some artefacts.

May be i should use additive blend + blur in low resolution, from turanszkij post, but can be simple to fix this implemenation.

I attached the new shader.

shaftsCryPS.glsl

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Advertisement