程序问答   发布时间:2022-06-01  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Pixi.js - 移动对象(文本、图形)但着色器不跟随内部(像面具一样)大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决Pixi.js - 移动对象(文本、图形)但着色器不跟随内部(像面具一样)?

开发过程中遇到Pixi.js - 移动对象(文本、图形)但着色器不跟随内部(像面具一样)的问题如何解决?下面主要结合日常开发的经验,给出你关于Pixi.js - 移动对象(文本、图形)但着色器不跟随内部(像面具一样)的解决方法建议,希望对你解决Pixi.js - 移动对象(文本、图形)但着色器不跟随内部(像面具一样)有所启发或帮助;

所以我试图在文本中渲染着色器动画,所以我创建了一个 Pixi.Text 并使用我的着色器代码添加了 Pixi.Filter。一切都很好,但是当我移动 Pixi.Text 或 PIXI.Graphics 的位置时,我可以看到着色器动画没有跟随,所以就像我的文本或图形在着色器动画上充当遮罩一样。我觉得这是因为我如何在我的片段着色器中应用我的纹理,但我找不到任何解决方案。

您可以在片段中看到纹理/着色器动画的表现。我希望我的着色器在文本中保持静态。

期待获得一些提示、建议或可能遵循的方向:)

var fragmentShader = document.getElementByID("fragmentShader").textContent


const mauve = 0xDBC4FB
const purple = 0x651B4E


let app = new PIXI.Application({wIDth: 256,height: 256,antialias: true,BACkgroundAlpha: 0,resolution: 1});
app.vIEw.classList.add("canvas__ulk")
document.body.appendChild(app.vIEw);
app.renderer.autoResize = true;
    app.renderer.resize(window.innerWIDth,window.innerHeight);


/** App */


    document.Fonts.load("10px Roboto").then(Font => {


        // TEXT
        let message = new PIXI.Text("123",new PIXI.TextStyle({
            FontFamily: "Roboto",FontSize: 350,fill: "white",}))
        app.stage.addChild(messagE)
                
            
        const uniforms = {
            uTime: 0.0,ucolor: [0.396,0.105,0.305],}
        let myShader = new PIXI.Filter(null,fragmentShader,uniforms)
        message.filters = [myShader]

        let time = 0

        app.ticker.add(delta => {
    
            time += delta
    
            // update myShader
            uniformS.UTime++
            
            message.y = -window.scrollY
    
        })

    })
h1,h2,h3,h4,p,ul,body,HTML {
  padding: 0;
  margin: 0;
}

header ul {
  display: flex;
  justify-content: center;
  padding: 15px 0;
}
header ul li {
  List-style-type: none;
  margin-right: 25px;
}
header ul li a {
  text-decoration: none;
  Font-size: 25px;
}

main .logo {
  border: 1px solID red;
  height: 644px;
  text-align: center;
}
main .logo h1 {
  Font-family: Roboto;
  Font-size: 350px;
  border: 1px solID blue;
}
main .logo h3 {
  Font-size: 40px;
  border: 1px solID blue;
}
main .scroll {
  text-align: center;
  margin-top: 55px;
  display: block;
  text-decoration: none;
  color: black;
  Font-weight: bold;
  Font-family: Arial,Helvetica,sans-serif;
}
main article {
  padding: 55px 65px;
}
main article h2 {
  Font-size: 105px;
}
main article p {
  max-wIDth: 650px;
  margin: 20px 0;
  margin-top: 45px;
  Font-size: 22px;
}

.canvas__ulk {
  border: 2px solID green;
  display: block;
  position: fixed;
  top: 0;
  pointer-events: none;
}
<script src="https://cdnjs.cloudFlare.com/AJAX/libs/pixi.Js/6.0.0/browser/pixi.min.Js"></script>
<HTML lang="en">
<head>
    <Meta charset="UTF-8">
    <Meta http-equiv="X-UA-Compatible" content="IE=edge">
    <Meta name="vIEwport" content="wIDth=device-wIDth,initial-scale=1.0">
    <link rel="preconnect" href="https://Fonts.gstatic.com">
    <link href="https://Fonts.GoogleAPIs.com/CSS2?family=Roboto:wght@700&display=swap" rel="stylesheet">
    <title>ulK / TEST PIXI</title>
