diff options
author | Frederico Linhares <fred@linhares.blue> | 2023-10-09 14:46:09 -0300 |
---|---|---|
committer | Frederico Linhares <fred@linhares.blue> | 2023-10-09 15:58:14 -0300 |
commit | ba447583c74d44c6b07c5409918207157f921efe (patch) | |
tree | 56cd1c36a8e77540136c8871eb3b94f0adf37139 /glsl | |
parent | 8fa221cb60c19638d4ad0833965fee605593eea3 (diff) |
feat Render sprite in a 3D position
Diffstat (limited to 'glsl')
-rw-r--r-- | glsl/shader_sprite_3d.frag.glsl | 42 | ||||
-rw-r--r-- | glsl/shader_sprite_3d.vert.glsl | 73 |
2 files changed, 115 insertions, 0 deletions
diff --git a/glsl/shader_sprite_3d.frag.glsl b/glsl/shader_sprite_3d.frag.glsl new file mode 100644 index 0000000..fe823f8 --- /dev/null +++ b/glsl/shader_sprite_3d.frag.glsl @@ -0,0 +1,42 @@ +/* + * Copyright 2022-2023 Frederico de Oliveira Linhares + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#version 450 +#extension GL_ARB_separate_shader_objects : enable + +struct DataTransferObject +{ + vec4 frag_color; + vec2 frag_texture_coord; +}; + +layout(location = 0) in DataTransferObject in_dto; + +layout(location = 0) out vec4 out_color; + +layout(set = 0, binding = 1) uniform UBOWorld +{ + vec3 directional_light_direction; + vec4 directional_light_color; +} ubo_world; + +layout(set = 2, binding = 1) uniform sampler2D texture_sampler; + +void +main() +{ + out_color = texture(texture_sampler, in_dto.frag_texture_coord); +} diff --git a/glsl/shader_sprite_3d.vert.glsl b/glsl/shader_sprite_3d.vert.glsl new file mode 100644 index 0000000..f7c6cf6 --- /dev/null +++ b/glsl/shader_sprite_3d.vert.glsl @@ -0,0 +1,73 @@ +/* + * Copyright 2022-2023 Frederico de Oliveira Linhares + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#version 450 +#extension GL_ARB_separate_shader_objects : enable + +layout(location = 0) in vec2 in_texture_coord; + +layout(location = 0) out DataTransferObject +{ + vec4 frag_color; + vec2 frag_texture_coord; +} out_dto; + +layout(set = 0, binding = 0) uniform UBOWorld +{ + vec4 ambient_light_color; +} ubo_world; + +layout(set = 1, binding = 0) uniform UBOView +{ + mat4 view; + mat4 proj; +} ubo_view; + +layout(set = 2, binding = 0) uniform UBOSprite3D +{ + vec3 position; + vec2 size; +} ubo_position; + +void +main() +{ + vec4 position = vec4(ubo_position.position, 1.0); + position = ubo_view.view * position; + switch(gl_VertexIndex) + { + case 0: + position.x -= ubo_position.size.x/2; + position.y -= ubo_position.size.y/2; + break; + case 1: + position.x -= ubo_position.size.x/2; + position.y += ubo_position.size.y/2; + break; + case 2: + position.x += ubo_position.size.x/2; + position.y -= ubo_position.size.y/2; + break; + case 3: + position.x += ubo_position.size.x/2; + position.y += ubo_position.size.y/2; + break; + } + gl_Position = ubo_view.proj * position; + + out_dto.frag_color = ubo_world.ambient_light_color; + out_dto.frag_texture_coord = in_texture_coord; +} |