yum-mirror/glslang
git clone https://git.yummers.dev/yum-mirror/glslang
284ceb6d
main
1/* 2The MIT License (MIT) 3 4Copyright (c) 2022 Sascha Willems 5 6Permission is hereby granted, free of charge, to any person obtaining a copy 7of this software and associated documentation files (the "Software"), to deal 8in the Software without restriction, including without limitation the rights 9to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10copies of the Software, and to permit persons to whom the Software is 11furnished to do so, subject to the following conditions: 12 13The above copyright notice and this permission notice shall be included in all 14copies or substantial portions of the Software. 15 16THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22SOFTWARE. 23*/ 24 25#version 450 26 27// Vertex attributes 28layout (location = 0 )in vec3 inPos ; 29layout (location = 1 )in vec3 inNormal ; 30layout (location = 2 )in vec2 inUV ; 31layout (location = 3 )in vec3 inColor ; 32 33// Instanced attributes 34layout (location = 4 )in vec3 instancePos ; 35layout (location = 5 )in vec3 instanceRot ; 36layout (location = 6 )in float instanceScale ; 37layout (location = 7 )in int instanceTexIndex ; 38 39layout (binding = 0 )uniform UBO 40{ 41mat4 projection ; 42mat4 modelview ; 43vec4 lightPos ; 44float locSpeed ; 45float globSpeed ; 46}ubo ; 47 48layout (location = 0 )out vec3 outNormal ; 49layout (location = 1 )out vec3 outColor ; 50layout (location = 2 )out vec3 outUV ; 51layout (location = 3 )out vec3 outViewVec ; 52layout (location = 4 )out vec3 outLightVec ; 53 54void main () 55{ 56outColor = inColor ; 57outUV = vec3 (inUV ,instanceTexIndex ); 58 59mat3 mx ,my ,mz ; 60 61// rotate around x 62float s = sin (instanceRot .x + ubo .locSpeed ); 63float c = cos (instanceRot .x + ubo .locSpeed ); 64 65mx [0 ]= vec3 (c ,s ,0.0 ); 66mx [1 ]= vec3 (- s ,c ,0.0 ); 67mx [2 ]= vec3 (0.0 ,0.0 ,1.0 ); 68 69// rotate around y 70s = sin (instanceRot .y + ubo .locSpeed ); 71c = cos (instanceRot .y + ubo .locSpeed ); 72 73my [0 ]= vec3 (c ,0.0 ,s ); 74my [1 ]= vec3 (0.0 ,1.0 ,0.0 ); 75my [2 ]= vec3 (- s ,0.0 ,c ); 76 77// rot around z 78s = sin (instanceRot .z + ubo .locSpeed ); 79c = cos (instanceRot .z + ubo .locSpeed ); 80 81mz [0 ]= vec3 (1.0 ,0.0 ,0.0 ); 82mz [1 ]= vec3 (0.0 ,c ,s ); 83mz [2 ]= vec3 (0.0 ,- s ,c ); 84 85mat3 rotMat = mz * my * mx ; 86 87mat4 gRotMat ; 88s = sin (instanceRot .y + ubo .globSpeed ); 89c = cos (instanceRot .y + ubo .globSpeed ); 90gRotMat [0 ]= vec4 (c ,0.0 ,s ,0.0 ); 91gRotMat [1 ]= vec4 (0.0 ,1.0 ,0.0 ,0.0 ); 92gRotMat [2 ]= vec4 (- s ,0.0 ,c ,0.0 ); 93gRotMat [3 ]= vec4 (0.0 ,0.0 ,0.0 ,1.0 ); 94 95vec4 locPos = vec4 (inPos .xyz * rotMat ,1.0 ); 96vec4 pos = vec4 ((locPos .xyz * instanceScale )+ instancePos ,1.0 ); 97 98gl_Position = ubo .projection * ubo .modelview * gRotMat * pos ; 99outNormal = mat3 (ubo .modelview * gRotMat )* inverse (rotMat )* inNormal ; 100 101pos = ubo .modelview * vec4 (inPos .xyz + instancePos ,1.0 ); 102vec3 lPos = mat3 (ubo .modelview )* ubo .lightPos .xyz ; 103outLightVec = lPos - pos .xyz ; 104outViewVec = - pos .xyz ; 105}