cables_dev/cables/src/core/cgl/cgl_shader_lib.js
- import { Uniform } from "./cgl_shader_uniform.js";
- import { Texture } from "./cgl_texture.js";
- import { TextureEffect } from "./cgl_textureeffect.js";
-
- const ShaderLibMods = {
- "CGL.BLENDMODES": function ()
- {
- this.name = "blendmodes";
- this.srcHeadFrag = TextureEffect.getBlendCode();
- },
- "CGL.BLENDMODES3": function ()
- {
- this.name = "blendmodes3";
- this.srcHeadFrag = TextureEffect.getBlendCode(3);
- },
-
- "CGL.LUMINANCE": function ()
- {
- this.name = "luminance";
- this.srcHeadFrag = "".endl()
- + "float cgl_luminance(vec3 c)".endl()
- + "{".endl()
- + " return dot(vec3(0.2126,0.7152,0.0722),c);".endl()
- + "}".endl();
- },
-
-
- // quite good random numbers, but somehow don't work in ANGLE
- "CGL.RANDOM_OLD": function ()
- {
- this.name = "randomNumber";
- this.srcHeadFrag = "".endl()
- + "float cgl_random(vec2 co)".endl()
- + "{".endl()
- + " return fract(sin(dot(co.xy ,vec2(12.9898,4.1414))) * 432758.5453);".endl()
- + "}".endl()
- + "vec3 cgl_random3(vec2 co)".endl()
- + "{".endl()
- + " return vec3( cgl_random(co),cgl_random(co+0.5711),cgl_random(co+1.5711));".endl()
- + "}";
- },
-
-
- // low quality generative ranodm numbers
- "CGL.RANDOM_LOW": function ()
- {
- this.name = "randomNumber";
- this.srcHeadFrag = "".endl()
- + "float cgl_random(vec2 co)".endl()
- + "{".endl()
- + " return fract(sin(dot(co.xy ,vec2(12.9898,4.1414))) * 358.5453);".endl()
- + "}".endl()
- + "vec3 cgl_random3(vec2 co)".endl()
- + "{".endl()
- + " return vec3( cgl_random(co),cgl_random(co+0.5711),cgl_random(co+1.5711));".endl()
- + "}";
- },
-
- // texture based random numbers
- "CGL.RANDOM_TEX": function ()
- {
- this.name = "randomNumbertex";
- this.srcHeadFrag = "".endl()
- + "UNI sampler2D CGLRNDTEX;".endl()
- + "float cgl_random(vec2 co)".endl()
- + "{".endl()
- + " return texture(CGLRNDTEX,co*5711.0).r;".endl()
- + "}".endl()
- + "vec3 cgl_random3(vec2 co)".endl()
- + "{".endl()
- + " return texture(CGLRNDTEX,co*5711.0).rgb;".endl()
- + "}";
-
- this.initUniforms = function (shader)
- {
- return [new Uniform(shader, "t", "CGLRNDTEX", 7)];
- };
-
- this.onBind = function (cgl, shader)
- {
- Texture.getRandomTexture(cgl);
- cgl.setTexture(7, Texture.getRandomTexture(cgl).tex);
- };
- },
- };
-
- export { ShaderLibMods };