Changeset 055750a in opengl-game for shaders


Ignore:
Timestamp:
Dec 4, 2019, 9:33:43 PM (5 years ago)
Author:
Dmitry Portnoy <dmitry.portnoy@…>
Branches:
feature/imgui-sdl, master, points-test
Children:
785333b, cf727ca
Parents:
e1308e8
Message:

In VulkanGame, use SSBOs in the ship and scene shaders to store per-object data (currently just the model matrix)

Location:
shaders
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • shaders/scene.frag

    re1308e8 r055750a  
    22#extension GL_ARB_separate_shader_objects : enable
    33
    4 layout(binding = 1) uniform sampler2D texSampler;
     4layout(binding = 2) uniform sampler2D texSampler;
    55
    66layout(location = 0) in vec3 fragColor;
  • shaders/scene.vert

    re1308e8 r055750a  
    22#extension GL_ARB_separate_shader_objects : enable
    33
     4struct Object {
     5   mat4 model;
     6};
     7
    48layout (binding = 0) uniform UniformBufferObject {
    5    mat4 model;
    69   mat4 view;
    710   mat4 proj;
    811} ubo;
     12
     13layout(binding = 1) readonly buffer StorageBufferObject {
     14    Object objects[];
     15} sbo;
    916
    1017layout(location = 0) in vec3 inPosition;
     
    1926   fragTexCoord = inTexCoord;
    2027
    21    gl_Position = ubo.proj * ubo.view * ubo.model * vec4(inPosition, 1.0);
     28   gl_Position = ubo.proj * ubo.view * sbo.objects[0].model * vec4(inPosition, 1.0);
    2229}
  • shaders/ship.vert

    re1308e8 r055750a  
    22#extension GL_ARB_separate_shader_objects : enable
    33
     4struct Object {
     5   mat4 model;
     6};
     7
    48layout (binding = 0) uniform UniformBufferObject {
    5    mat4 model;
    69   mat4 view;
    710   mat4 proj;
    811} ubo;
     12
     13layout(binding = 1) readonly buffer StorageBufferObject {
     14    Object objects[];
     15} sbo;
    916
    1017layout(location = 0) in vec3 vertex_position;
     
    2633// Check Anton's book to see how to fix this
    2734void main() {
    28    position_eye = vec3(ubo.view * ubo.model * vec4(vertex_position, 1.0));
     35   position_eye = vec3(ubo.view * sbo.objects[0].model * vec4(vertex_position, 1.0));
    2936   //position_eye = vec3(view * model_mats[ubo_index] * vec4(vertex_position, 1.0));
    3037
    3138   // Using 0.0 instead of 1.0 means translations won't effect the normal
    32    normal_eye = normalize(vec3(ubo.view * ubo.model * vec4(vertex_normal, 0.0)));
     39   normal_eye = normalize(vec3(ubo.view * sbo.objects[0].model * vec4(vertex_normal, 0.0)));
    3340   //normal_eye = normalize(vec3(view * model_mats[ubo_index] * vec4(vertex_normal, 0.0)));
    3441   color = vertex_color;
Note: See TracChangeset for help on using the changeset viewer.