yum-mirror/glslang
git clone https://git.yummers.dev/yum-mirror/glslang
284ceb6d
main
1/* 2The MIT License (MIT) 3 4Copyright (c) 2022 Google LLC 5Copyright (c) 2022 Sascha Willems 6 7Permission is hereby granted, free of charge, to any person obtaining a copy 8of this software and associated documentation files (the "Software"), to deal 9in the Software without restriction, including without limitation the rights 10to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11copies of the Software, and to permit persons to whom the Software is 12furnished to do so, subject to the following conditions: 13 14The above copyright notice and this permission notice shall be included in all 15copies or substantial portions of the Software. 16 17THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23SOFTWARE. 24*/ 25 26struct VSInput 27{ 28[[vk ::location (0 )]]float3 Pos :POSITION0 ; 29[[vk ::location (1 )]]float3 Normal :NORMAL0 ; 30[[vk ::location (2 )]]float2 UV :TEXCOORD0 ; 31[[vk ::location (3 )]]float3 Color :COLOR0 ; 32 33// Instanced attributes 34[[vk ::location (4 )]]float3 instancePos :POSITION1 ; 35[[vk ::location (5 )]]float3 instanceRot :TEXCOORD1 ; 36[[vk ::location (6 )]]float instanceScale :TEXCOORD2 ; 37[[vk ::location (7 )]]int instanceTexIndex :TEXCOORD3 ; 38}; 39 40struct UBO 41{ 42float4x4 projection ; 43float4x4 modelview ; 44float4 lightPos ; 45float locSpeed ; 46float globSpeed ; 47}; 48 49cbuffer ubo : register(b0 ) {UBO ubo ; } 50 51struct VSOutput 52{ 53float4 Pos :SV_POSITION ; 54[[vk ::location (0 )]]float3 Normal :NORMAL0 ; 55[[vk ::location (1 )]]float3 Color :COLOR0 ; 56[[vk ::location (2 )]]float3 UV :TEXCOORD0 ; 57[[vk ::location (3 )]]float3 ViewVec :TEXCOORD1 ; 58[[vk ::location (4 )]]float3 LightVec :TEXCOORD2 ; 59}; 60 61VSOutput main (VSInput input ) 62{ 63VSOutput output = (VSOutput )0 ; 64output .Color = input .Color ; 65output .UV = float3 (input .UV ,input .instanceTexIndex ); 66 67// rotate around x 68float s = sin (input .instanceRot .x + ubo .locSpeed ); 69float c = cos (input .instanceRot .x + ubo .locSpeed ); 70 71float3x3 mx = {c ,- s ,0.0 , 72s ,c ,0.0 , 730.0 ,0.0 ,1.0 }; 74 75// rotate around y 76s = sin (input .instanceRot .y + ubo .locSpeed ); 77c = cos (input .instanceRot .y + ubo .locSpeed ); 78 79float3x3 my = {c ,0.0 ,- s , 800.0 ,1.0 ,0.0 , 81s ,0.0 ,c }; 82 83// rot around z 84s = sin (input .instanceRot .z + ubo .locSpeed ); 85c = cos (input .instanceRot .z + ubo .locSpeed ); 86 87float3x3 mz = {1.0 ,0.0 ,0.0 , 880.0 ,c ,- s , 890.0 ,s ,c }; 90 91float3x3 rotMat = mul (mz ,mul (my ,mx )); 92 93float4x4 gRotMat ; 94s = sin (input .instanceRot .y + ubo .globSpeed ); 95c = cos (input .instanceRot .y + ubo .globSpeed ); 96gRotMat [0 ]= float4 (c ,0.0 ,- s ,0.0 ); 97gRotMat [1 ]= float4 (0.0 ,1.0 ,0.0 ,0.0 ); 98gRotMat [2 ]= float4 (s ,0.0 ,c ,0.0 ); 99gRotMat [3 ]= float4 (0.0 ,0.0 ,0.0 ,1.0 ); 100 101float4 locPos = float4 (mul (rotMat ,input .Pos .xyz ),1.0 ); 102float4 pos = float4 ((locPos .xyz * input .instanceScale )+ input .instancePos ,1.0 ); 103 104output .Pos = mul (ubo .projection ,mul (ubo .modelview ,mul (gRotMat ,pos ))); 105output .Normal = mul ((float3x3 )mul (ubo .modelview ,gRotMat ),mul (rotMat ,input .Normal )); 106 107pos = mul (ubo .modelview ,float4 (input .Pos .xyz + input .instancePos ,1.0 )); 108float3 lPos = mul ((float3x3 )ubo .modelview ,ubo .lightPos .xyz ); 109output .LightVec = lPos - pos .xyz ; 110output .ViewVec = - pos .xyz ; 111return output ; 112}