Sha256: 0985d642c3a6a38908b7b888f41e9ff2a2dde568adb01a435ca4cab06f62015e

Contents?: true

Size: 1.74 KB

Versions: 9

Compression:

Stored size: 1.74 KB

Contents

void main(inout vec4 ambient, inout vec4 diffuse, inout vec4 specular) {
  vec4 _ambient = vec4(0), _diffuse = vec4(0), _specular = vec4(0);
  
  vec3 nNormal = normalize(vNormal);

  if (LIGHTING_ENABLED) {
    if (LIGHT_TYPE == <%=Jax.DIRECTIONAL_LIGHT%>)
      DirectionalLight(nNormal, _ambient, _diffuse, _specular);
    else
      if (LIGHT_TYPE == <%=Jax.POINT_LIGHT%>)
        if (LIGHT_ATTENUATION_CONSTANT == 1.0 && LIGHT_ATTENUATION_LINEAR == 0.0 && LIGHT_ATTENUATION_QUADRATIC == 0.0)
          PointLightWithoutAttenuation(vSurfacePos, nNormal, _ambient, _diffuse, _specular);
        else
          PointLightWithAttenuation(vSurfacePos, nNormal, _ambient, _diffuse, _specular);
      else
        if (LIGHT_TYPE == <%=Jax.SPOT_LIGHT%>)
          SpotLight(vSurfacePos, nNormal, _ambient, _diffuse, _specular);
        else
        { // error condition, output 100% red
          gl_FragColor = vec4(1,0,0,1);
          return;
        }
  } else {
    _ambient = vec4(1,1,1,1);
    _diffuse = _specular = vec4(0,0,0,0);
  }

  /*
    Light colors will be multiplied by material colors. Light can't really be transparent,
    so we'll use alpha to represent intensity. This means we must multiply resultant light
    colors by light alpha, and then hard-code alpha 1 to avoid polluting transparency.
    
    The reason we use LIGHT_*.a instead of _*.a is because _*.a has been tainted by attenuation.
    A light's intensity, regardless of distance or relative brightness, has not actually changed;
    attenuation has been factored into color already; we don't want to square the atten amt.
  */
  ambient *= vec4(_ambient.rgb * LIGHT_AMBIENT.a, 1.0);
  diffuse *= vec4(_diffuse.rgb * LIGHT_DIFFUSE.a, 1.0);
  specular *= vec4(_specular.rgb * LIGHT_SPECULAR.a, 1.0);
}

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
jax-1.0.1.rc1 builtin/shaders/lighting/fragment.ejs
jax-1.0.0 builtin/shaders/lighting/fragment.ejs
jax-0.0.0.10 builtin/shaders/lighting/fragment.ejs
jax-0.0.0.9 builtin/shaders/lighting/fragment.ejs
jax-0.0.0.8 builtin/shaders/lighting/fragment.ejs
jax-0.0.0.7 builtin/shaders/lighting/fragment.ejs
jax-0.0.0.6 builtin/shaders/lighting/fragment.ejs
jax-0.0.0.5 builtin/shaders/lighting/fragment.ejs
jax-0.0.0.4 builtin/shaders/lighting/fragment.ejs