项目作者: sienkiewiczkm

项目描述 :
Shader markup language for GLSL shaders.
高级语言: C++
项目地址: git://github.com/sienkiewiczkm/shabui.git
创建时间: 2017-02-21T13:47:46Z
项目社区:https://github.com/sienkiewiczkm/shabui

开源协议:MIT License

下载


Shabui

Shabui is shader building tool designed to simplify my personal projects. It is special language that helps generation shaders in single GLSL shader pipeline. For current features see issues and code directly. This is not mature project yet.

Syntax

Example file

  1. version 1;
  2. version glsl 330 core;
  3. shader "Example Shader"
  4. {
  5. shared
  6. <<<
  7. uniform vec3 lightDirection;
  8. uniform mat4 model;
  9. uniform mat4 view;
  10. uniform mat4 projection;
  11. >>>;
  12. struct vertexLayout
  13. {
  14. vec3 position {location = 0},
  15. vec3 normal {location = 1}
  16. };
  17. struct vertexOutput
  18. {
  19. vec3 Normal,
  20. vec3 ViewLightDirection
  21. };
  22. func vertex(vertexLayout vertex): vertexOutput result
  23. <<<
  24. vec4 viewPosition = view * model * vec4(vertex.position, 1.0);
  25. gl_Position = projection * viewPosition;
  26. result.Normal = normalize(
  27. (view * (transpose(inverse(model)) * vec4(vertex.normal, 0))).xyz
  28. );
  29. result.ViewLightDirection = normalize(
  30. (view * vec4(lightDirection, 0)).xyz
  31. );
  32. >>>;
  33. func fragment(vertexOutput vsOut): vec4 result
  34. <<<
  35. vec3 lightDir = normalize(vsOut.ViewLightDirection);
  36. vec3 normal = normalize(vsOut.Normal);
  37. float diffuse = dot(lightDir, normal);
  38. result = vec4(vec3(diffuse), 1.0);
  39. >>>;
  40. };

Syntax cheatsheet

Shabui is case sensitive. Every statement should end with ;.

Code Allowed in Meaning
version VERSION global Marks version of a shabui file. Currently can be anything because exact version 1 grammar hasn’t been estabilished yet.
version glsl VERSION PROFILE global Specifies exact version of GLSL used in this file. It will generate #version VERSION PROFILE on top of each GLSL shader file.
shader "SHADER NAME" { ... } global Marks shader section.
struct name { ... } shader Creates a structure which can be used as interface block. If interface block is not available (eg. input for vertex shader) contents of this structure will be put into global scope and vertex. (see example above) will be removed from GLSL code string.
varType varName { location: INT } struct Optional properties of variable definition. It marks layout for inputs for Vertex Shader. It generates layout(location=INT) in front of code that generates that variable in GLSL.
func name(...inputs...): ...outputs... <<<code>>> shader Defines shader function. Inputs and outputs are C-style variable lists, if multiple outputs are present they have to be surrounded with parentheses. All inputs/outputs must be named. Currently, if non-primitive type is used in function it must be the only argument.
<<< GLSL code block >>> argument Code will be copied and pasted directly, except changes explained in struct section.

Usage (CMake)

Add project as submodule, include that in CMakeLists.txt and then include shabui/GLSLLoader.hpp where you need it. Look at source of that file for details.