What is best method of performance for cheap coloring

@horusscope

Lol.
No way.
It is :arrow_down:

Correct :+1:

Can you use the shaders 1 at a time with all the objects in view, and see which has the largest impact?
edit: make sure you have lights/walls/reflective surfaces in the scene approx equal to what you would get on average

@horusscope

Already did repeatedly.
It was these the most :arrow_down:

I’m sorry.
But are you not understanding my posts (?)

Sorry, no I wasn’t. I thought you were asking whether textures or material color used more CPU. Your problem is probably with lighting and shadows

@horusscope

Yes.
Baking takes along time for me tho :wink:
I have done that repeatedly tho.
It’s semi-ok :ok_hand:

SHADERS are per-pixel & i’m using split-screen so that’s * 2 computing I think . . .

HDR and bloom are expensive. There might be more performance friendly variants of some GLSL filters though, I say surf the resources and see what you find.

@Liebranca

I already have & looking for other ways to cut-back on performance hazards.
Hence this thread about which way is the best for color performance.

The fragment shader is per-pixel.
Vertex shaders are per vertex

Have you read any of the shader code which is running in your game? You keep saying shaders and this might be stupid but to me it is very ambiguous because I don’t know if you wrote them or someone else wrote them or it’s the default shader or etc, sorry…

It’s a collection of post processing effects written in GLSL by different people and put into a single package by a guy who did BGE tutorials back in the day.

What did you think of them? Heavy? Light?
A shader like you were talking about which is only a UV could be just this:

	 varying highp vec2 VaryingTextureCoordinate;
	 uniform sampler2D UniformSampler;
	 void main( ) {
	     gl_FragColor = texture2D(UniformSampler, VaryingTextureCoordinate);
	 }

but I don’t for the life of me know what he is actually running in the darn thing, so how can I even guess? If you have any clue maybe you could share

I have the scripts and use some of them, but I barely know enough GLSL to do some basic image manipulation; I’m likely not the best suited to do an evaluation.

If you’re fluent in shading languages though… here’s what the bloom looks like,

uniform sampler2D bgl_RenderedTexture;

uniform float bloom_amount = 0.5;
const float BRIGHT_PASS_OFFSET = 0.5;

#define blurclamp 0.002
#define bias 0.01

#define KERNEL_SIZE 3.0

vec2 texcoord = vec2(gl_TexCoord[0]).st;

vec4 bright(vec2 coo)
{
vec4 color = texture2D(bgl_RenderedTexture, coo);

color = max(color - bloom_amount, 0.0);

return color / (color + BRIGHT_PASS_OFFSET); 
}


void main(void)
{
vec2 blur = vec2(clamp( bias, -blurclamp, blurclamp ));

vec4 col = vec4( 0, 0, 0, 0 );
for ( float x = -KERNEL_SIZE + 1.0; x < KERNEL_SIZE; x += 1.0 )
{
for ( float y = -KERNEL_SIZE + 1.0; y < KERNEL_SIZE; y += 1.0 )
{
col += bright( texcoord + vec2( blur.x * x, blur.y * y ) );
}
}
col /= ((KERNEL_SIZE+KERNEL_SIZE)-1.0)*((KERNEL_SIZE+KERNEL_SIZE)-1.0);
gl_FragColor = col + texture2D(bgl_RenderedTexture, texcoord);
}

I have very little idea what’s going on in there. Maybe it can be optimized for low-end systems?

It’s an image convolution filter, you can see a visual example here http://setosa.io/ev/image-kernels/
(it has a widget where you can tweak the numbers for example and put a sobel or Laplace edge detection filter

Sobel horizontal filter
 1   2   1
 0   0   0
-1  -2  -1

Sobel vertical filter
-1   0   1
-2   0   2
-1   0   1

Laplace filter
1   1   1
1  -8   1
1   1   1

x = -2 ; x < 3 ; ++x means the kernel is 5x5 (huge)
this is definitely a heavy thing to run per fragment

@horusscope

(no offense) But I really think your not reading what I post.

@Liebranca is right on this one.

You seem like a guy this would actually help, so I’m going to brief you on what this code really is real quick.

This holds the texture (image)
uniform sampler2D bgl_RenderedTexture;
You can see it ultimately get assigned at the end:
gl_FragColor = col + texture2D(bgl_RenderedTexture, texcoord);

These are constants which define how much bloom (I’m sure you knew that)

uniform float bloom_amount = 0.5;
const float BRIGHT_PASS_OFFSET = 0.5;

#define blurclamp 0.002
#define bias 0.01

This defines how much sample space the filter uses, that is, it tries every pixel in a 5x5 radius and makes a type of average for the 1 pixel value in the middle. Although, 3.0 is a lie because it does (negative)SIZE+1 to (positive)SIZE so it’s actually a kernel size of 5
#define KERNEL_SIZE 3.0

This is the UV map input… probably obvious
vec2 texcoord = vec2(gl_TexCoord[0]).st;

This function is used by the ‘sigma’, it defines the value to average

vec4 bright(vec2 coo)
{
vec4 color = texture2D(bgl_RenderedTexture, coo);
// color was from the actual image sampler @ UV coordinate
color = max(color - bloom_amount, 0.0);
// notice it's just referencing constants
return color / (color + BRIGHT_PASS_OFFSET); 
}

‘MAIN’ is the function which is called per fragment (“pixel”)

void main(void)
{
// This could literally be a constant outside of main
vec2 blur = vec2(clamp( bias, -blurclamp, blurclamp ));
// It's summing the average into this variable 'col'
vec4 col = vec4( 0, 0, 0, 0 );
for x...
   for y...
      // this is that function from above where it just reads the image/texture
      // blur is a constant
      col += bright( texcoord + vec2( blur.x * x, blur.y * y ) );

// it's an average, so we divide by 25, which is the number of pixels we sampled
// he could have just wrote 25
col /= ((KERNEL_SIZE+KERNEL_SIZE)-1.0)*((KERNEL_SIZE+KERNEL_SIZE)-1.0);

// then finally like I said at the beginning, it sets the pixel color for the UV coord, using an "ADD" operation (similar to add in blender mix shaders)
gl_FragColor = col + texture2D(bgl_RenderedTexture, texcoord);
}
2 Likes

That’s tres cool. Very clear explanation, thanks. c:

@horusscope

Is this lecture :wink: for Me or @Liebranca (?)

I thought you had given up and @Liebranca would go on to write custom shader code.

If you’re using that shader that he linked, you could try reducing the kernel size to 2, which would speed up that shader by 3x. I don’t know what kind of advice or answer you want, and I did already tell you that non-variable color is faster because it’s just a constant value and doesn’t have to be sampled. The best I can do is help you to optimize the shaders and I asked you from the beginning to please provide code where your game is getting bottlenecked. I also told you to reduce the number of lights per object, 3 being just about too many.

@horusscope

Thx.
Btw, I thought BGE was unoptimized with shaders & that UPBGE was the one that had shader optimization. Am I wrong (?)

P.S Are you Discord user abluehorse (?)