ios - Use parent coordinates in SKShader -


i'm playing around skshader ios.

void main() {   vec4 val = texture2d(u_texture, v_tex_coord);   float len = 0.5 + 0.5 * sin(10.0 * u_time + 0.05 * (gl_fragcoord.x + gl_fragcoord.y));   vec4 c = vec4(vec3(len), 1);   gl_fragcolor = c * val; } 

i want assign shader sprites connected, , want effect smooth between sprites. hence don't think can use v_tex_coord in shader. use gl_fragcoord instead.

the problem sprites children of sknode can moved. , gl_fragcoord in screen coordinates movement affect animation.

q: there way avoid sprite shaders affected movement of parent node without passing uniform data, containing position , zrotation of sprite, shader?

yes, rather changing uniform (which recompile shader), pass size skattribute , update attribute in skscenedelegate update method.

for example:

let attributebasedshader = skshader(filenamed: "usingattributes.fsh") attributebasedshader.attributes = [     skattribute(name: "a_sprite_position", type: .vectorfloat2)]  let sprite = skspritenode() sprite.shader = attributebasedshader   let spriteposition = vector_float2(float(sprite.position.x),                                     float(sprite.position.y)) sprite.setvalue(skattributevalue(vectorfloat2: spriteposition),                  forattribute: "a_sprite_position") 

Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -