Tuesday, November 5, 2024
spot_img

Cocos creator (2.4.13) Impact Materials shouldn’t be centered on the Sprite Node – Cocos Creator


Hello, I’m at present going through the difficulty the place my impact shouldn’t be centered on the node when its node materials is utilized.

Prime aspect is the picture of the proper place of my shockwave when my node place is at (0,0).

Backside aspect is the picture when my node place is modified. (400,0). Nevertheless the impact place shouldn’t be modified in any respect.

The aim is to make my impact capable of observe the place of my node.

These are the code for the impact file for reference.

// Impact (Fragment Shader)
CCProgram fs %{
  precision highp float;

  #embody 
  #embody 
  #embody 

  in vec4 v_color;

  #if USE_TEXTURE
  in vec2 v_uv0;
  uniform sampler2D texture;
  #endif

  uniform Fixed{
    vec2 iResolution;
  };



  void major () {

    vec2 p = -.5 + ((gl_FragCoord.xy)/ iResolution.xy);
    p.x *= iResolution.x / iResolution.y;
    
    float dist = size(p);
   
    float radius = ((cc_time.x) ) * 0.3;
 
    float depth = smoothstep(radius, radius + 0.15, dist);

    gl_FragColor = vec4(1.,1.,1.,depth);
  }
}%

// In typescript
this._sprite.getMaterial(0).setProperty("iResolution", cc.v2(cc.view.getCanvasSize().width, cc.view.getCanvasSize().peak));

I’m thought of myself as a newbie of GLSL shader coding and could be appreciated if anybody would clarify to me and present me repair this.

Thanks upfront.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisement -spot_img

Latest Articles