</head>
<body>

    <header>

        <ul>
            <li><a href="/">link 1</a></li>
            <li><a href="/">link 2</a></li>
            <li><a href="/">link 3</a></li>
            <li><a href="/">link 4</a></li>
        </ul>

    </header>


    <main>

        <div class="logo">

            <h1 ID="Js__ulk-title">123</h1>

        </div>
        <a href="#" class="scroll">SCRolL</a>

        <article>

            <h2>MY title</h2>
            <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Modi laborum molestias nisi architecto enim corporis debitis Dicta,impedit iusto quae nemo vero! Debitis iste possimus atque ducimus! Suscipit pariatur dignissimos exercitationem assumenda qui? Minima facere maiores tempora,fugit nobis error ea,obcaecati quod ex labore dolorem vel,quos quas expedita aut eligendi quo fuga consequuntur.</p>

        </article>


    </main>
    
    <script type="x-fragment" ID="fragmentShader">
  
precision highp float;

//
// Description : Array and textureless GLSL 2D/3D/4D simplex 
//               noise functions.
//      Author : Ian McEwan,Ashima Arts.
//  Maintainer : ijm
//     Lastmod : 20110813 (stegu)
//     license : copyright (C) 2011 Ashima Arts. All rights reserved.
//               diStributed under the MIT license. See liCENSE file.
// 

vec3 mod289(vec3 X) {
return x - floor(x * (1.0 / 289.0)) * 289.0;
}

vec4 mod289(vec4 X) {
return x - floor(x * (1.0 / 289.0)) * 289.0;
}

vec4 permute(vec4 X) {
    return mod289(((x*34.0)+1.0)*X);
}

vec4 taylorInvSqrt(vec4 r)
{
return 1.79284291400159 - 0.85373472095314 * r;
}

float snoise(vec3 v)
{ 
const vec2  C = vec2(1.0/6.0,1.0/3.0) ;
const vec4  D = vec4(0.0,0.5,1.0,2.0);

// First corner
vec3 i  = floor(v + dot(v,C.yyy) );
vec3 x0 =   v - i + dot(i,C.xxX) ;

// Other corners
vec3 g = step(x0.yzx,x0.xyz);
vec3 l = 1.0 - g;
vec3 i1 = min( g.xyz,l.zxy );
vec3 i2 = max( g.xyz,l.zxy );

//   x0 = x0 - 0.0 + 0.0 * C.xxx;
//   x1 = x0 - i1  + 1.0 * C.xxx;
//   x2 = x0 - i2  + 2.0 * C.xxx;
//   x3 = x0 - 1.0 + 3.0 * C.xxx;
vec3 x1 = x0 - i1 + C.xxx;
vec3 x2 = x0 - i2 + C.yyy; // 2.0*C.x = 1/3 = C.y
vec3 x3 = x0 - D.yyy;      // -1.0+3.0*C.x = -0.5 = -D.y

// Permutations
i = mod289(i); 
vec4 p = permute( permute( permute( 
            i.z + vec4(0.0,i1.z,i2.z,1.0 ))
        + i.y + vec4(0.0,i1.y,i2.y,1.0 )) 
        + i.x + vec4(0.0,i1.x,i2.x,1.0 ));

// GradIEnts: 7x7 points over a square,mapped onto an octahedron.
// The ring size 17*17 = 289 is close to a multiple of 49 (49*6 = 294)
float n_ = 0.142857142857; // 1.0/7.0
vec3  ns = n_ * D.wyz - D.xzx;

vec4 j = p - 49.0 * floor(p * ns.z * ns.z);  //  mod(p,7*7)

vec4 x_ = floor(j * ns.z);
vec4 y_ = floor(j - 7.0 * x_ );    // mod(j,N)

vec4 x = x_ *ns.x + ns.yyyy;
vec4 y = y_ *ns.x + ns.yyyy;
vec4 h = 1.0 - abs(X) - abs(y);

vec4 b0 = vec4( x.xy,y.xy );
vec4 b1 = vec4( x.zw,y.zw );

//vec4 s0 = vec4(lessthan(b0,0.0))*2.0 - 1.0;
//vec4 s1 = vec4(lessthan(b1,0.0))*2.0 - 1.0;
vec4 s0 = floor(b0)*2.0 + 1.0;
vec4 s1 = floor(b1)*2.0 + 1.0;
vec4 sh = -step(h,vec4(0.0));

vec4 a0 = b0.xzyw + s0.xzyw*sh.xxyy ;
vec4 a1 = b1.xzyw + s1.xzyw*sh.zzww ;

vec3 p0 = vec3(a0.xy,h.X);
vec3 p1 = vec3(a0.zw,h.y);
vec3 p2 = vec3(a1.xy,h.z);
vec3 p3 = vec3(a1.zw,h.w);

//normalise gradIEnts
vec4 norm = taylorInvSqrt(vec4(dot(p0,p0),dot(p1,p1),dot(p2,p2),dot(p3,p3)));
p0 *= norm.x;
p1 *= norm.y;
p2 *= norm.z;
p3 *= norm.w;

// Mix final noise value
vec4 m = max(0.6 - vec4(dot(x0,x0),dot(x1,x1),dot(x2,x2),dot(x3,x3)),0.0);
m = m * m;
return 42.0 * dot( m*m,vec4( dot(p0,x3) ) );
} 

