- Home /
What is this shader?
I profiled my game using Mali Graphics Debugger 3.5. And found out, One shader is costing a lot of unexpected cycles. I don't know what is this shader, and why so much heavy. It is 86 shader in the picture.
It is called at the end of frame. (last draw call)
Here is the function call.
glDrawElements
(
mode = GL_TRIANGLES,
count = 3,
type = GL_UNSIGNED_SHORT,
indices = NULL
)
Uniforms
Index / Location / Name / Type / Value
0 / 0 / tex / GL_SAMPLER_2D / [0]
1 / 1 / uvOffsetAndScale / GL_FLOAT_VEC4 / [0.0, 0.0, 1.0, 1.0]
Vertices
0 -1.0, 3.0, 0.0, 2.0
1 -1.0, -1.0, 0.0, 0.0
2 3.0, -1.0, 2.0, 0.0
Indices
[0, 1, 2]
So, It is a single triangle, That covers whole perspective coordniates.
And the fragment count is equal to screen.width * screen.height.
I deleted every my rendered objects but this shader is steel running(even disabled the camera).
Vertex shader code
#version 300 es
#define ATTRIBUTE_IN in
#define VARYING_IN in
#define VARYING_OUT out
#define DECLARE_FRAG_COLOR out vec4 fragColor
#define FRAG_COLOR fragColor
#define SAMPLE_TEXTURE_2D texture
precision highp float;
ATTRIBUTE_IN vec4 vertex;
uniform vec4 uvOffsetAndScale;
VARYING_OUT vec2 texCoord;
void main()
{
gl_Position = vec4(vertex.xy, 0.0, 1.0);
texCoord = vertex.zw * uvOffsetAndScale.zw + uvOffsetAndScale.xy;
}
Fragment shader code
#version 300 es
#define ATTRIBUTE_IN in
#define VARYING_IN in
#define VARYING_OUT out
#define DECLARE_FRAG_COLOR out vec4 fragColor
#define FRAG_COLOR fragColor
#define SAMPLE_TEXTURE_2D texture
precision mediump float;
VARYING_IN vec2 texCoord;
#ifdef DECLARE_FRAG_COLOR
DECLARE_FRAG_COLOR;
#endif
uniform sampler2D tex;
void main()
{
vec4 c = SAMPLE_TEXTURE_2D(tex, texCoord);
FRAG_COLOR = vec4(c.rgb, 1.0);
}
Thank you.
---------------- Additonal Info -----------------
So I created a new Unity project.(Unity 5.3.4f) Here is what i have done.
Add single empty scene to "Scenes in build" list.
Set zero "Always Included Shaders" and "Preloaded Shaders" in the GraphicsSettings.
Set android bundle ID in the PlayerSettings.
Add libMGD.so and custom Activity to load the libMGD.so file. (to connect with Mali Graphic Debugger. This step may make side effects. But this unrecognized shading is occured at Galaxy S4 device with Adreno GPU Profiler)
Build android apk and install it to my Galaxy S6 device.
And the result is same. The shader steel running. In this time it, There is only Unity Logo in the screen, And not disappear, becuase there is no camera.
Here is draw calls of whole frames.
Frame 0 ~ Frame 2 (9 vertices, 5 draws, )
First Render Pass
glClear
glClear GL_DEPTH_BUFFER_BIT
glDrawElements 6 vertices, no indices
Secnd Render Pass
glClear
glDrawElements 3 vertices, 3 indices -> It is the shader of this question.
Frame 3 (30243 vertices, 15 draws)
First Render Pass
glClear
glClear GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT
glDrawArrays 5040 vertices
glClear GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT
glDrawArrays 5040 vertices
glClear GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT
glDrawArrays 5040 vertices
glClear GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT
glDrawArrays 5040 vertices
glClear GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT
glDrawArrays 5040 vertices
glClear GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT
glDrawArrays 5040 vertices
Second Render Pass
glClear
glDrawElements 3 vertices
Frame 4 ~ end of frame
First Render Pass
glClear
glDrawElements 3 vertices
So the shader is running every frames.
Additonally, at the frame 3, the app draws sphere that has dense vertices near the equator with 5040 vertices 6 times. I don't know what it is, But it would be necessary for Unity engine system I guess??
Curious. You get this even with no camera or rendered objects in your scene. No UI? No Graphics.Draw$$anonymous$$esh? No image effects or RenderTextures? Can't think why you've got a full screen shader otherwise, but interested to know if you find out. +1 for well-researched question too :)
Complete stab in the dark, but something to do with deferred rendering maybe?
I disabled all deferred supports at GraphicsSettings and tested with "Forward" and "Legacy Vertex-lit" rendering mode at PlayerSettings but the result is same.
Sorry, not an expert on shaders here, but my first thought is the procedural skybox shader maybe? "sphere that has dense vertices near the equator" sounds kind of like that to me. 6x for the cubemap effect?
Do you have the default skybox in the lighting settings?
You were right. The sphere was Skybox. I changed Ambient Source to Skybox to Color And the sphere render call is gone. Unfortunately the issue steel exists.
I re-captured with adreno profiler, and found something. This shader draws entire screen. Unity camera draws to render buffer and finally this shader draws complete rendered scene "again" to another back buffer.