bkaradzic / bgfx

Cross-platform, graphics API agnostic, "Bring Your Own Engine/Framework" style rendering library.
https://bkaradzic.github.io/bgfx/overview.html
BSD 2-Clause "Simplified" License
15.15k stars 1.95k forks source link

can't generate example-37-gpudrivenrendering shaders for essl #1593

Open mean-ui-thread opened 5 years ago

mean-ui-thread commented 5 years ago
shaderc -f /home/mchiasson/git/bgfx/examples/37-gpudrivenrendering/fs_gdr_instanced_indirect_rendering.sc -i /home/mchiasson/git/bgfx/src -o /home/mchiasson/git/bgfx/examples/runtime/shaders/essl/fs_gdr_instanced_indirect_rendering.bin --platform android --type fragment
Code:
---
    354: void main()
    355: {
    356: vec4 color = u_color[uint(v_materialID)];
    357: if (color.w < 1.0f)
    358: {
    359: if ( (int(gl_FragCoord.x) % 2) == (int(gl_FragCoord.y) % 2) )
    360: {
    361: discard;
    362: }
    363: }

>>> 364: gl_FragColor = vec4(color.xyz, 1.0);
>>>   1: ^

    365: }
---
Error: (364,1): error: `gl_FragColor' undeclared
(364,1): error: value of type vec4 cannot be assigned to variable of type error

Failed to build shader.

same issue with --platform nacl and --platform asm.js

mean-ui-thread commented 5 years ago

I managed to fixed it by doing these two changes:

diff --git a/examples/37-gpudrivenrendering/fs_gdr_instanced_indirect_rendering.sc b/examples/37-gpudrivenrendering/fs_gdr_instanced_indirect_rendering.sc
index 14f484991..6ad17cb3b 100644
--- a/examples/37-gpudrivenrendering/fs_gdr_instanced_indirect_rendering.sc
+++ b/examples/37-gpudrivenrendering/fs_gdr_instanced_indirect_rendering.sc
@@ -11,12 +11,12 @@ uniform vec4 u_color[32];

 void main()
 {
-       vec4 color = u_color[uint(v_materialID)];
+       vec4 color = u_color[int(v_materialID)];

        if (color.w < 1.0f)
        {
                //render dithered alpha
-               if ( (int(gl_FragCoord.x) % 2) == (int(gl_FragCoord.y) % 2) )
+               if ( mod(gl_FragCoord.x, 2.0) == mod(gl_FragCoord.y, 2.0) )
                {
                        discard;
                }
diff --git a/examples/37-gpudrivenrendering/varying.def.sc b/examples/37-gpudrivenrendering/varying.def.sc
index bab2e384d..f0615767d 100644
--- a/examples/37-gpudrivenrendering/varying.def.sc
+++ b/examples/37-gpudrivenrendering/varying.def.sc
@@ -6,4 +6,4 @@ vec4 i_data2     : TEXCOORD5;
 vec4 i_data3     : TEXCOORD4;

 vec2  v_texcoord0 : TEXCOORD0;
-flat float v_materialID : TEXCOORD0;
+float v_materialID : TEXCOORD0;