#pragma glslify: export(snoisE)


precision mediump float;

varying vec2 vTextureCoord;

uniform sampler2D uSampler;
uniform float uTime;
uniform vec3 ucolor;


float rf = 405.4;
float gf = 1022.0;
float bf = 720.2;

vec3 red = vec3(0.901,0.074,0.235);
vec3 mauve = vec3(0.854,0.772,1);
vec3 orange = vec3(0.929,0.443,0.231);


float clampbetween(float x,float pmin,float pmax,float cmin,float cmaX){
    return ((x - pmin) / (pmax - pmin)) * (cmax - cmin) + cmin;
}


vec4 getplasma1(float noiseValue,float colorNoisE){

    vec4 noisePerturbationcolor = vec4(noiseValue,noiseValue,1.);


    vec3 targetcolor = mix(
        mauve,red,colorNoise
    );

    
    float clampedValue = clamp(noiseValue,0.,1.);

    // black go ucolor & others go targetcolor
    noisePerturbationcolor.rgb = mix(
        ucolor,mauve,clampedValue
    ); 


    float threshold = .7;

    if(noiseValue >= threshold){

        noisePerturbationcolor.rgb = mix(
            noisePerturbationcolor.rgb,orange,clampbetween(clampedValue,threshold,1.,.0,1.)
        ); 

    }


    threshold = .86;

    if(noiseValue >= threshold){

        noisePerturbationcolor.rgb = mix(
            noisePerturbationcolor.rgb,1.)
        ); 

    }

    return noisePerturbationcolor;

}

vec4 getplasma2(float noiseValue,float noise2value){

    vec4 noisePerturbationcolor = vec4(noiseValue,1.);

    /** APPLY MAUVE **/

    float threshold = 0.;
    float maxlissage = .05;

    // lissage
    noisePerturbationcolor.rgb = mix(
        ucolor,clamp(clampbetween(
            noiseValue,maxlissage,1.
        ),1.)
    );


    /** APPLY ORANGE **/
    threshold = .34;
    maxlissage = .84;

    // lissage
    noisePerturbationcolor.rgb = mix(
        noisePerturbationcolor.rgb,1.)
    );

    /** APPLY RED **/
    threshold = .87;
    maxlissage = 1.;

    // lissage
    noisePerturbationcolor.rgb = mix(
        noisePerturbationcolor.rgb,1.)
    );


    return noisePerturbationcolor;
}

voID main()
{


    // noise
        float t = uTime * .005;
        vec2 uv = 1.0*vTextureCoord;

        float noisePrecision = 2.4;

        float value = snoise(vec3(uv.x * noisePrecision,uv.y * noisePrecision,t/2.0));

        float colorNoise = snoise(vec3(uv.x * noisePrecision,-3. + t/2.0));
        float orangeNoise = snoise(vec3(uv.x * 2.,uv.y * 2.,t/2.0));

        float r = (sin(radians(value*rf+100.0*t)) +1.0)/2.0;
        float g = (sin(radians(value*gf+100.0*t)) +1.0)/2.0;
        float b = (sin(radians(value*bf+100.0*t)) +1.0)/2.0;
        

        // vec4 noisePerturbationcolor = vec4(pow(r,10.0)+r,1.0-b,1);
        // vec4 noisePerturbationcolor = vec4(r,r+g/b,r,1);
        // vec4 noisePerturbationcolor = vec4(value,value,1.);
        // vec4 noisePerturbationcolor = getplasma1(value,colorNoisE);
        vec4 noisePerturbationcolor = getplasma2(value,orangeNoisE);

    // noise

    // get from uSampler
    vec4 texturecolor = texture2D(uSampler,vTextureCoord);

    
    gl_Fragcolor = noisePerturbationcolor * texturecolor;
}
    
    </script>

    <script src="./src/index.Js"></script>
</body>
</HTML>

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

@H_696_34@

大佬总结

以上是大佬教程为你收集整理的Pixi.js - 移动对象(文本、图形)但着色器不跟随内部(像面具一样)全部内容,希望文章能够帮你解决Pixi.js - 移动对象(文本、图形)但着色器不跟随内部(像面具一样)所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签:-