Search code examples
c++bgfx

BGFX shader compilation using shaderc


I'm trying to compile the following shader from this tutorial:

$input a_position, a_color0
$output v_color0

#include <bgfx_shader.sh>

void main()
{
    gl_Position = mul(u_modelViewProj, vec4(a_position, 1.0) );
    v_color0 = a_color0;
}

I am working on windows so I modified the command from the tutorial to target the windows platform:

"../../bgfx/.build/win64_vs2017/bin/shadercDebug.exe" -f v_simple.sc -o v_simple.bin --platform windows --type vertex --verbose -i "../../bgfx/src"

This fails to compile and I get the following output:

C:\Users\REDACTED\VisualStudioCode\bgfxTutorial\src\shaders>"../../bgfx/.build/win64_vs2017/bin/shadercDebug.exe" -f v_simple.sc -o v_simple.bin --platform windows --type vertex --verbose -i "../../bgfx/src"
Code:
---
     76: uniform mat4 u_proj;
     77: uniform mat4 u_invProj;
     78: uniform mat4 u_viewProj;
     79: uniform mat4 u_invViewProj;
     80: uniform mat4 u_model[32];
     81: uniform mat4 u_modelView;
     82: uniform mat4 u_modelViewProj;
     83: uniform vec4 u_alphaRef4;
     84: void main()
     85: {

>>>  86: gl_Position = ( (u_modelViewProj) * (vec4(a_position, 1.0) ) );
>>>  43:                                           ^

     87: v_color0 = a_color0;
     88: }
---
Error: (86,43): error: `a_position' undeclared
(86,38): error: cannot construct `vec4' from a non-numeric data type
(86,17): error: operands to arithmetic operators must be numeric
(87,1): error: `v_color0' undeclared
(87,1): error: value of type vec4 cannot be assigned to variable of type error

Failed to build shader.

I have the varying.def.sc file which would be necessary to compile:

// outputs
vec4 v_color0 : COLOR0;

// inputs
vec3 a_position : POSITION;
vec4 a_color0 : COLOR0;

I've also tried to use the makefile from the tutorials:

BGFX_DIR=../../bgfx
include $(BGFX_DIR)/scripts/shader.mk

(I've modifieds it to point to my bgfx dir)
When I try to run it, it results in empty directories regardless of the supplied TARGET variable.


Solution

  • Comments in varying.def.sc aren't parsed by shaderc correctly, you'll unfortunately have to remove them.