Plasma shader with glossness

Hi!
I doing some kind of plasma shader, but I want to keep material more glossness.
image
I use this material with this parameters:


But sphere looks like this:
image
Shader:

uniform float iGlobalTime;

vec3 getEmission() {
vec2 p = -1.0 + 2.0 * vUv0;

    // main code, *original shader by: 'Plasma' by Viktor Korsun (2011)
    float x = p.x;
    float y = p.y;
    float mov0 = x+y+cos(sin(iGlobalTime)*2.0)*100.+sin(x/100.)*1000.;
    float mov1 = y / 0.9 +  iGlobalTime;
    float mov2 = x / 0.2;
    float c1 = abs(sin(mov1+iGlobalTime)/2.+mov2/1.5-mov1-mov2+iGlobalTime);
    float c1Range = (c1 - 0.)/(1.-0.)*(1.-0.75)+0.75;
    float c2 = abs(sin(c1+sin(mov0/1000.+iGlobalTime)+sin(y/40.+iGlobalTime)+sin((x+y)/100.)*3.));
    float c2Range = (c2 - 0.)/(1.-0.)*(0.4-0.1)+0.1;
    float c3 = abs(sin(c2+cos(mov1+mov2+c2)+cos(mov2)+sin(x/1000.)));
    float c3Range = (c3 - 0.)/(1.-0.)*(0.05-0.)+0.05;
    return vec3(c1Range, c2Range,c3Range);
}

Hi @pekarnik,

Nice! Have you tried playing with the Specular (metallic) and Environment maps of the material?

Try doing that and most likely you will both glossiness and reflectivity. Unless the emissive color calculated from the shader is too bright and overrides the resulting color value. In that case maybe try moving your shader to another material channel (maybe diffuse/albedo).

Hi @Leonidas!
I can’t find api of chunks( conole.log of it show me only emissivePs… Do you know where I can see a full list?

Good point, this is still an undocumented feature of the engine, so you will have to find your way around the engine source code.

Here is a full list of all shader chunks available to a material:

If the extension ends with .frag then you should be adding the suffix PS (for pixel shader) to the chunk name when overriding it.

If the extension ends with .vert you add VS (for vertex shader).

Here are some example overrides:

// diffuse/emissive/opacity channels
material.chunks.diffusePS = '[shader code]';
material.chunks.emissivePS = '[shader code]';
material.chunks.opacityPS = '[shader code]';

// the base vertex shader, useful when doing vertex displacement in shader e.g. for grass animation
material.chunks.transformVS= '[shader code]';

Now, you don’t really know which chunks are used for each material unless you step in the debugger and see live how each shader program is generated.

Though guessing is usually enough:

  • If you have assigned a diffuse texture to your material or changed the default diffuse color then the diffusePS chunk is used and you can override it.
  • If you are using opacity on a material, then opacityPS is used/can be overridden.
    etc

If you override a shader chunk and nothing visually happens (or no error thrown, try making a deliberate error in your shader code) then most likely this shader chunk isn’t used by this material.

It’s a system with a steep learning curve, but helps you understand the internals of the Playcanvas rendering pipeline and eventually you come to appreciate its power.

ERROR: 0:150: ‘getEmission’ : function already has a body
ERROR: 0:479: ‘getAlbedo’ : no matching overloaded function found

Hm, I need to change my shader too as i see.

void main(void) {
470: dDiffuseLight = vec3(0);
471: dSpecularLight = vec3(0);
472: dReflection = vec4(0);
473: dSpecularity = vec3(0);
474: dVertexNormalW = vNormalW;
475: dAlpha = 1.0;
476: getViewDir();
477: getNormal();
478: getReflDir();
479: getAlbedo();
480: getSpecularity();
481: getGlossiness();
482: addAmbient();
483: addReflection();
484: dLightDirNormW = light0_direction;
485: dAtten = 1.0;
486: dAtten *= getLightDiffuse();
487: dAtten *= getShadowPCF3x3VS(light0_shadowMap, light0_shadowParams);
488: dDiffuseLight += dAtten * light0_color;
489: dAtten *= getLightSpecular();
490: dSpecularLight += dAtten * light0_color;
491:
492: addRefraction();

this is a functions that mean that I need to use other function for diffuse.
I will look at it, thank you

1 Like