Slastraf Posted March 4, 2024 Posted March 4, 2024 Hi, I try to program a shader but for my use case I need a time value. For this I tried to use the extension #extension GL_EXT_shader_realtime_clock : enable // NOT ALLOWED which is not allowed in the current setup. I dont know much about Vulcan or shaders, but could this be shipped with the next update ? That would make things a lot easier as I also try to make an animated (sprite) material which is not possible without a time value. On the other hand , i tried passing it trough c++ directly using a uniform variable uniform float u_Time; which would lead to the following error. 'non-opaque uniforms outside a block' : not allowed when using GLSL for Vulkan Looking forward for a solution, as I said I am not experienced in shaders so maybe there already is. Quote
Solution SpiderPig Posted March 4, 2024 Solution Posted March 4, 2024 There is a CurrentTime variable in UniformBlocks.glsl that you can use. 1 Quote
Slastraf Posted March 4, 2024 Author Posted March 4, 2024 #version 450 #extension GL_GOOGLE_include_directive : enable #extension GL_ARB_separate_shader_objects : enable //#extension GL_EXT_shader_realtime_clock : enable // NOT ALLOWED #include "../Base/Fragment.glsl" #include "../Base/UniformBlocks.glsl" #define PI 3.14159 float vDrop(vec2 uv,float t) { uv.x = uv.x*128.0; // H-Count float dx = fract(uv.x); uv.x = floor(uv.x); uv.y *= 0.05; // stretch float o=sin(uv.x*215.4); // offset float s=cos(uv.x*33.1)*.3 +.7; // speed float trail = mix(95.0,35.0,s); // trail length float yv = fract(uv.y + t*s + o) * trail; yv = 1.0/yv; yv = smoothstep(0.0,1.0,yv*yv); yv = sin(yv*PI)*(s*5.0); float d2 = sin(dx*PI); return yv*(d2*d2); } void main() { //vec2 p = (vertexWorldPosition.xz - 0.5 * (vertexWorldPosition.xz+500.0)) / (vertexWorldPosition.xz-250.0); vec2 p = (vertexWorldPosition.xz); float d = length(p)+0.1; p = vec2(atan(p.x, p.y) / PI, 2.5 / d); float t = CurrentTime*0.004; vec3 col = vec3(1.55,0.65,.225) * vDrop(p,t); // red col += vec3(0.55,0.75,1.225) * vDrop(p,t+0.33); // blue col += vec3(0.45,1.15,0.425) * vDrop(p,t+0.66); // green outColor[0] = vec4(col*(d*d), 1.0); //Material material = materials[materialID]; //outColor[0] = material.diffuseColor * color; //int textureID = GetMaterialTextureHandle(material, TEXTURE_DIFFUSE); //if (textureID != -1) outColor[0] *= texture(texture2DSampler[textureID], texcoords.xy); //Camera distance fog //if ((entityflags & ENTITYFLAGS_NOFOG) == 0) ApplyDistanceFog(outColor[0].rgb, vertexWorldPosition.xyz, CameraPosition); //if ((RenderFlags & RENDERFLAGS_TRANSPARENCY) != 0) //{ // outColor[0].rgb *= outColor[0].a; // //outColor[0].a = 1.0f; //} } Hyperdrive shader based on Drop Tunnel by Del 2 Quote
SpiderPig Posted March 4, 2024 Posted March 4, 2024 Nice! Shader toy has some good shaders. 🙂 1 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.