Jump to content

Updating shaders to use no sampling.


reepblue
 Share

Recommended Posts

Hey all,

 

I decided for fun to sync up the Vectronic Demo with the latest version. I also wanted to see how the game looked with multi sampling off. when I booted up the game however, it lacked fog. No big deal I thought, I'll just use the #if SAMPLES==0 statements like the light shaders do, and make ms textures 2d textures.

 

I did just that, and it works.... Only if SAMPLES==0 and MSAA is set to 0 as well. I'm curious why there isn't an automatic system in the shader system to detect if MSAA is 0. (I thought #if SAMPLES==0 was it.)

 

I've looked at the decals and they use an int that's most likely toggled under the hood. How would I do this with any Post Process effects that are loaded? In the PBR code, there was a way to toggle an int value, but could I just load the shader and toggle it, or do I need to fetch the active camera, get the shaders of the post processing effects, and do it that way?

 

Perhaps a global sampling value would be nice here so other users don't collide with this issue while making/updating shaders. Maybe actually Set SAMPLES to 0 when Multisampling is 0? This might be more of a request more than anything.

 

Thanks.

 

Oh, for those who want the semi-fix, here:

 

_passthrough.shader (Frag)

#version 400

#ifndef SAMPLES

#define SAMPLES 1

#endif

 

uniform bool isbackbuffer;

uniform vec2 buffersize;

uniform vec2 camerarange;

uniform float currenttime;

 

out vec4 fragData0;

 

uniform sampler2D texture1;

 

#if SAMPLES==0

uniform sampler2DMS texture2;

uniform sampler2DMS texture3;

#else

uniform sampler2D texture2;

uniform sampler2D texture3;

#endif

 

void main()

{

vec2 icoord = vec2(gl_FragCoord.xy/buffersize);

if (isbackbuffer) icoord.y = 1.0 - icoord.y;

vec4 color = texture(texture1,icoord);

fragData0=color;

}

 

_klepto_fog.shader (Frag)

#version 400

#ifndef SAMPLES

#define SAMPLES 1

#endif

 

uniform sampler2D texture1;

uniform samplerCube texture2;

 

#if SAMPLES==0

uniform sampler2D texture3;

#else

uniform sampler2DMS texture3;

#endif

 

uniform bool isbackbuffer;

uniform vec2 buffersize;

out vec4 fragData0;

uniform samplerCube uTexture;

smooth in vec3 eyeDirection;

uniform vec2 camerarange;

uniform float camerazoom;

uniform vec3 cameraposition;

uniform mat4 camerainversematrix;

uniform mat4 projectionmatrix;

uniform mat4 cameramatrix;

 

uniform vec2 fogrange = vec2(0.0,15.0);

uniform vec4 fogcolor = vec4(0.72,0.73,0.67,1.0);

uniform vec2 fogangle = vec2(5.0,15.0);

uniform bool fogislocal = false;

uniform float clipheight= 0.0;

 

 

float DepthToZPosition(in float depth) {

return camerarange.x / (camerarange.y - depth * (camerarange.y - camerarange.x)) * camerarange.y;

}

 

void main() {

//integer screen coordinates

//needed for depth lookup

ivec2 icoord = ivec2(gl_FragCoord.xy);

if (isbackbuffer) icoord.y = int(buffersize.y) - icoord.y;

 

//floating screencoords normalised to range 0-1

vec2 coord = vec2(gl_FragCoord.xy/buffersize);

if (isbackbuffer) coord.y = 1.0 - coord.y;

 

//fetch depth value

float depth;

 

#if SAMPLES==0

depth = texelFetch(texture3,icoord,0).x;

#else

depth = texelFetch(texture3,icoord,0).x;

#endif

 

//calculating worldposition from cameramatrix,screenposition and depth

//normalize it to get the cubecoords

vec3 screencoord;

screencoord = vec3(((coord.x)-0.5) * 2.0,((coord.y)-0.5) * 2.0 / (buffersize.x/buffersize.y),DepthToZPosition( depth ));

screencoord.x *= screencoord.z;

screencoord.y *= -screencoord.z;

vec4 worldpostemp= vec4(screencoord,1.0) * camerainversematrix;

vec3 worldpos = worldpostemp.xyz;// / 1.0-worldpostemp.w;

worldpos+=cameraposition;

vec3 cubecoord = normalize(worldpos.xyz);

 

fragData0 = texture(texture1,coord);

 

if(depth == 1.0) //no geometry rendered --> background

{

vec3 normal=normalize(cubecoord);

normal.y=max(normal.y,0.0);

float angle=asin(normal.y)*57.2957795-fogangle.x;

float fogeffect=1.0-clamp(angle/(fogangle.y-fogangle.x),0.0,1.0);

fogeffect *= fogcolor.w;

fragData0=fragData0*(1.0-fogeffect)+fogeffect*fogcolor;

}

else // no background - render input + fog to output

{

float lineardepth = DepthToZPosition(depth);

float fogeffect = clamp( 1.0 - (fogrange.y - lineardepth) / (fogrange.y - fogrange.x) , 0.0, 1.0 );

if (fogislocal && lineardepth > fogrange.y) fogeffect=0.0;

fragData0 = fragData0 * (1.0 - fogeffect) + fogcolor * fogeffect;

}

//if (cameramatrix[3][1] <= -0.99) fragData0=texture(texture1, icoord);

}

Cyclone - Ultra Game System - Component PreprocessorTex2TGA - Darkness Awaits Template (Leadwerks)

If you like my work, consider supporting me on Patreon!

Link to comment
Share on other sites

Bout time! I've went to the post to see what they've said, but I figure it was a PM/E-mail as nothing else was posted.

 

I still like the idea of turning multi-sampling completely off personally, but I understand that this is getting real messy, real fast. However, you're already knee deep in this process...

Cyclone - Ultra Game System - Component PreprocessorTex2TGA - Darkness Awaits Template (Leadwerks)

If you like my work, consider supporting me on Patreon!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...