ok it is quite large and a mod of an earlier version of lightblow, though I only worked with the frag shader(added a second custom Ramp operation)
I can bundle the the entire test if need be, I will have to try and make it jmp ready though
see RIMLIGHTING for the problem area
frag
[java]#import “Common/ShaderLib/Parallax.glsllib”
#import “Common/ShaderLib/Optics.glsllib”
#define ATTENUATION
//#define HQ_ATTENUATION
varying vec2 texCoord;
#ifdef SEPERATE_TEXCOORD
varying vec2 texCoord2;
#endif
varying vec3 AmbientSum;
varying vec4 DiffuseSum;
varying vec3 SpecularSum;
#ifdef HAS_LIGHTMAP
uniform float m_LightMapIntensity;
uniform sampler2D m_LightMap;
#endif
#ifndef VERTEX_LIGHTING
uniform vec4 g_LightDirection;
varying vec3 vPosition;
varying vec3 vViewDir;
varying vec4 vLightDir;
varying vec3 mat;
varying vec3 lightVec;
#else
varying vec2 vertexLightValues;
#endif
#ifdef DIFFUSEMAP
uniform sampler2D m_DiffuseMap;
#endif
#ifdef SPECULARMAP
uniform sampler2D m_SpecularMap;
#endif
#ifdef PARALLAXMAP
uniform sampler2D m_ParallaxMap;
#endif
#ifdef NORMALMAP
uniform sampler2D m_NormalMap;
#else
varying vec3 vNormal;
#endif
#ifdef ALPHAMAP
uniform sampler2D m_AlphaMap;
#endif
#ifdef COLORRAMP
uniform sampler2D m_ColorRamp;
#endif
#ifdef COLORRAMP2
uniform sampler2D m_ColorRamp2;
#endif
uniform float m_AlphaDiscardThreshold;
#ifndef VERTEX_LIGHTING
#ifdef SPECULAR_LIGHTING
uniform float m_Shininess;
uniform float m_SpecIntensity;
#endif
#ifdef HQ_ATTENUATION
uniform vec4 g_LightPosition;
#endif
#if defined RIM_LIGHTING || RIM_LIGHTING_2
uniform vec4 m_RimLighting;
uniform vec4 m_RimLighting2;
// uniform vec4 g_AmbientLightColor;
#endif
#ifdef IBL
varying vec3 iblVec;
uniform ENVMAP m_IblMap;
uniform float m_iblIntensity;
#endif
#ifdef REFLECTION
uniform float m_RefPower;
uniform float m_RefIntensity;
varying vec3 refVec;
uniform ENVMAP m_RefMap;
varying float refTex;
#endif
#ifdef MINNAERT
uniform vec4 m_Minnaert;
#endif
float tangDot(in vec3 v1, in vec3 v2){
float d = dot(v1,v2);
#ifdef V_TANGENT
d = 1.0 - dd;
return step(0.0, d) * sqrt(d);
#else
return d;
#endif
}
float lightComputeDiffuse(in vec3 norm, in vec3 lightdir, in vec3 viewdir){
#if defined(HEMI_LIGHTING_1)
return (0.5 + 0.5 * dot(norm, lightdir)) * (0.5 + 0.5 * dot(norm, lightdir));
#elif !defined(HEMI_LIGHTING_1) && defined(HEMI_LIGHTING_2)
return 0.4 + 0.5 * dot(norm, lightdir);
#else
return max(0.0, dot(norm, lightdir));
#endif
}
#if defined(SPECULAR_LIGHTING) && !defined(VERTEX_LIGHTING)
float lightComputeSpecular(in vec3 norm, in vec3 viewdir, in vec3 lightdir, in float shiny){
// NOTE: check for shiny <= 1 removed since shininess is now
// 1.0 by default (uses matdefs default vals)
#ifdef LOW_QUALITY
// Blinn-Phong
// Note: preferably, H should be computed in the vertex shader
vec3 H = (viewdir + lightdir) * vec3(0.5);
return pow(max(tangDot(H, norm), 0.0), shiny);
#elif defined(WARDISO)
// Isotropic Ward
vec3 halfVec = normalize(viewdir + lightdir);
float NdotH = max(0.001, tangDot(norm, halfVec));
float NdotV = max(0.001, tangDot(norm, viewdir));
float NdotL = max(0.001, tangDot(norm, lightdir));
float a = tan(acos(NdotH));
float p = max(shiny/128.0, 0.001);
return NdotL * (1.0 / (4.03.14159265pp)) * (exp(-(aa)/(pp)) / (sqrt(NdotV * NdotL)));
#else
// Standard Phong
vec3 R = reflect(-lightdir, norm);
return pow(max(tangDot(R, viewdir), 0.0), shiny);
#endif
}
#endif
vec2 computeLighting(in vec3 wvPos, in vec3 wvNorm, in vec3 wvViewDir, in vec3 wvLightDir){
float diffuseFactor = lightComputeDiffuse(wvNorm, wvLightDir, wvViewDir);
float specularFactor;
#ifdef SPECULAR_LIGHTING
specularFactor = lightComputeSpecular(wvNorm, wvViewDir, wvLightDir, m_Shininess);
specularFactor = (specularFactor * step(1.0, m_Shininess)) * m_SpecIntensity;
#else
specularFactor = 0.0;
#endif
#ifdef HQ_ATTENUATION
float att = clamp(1.0 - g_LightPosition.w * length(lightVec), 0.0, 1.0);
#elif NO_ATTENUATION
float att = 1.0;
#else
float att = vLightDir.w;
#endif
return vec2(diffuseFactor, specularFactor) * vec2(att);
}
#endif
void main(){
vec2 newTexCoord;
#if defined(PARALLAXMAP) || defined(PARALLAX_A_NOR) && !defined(VERTEX_LIGHTING)
float h;
#if defined (PARALLAXMAP)
h = texture2D(m_ParallaxMap, texCoord).r;
#elif defined (PARALLAX_A_NOR) && defined (NORMALMAP)
h = texture2D(m_NormalMap, texCoord).a;
#endif
float heightScale = 0.05;
float heightBias = heightScale * -0.5;
vec3 normView = normalize(vViewDir);
h = (h * heightScale + heightBias) * normView.z;
newTexCoord = texCoord + (h * normView.xy);
#else
newTexCoord = texCoord;
#endif
#ifdef DIFFUSEMAP
vec4 diffuseColor = texture2D(m_DiffuseMap, newTexCoord);
#else
vec4 diffuseColor = vec4(0.6, 0.6, 0.6, 1.0);
#endif
#if defined(NORMALMAP) && !defined(VERTEX_LIGHTING)
vec4 normalHeight = texture2D(m_NormalMap, newTexCoord);
vec3 normal = (normalHeight.xyz * vec3(2.0) - vec3(1.0));
// normal = normalize(normal);
#ifdef LATC
normal.z = sqrt(1.0 - (normal.x * normal.x) - (normal.y * normal.y));
#endif
#if defined (NOR_INV_X) && (NORMALMAP)
normal.x = -normal.x;
#endif
#if defined (NOR_INV_Y) && (NORMALMAP)
normal.y = -normal.y;
#endif
#if defined (NOR_INV_Z) && (NORMALMAP)
normal.z = -normal.z;
#endif
#elif !defined(VERTEX_LIGHTING)
vec3 normal = vNormal;
#if !defined(LOW_QUALITY) && !defined(V_TANGENT)
normal = normalize(normal);
#endif
#endif
#ifdef SPECULARMAP
vec4 specularColor = texture2D(m_SpecularMap, newTexCoord);
#else
vec4 specularColor = vec4(1.0);
#endif
#if defined(SPECULAR_LIGHTING) && defined(SPEC_A_NOR) && defined(NORMALMAP) && !defined(SPECULARMAP)
float specA = texture2D(m_NormalMap, newTexCoord).a;
specularColor = vec4(specA);
#elif defined(SPECULAR_LIGHTING) && defined(SPEC_A_DIF) && !defined(SPEC_A_NOR) && defined(DIFFUSEMAP) && !defined(SPECULARMAP)
float specA = texture2D(m_DiffuseMap, newTexCoord).a;
specularColor = vec4(specA);
#endif
float alpha = DiffuseSum.a;
#if defined (ALPHA_A_DIF) && defined (DIFFUSEMAP)
alpha = diffuseColor.a;
#elif defined (ALPHA_A_NOR) && defined (NORMALMAP)
alpha = normalHeight.a;
#endif
if(alpha < m_AlphaDiscardThreshold){
discard;
}
#ifndef VERTEX_LIGHTING
float spotFallOff = 1.0;
#if VERSION >= 110
// allow use of control flow
if(g_LightDirection.w != 0.0){
#endif
vec3 L = normalize(lightVec.xyz);
vec3 spotdir = normalize(g_LightDirection.xyz);
float curAngleCos = dot(-L, spotdir);
float innerAngleCos = floor(g_LightDirection.w) * 0.001;
float outerAngleCos = fract(g_LightDirection.w);
float innerMinusOuter = innerAngleCos - outerAngleCos;
spotFallOff = (curAngleCos - outerAngleCos) / innerMinusOuter;
#if VERSION >= 110
if(spotFallOff <= 0.0){
gl_FragColor.rgb = AmbientSum * diffuseColor.rgb;
gl_FragColor.a = alpha;
return;
}else{
spotFallOff = clamp(spotFallOff, 0.0, 1.0);
}
}
#else
spotFallOff = clamp(spotFallOff, step(g_LightDirection.w, 0.001), 1.0);
#endif
#endif
#ifdef VERTEX_LIGHTING
vec2 light = vertexLightValues.xy;
#ifdef COLORRAMP
light.x = texture2D(m_ColorRamp, vec2(light.x, 0.0)).r;
light.y = texture2D(m_ColorRamp, vec2(light.y, 0.0)).r;
#endif
#ifdef COLORRAMP2
light.x = texture2D(m_ColorRamp2, vec2(light.x, 0.0)).r;
light.y = texture2D(m_ColorRamp2, vec2(light.y, 0.0)).r;
#endif
#if defined(SPECULAR_LIGHTING) && defined(VERTEX_LIGHTING)
gl_FragColor.rgb = AmbientSum * diffuseColor.rgb +
DiffuseSum.rgb * diffuseColor.rgb * vec3(light.x) +
SpecularSum.rgb * specularColor.rgb * vec3(light.y);
#endif
#if !defined(SPECULAR_LIGHTING) && defined(VERTEX_LIGHTING)
gl_FragColor.rgb = AmbientSum * diffuseColor.rgb +
DiffuseSum.rgb * diffuseColor.rgb * vec3(light.x);
#endif
#else
vec4 lightDir = vLightDir;
lightDir.xyz = normalize(lightDir.xyz);
vec3 viewDir = normalize(vViewDir.xyz);
//Custom opertions
vec2 light = computeLighting(vPosition, normal, viewDir.xyz, lightDir.xyz) * spotFallOff;
vec3 normalizedLight_ViewDirection = normalize(viewDir.xyz+lightDir.xyz);
float NDotL2 = max(0.0, dot(normal, normalizedLight_ViewDirection));
#ifdef COLORRAMP
light.x = texture2D(m_ColorRamp, vec2(light.x+NDotL2, 0.0)).r;
light.y = texture2D(m_ColorRamp, vec2(light.y+NDotL2, 0.0)).r;
#endif
#ifdef COLORRAMP2
light.x += texture2D(m_ColorRamp2, vec2(light.x*+NDotL2, 0.0)).r;
light.y += texture2D(m_ColorRamp2, vec2(light.y*+NDotL2, 0.0)).r;
#endif
//end of custom operation
// Workaround, since it is not possible to modify varying variables
vec4 SpecularSum2 = vec4(SpecularSum, 1.0);
#ifdef IBL
// IBL - Image Based Lighting. The lighting based on either cube map or sphere map.
#if defined (IBL) && defined (NORMALMAP)
vec3 iblLight = Optics_GetEnvColor(m_IblMap, (iblVec - mat * normal)).rgb;
#elif defined (IBL) && !defined (NORMALMAP)
vec3 iblLight = Optics_GetEnvColor(m_IblMap, iblVec).rgb;
#endif
//Albedo
AmbientSum.rgb += iblLight * m_iblIntensity;
#endif
#if defined(EMISSIVEMAP) && defined(DIFFUSEMAP)
//Illumination based on diffuse map alpha chanel.
float emissiveTex = diffuseColor.a;
// AmbientSum.rgb = AmbientSum.rgb + 2.0 * emissiveTex;
// AmbientSum.rgb = max(AmbientSum.rgb, emissiveTex);
light.x = light.x + emissiveTex;
// light.x = max(light.x, emissiveTex);
//diffuseColor.rgb = max(diffuseColor, emissiveTex);
#endif
#if defined (REFLECTION)
// Reflection based on either cube map or sphere map.
#if defined (REFLECTION) && defined (NORMALMAP)
// vec4 refGet = Optics_GetEnvColor(m_RefMap, (refVec.xyz - mat.xyz * normal.xyz)-1.5);
vec3 refGet = Optics_GetEnvColor(m_RefMap, (refVec - mat * normal)).rgb;
#elif defined (REFLECTION) && !defined (NORMALMAP)
vec3 refGet = Optics_GetEnvColor(m_RefMap, refVec).rgb;
#endif
vec3 refColor = refGet * m_RefPower;
refTex = 1.0;
#if defined(REF_A_NOR) && defined(NORMALMAP)
refTex = normalHeight.a * m_RefIntensity;
diffuseColor.rgb += refColor * refTex;
#elif defined(REF_A_DIF) && !defined(REF_A_NOR) && defined(DIFFUSEMAP)
refTex = diffuseColor.a * m_RefIntensity;
diffuseColor.rgb += refColor.rgb * refTex;
#else
diffuseColor.rgb += refColor.rgb;
#endif
light.x = max(light.x, refGet refTex * 0.85);
#endif
#ifdef MINNAERT
// if (length(g_AmbientLightColor.xyz) != 0.0) { // 1st pass only
vec3 minnaert = pow( 1.0 - dot( normal.xyz, vViewDir.xyz ), 1.7 ) * m_Minnaert.xyz * m_Minnaert.w;
// minnaert.a = 0.0;
AmbientSum += minnaert.rgblight.x;
// light.x += minnaert0.1;
// }
#endif
#ifdef RIM_LIGHTING
vec4 rim = pow( 1.0 - dot( normal, vViewDir.xyz ), 1.5 ) * m_RimLighting * m_RimLighting.w;
rim.a = 0.0;
//ATI no likey
but it gives the desired effect on nvidia, note don’t have to call for it to work.
//AmbientSum += (rim.rgbdiffuseColor.rgb);
//trying to address incompatibility with ATI cards
vec3 amb = AmbientSum;
amb+= (rim.rgbdiffuseColor.rgb);
gl_FragColor.rgb += amb.rgb;
#endif
#ifdef RIM_LIGHTING_2
// if (length(g_AmbientLightColor.xyz) != 0.0) { // 1st pass only
vec3 rim2 = pow( 1.0 - dot( normal, vViewDir.xyz ), 1.5 ) * m_RimLighting2.xyz * m_RimLighting2.w;
AmbientSum += rim2;
// rim2.a = 0.0;
// gl_FragColor.rgb += rim2.rgbdiffuseColor.rgb;
// light.x += rim20.1;
// }
#endif
#ifdef HAS_LIGHTMAP
vec3 lightMapColor;
#ifdef SEPERATE_TEXCOORD
lightMapColor = texture2D(m_LightMap, texCoord2).rgb * m_LightMapIntensity;
#else
lightMapColor = texture2D(m_LightMap, texCoord).rgb * m_LightMapIntensity;
#endif
specularColor.rgb *= lightMapColor;
diffuseColor.rgb *= lightMapColor;
#endif
#if defined(SPECULAR_LIGHTING) && !defined(VERTEX_LIGHTING)
gl_FragColor.rgb = AmbientSum * diffuseColor.rgb +
DiffuseSum.rgb * diffuseColor.rgb * vec3(light.x) +
SpecularSum2.rgb * specularColor.rgb * vec3(light.y);
#endif
#if !defined(SPECULAR_LIGHTING) && !defined(VERTEX_LIGHTING)
gl_FragColor.rgb = AmbientSum * diffuseColor.rgb +
DiffuseSum.rgb * diffuseColor.rgb * vec3(light.x);
#endif
#endif
gl_FragColor.a = alpha;
}
[/java]
vert: I did nothing here
[java]#define ATTENUATION
//#define HQ_ATTENUATION
uniform mat4 g_WorldViewProjectionMatrix;
uniform mat4 g_WorldViewMatrix;
uniform mat3 g_NormalMatrix;
uniform mat4 g_ViewMatrix;
varying vec3 mat;
uniform vec4 m_Ambient;
uniform vec4 m_Diffuse;
uniform vec4 m_Specular;
uniform float m_Shininess;
uniform vec4 g_LightColor;
uniform vec4 g_LightPosition;
uniform vec4 g_AmbientLightColor;
varying vec2 texCoord;
#ifdef SEPERATE_TEXCOORD
attribute vec2 inTexCoord2;
varying vec2 texCoord2;
#endif
#ifdef SEPERATE_TEXCOORD2
attribute vec2 inTexCoord3;
varying vec2 texCoord3;
#endif
varying vec3 AmbientSum;
varying vec4 DiffuseSum;
varying vec3 SpecularSum;
attribute vec3 inPosition;
attribute vec2 inTexCoord;
attribute vec3 inNormal;
varying vec3 lightVec;
//varying vec4 spotVec;
#ifdef VERTEX_COLOR
attribute vec4 inColor;
#endif
#ifndef VERTEX_LIGHTING
attribute vec4 inTangent;
#ifndef NORMALMAP
varying vec3 vNormal;
#endif
varying vec3 vPosition;
varying vec3 vViewDir;
varying vec4 vLightDir;
#else
varying vec2 vertexLightValues;
uniform vec4 g_LightDirection;
#endif
#if defined(REFLECTION) || defined(IBL) || defined(IBL_SIMPLE) || defined(FOG_SKY)
varying vec3 I;
uniform vec3 g_CameraPosition;
uniform mat4 g_WorldMatrix;
#endif
#if defined(REFLECTION) || defined(IBL) || defined(IBL_SIMPLE)
varying vec3 refVec;
varying vec3 iblVec;
#endif
#ifdef FOG
varying float fog_z;
#endif
// JME3 lights in world space
void lightComputeDir(in vec3 worldPos, in vec4 color, in vec4 position, out vec4 lightDir){
float posLight = step(0.5, color.w);
vec3 tempVec = position.xyz * sign(posLight - 0.5) - (worldPos * posLight);
lightVec = tempVec;
#ifdef ATTENUATION
float dist = length(tempVec);
lightDir.w = clamp(1.0 - position.w * dist * posLight, 0.0, 1.0);
lightDir.xyz = tempVec / vec3(dist);
#else
lightDir = vec4(normalize(tempVec), 1.0);
#endif
}
#ifdef VERTEX_LIGHTING
float lightComputeDiffuse(in vec3 norm, in vec3 lightdir){
return max(0.0, dot(norm, lightdir));
}
#if defined(SPECULAR_LIGHTING) && defined(VERTEX_LIGHTING)
float lightComputeSpecular(in vec3 norm, in vec3 viewdir, in vec3 lightdir, in float shiny){
if (shiny <= 1.0){
return 0.0;
}
#ifndef LOW_QUALITY
vec3 H = (viewdir + lightdir) * vec3(0.5);
return pow(max(dot(H, norm), 0.0), shiny);
#else
return 0.0;
#endif
}
#endif
vec2 computeLighting(in vec3 wvPos, in vec3 wvNorm, in vec3 wvViewDir, in vec4 wvLightPos){
vec4 lightDir;
lightComputeDir(wvPos, g_LightColor, wvLightPos, lightDir);
float spotFallOff = 1.0;
if(g_LightDirection.w != 0.0){
vec3 L=normalize(lightVec.xyz);
vec3 spotdir = normalize(g_LightDirection.xyz);
float curAngleCos = dot(-L, spotdir);
float innerAngleCos = floor(g_LightDirection.w) * 0.001;
float outerAngleCos = fract(g_LightDirection.w);
float innerMinusOuter = innerAngleCos - outerAngleCos;
spotFallOff = clamp((curAngleCos - outerAngleCos) / innerMinusOuter, 0.0, 1.0);
}
float diffuseFactor = lightComputeDiffuse(wvNorm, lightDir.xyz);
#if defined(SPECULAR_LIGHTING) && defined(VERTEX_LIGHTING)
float specularFactor = lightComputeSpecular(wvNorm, wvViewDir, lightDir.xyz, m_Shininess);
#endif
#if !defined(SPECULAR_LIGHTING) && defined(VERTEX_LIGHTING)
float specularFactor = 0.0;
#endif
return vec2(diffuseFactor, specularFactor) * vec2(lightDir.w)*spotFallOff;
// float diffuseFactor = lightComputeDiffuse(wvNorm, lightDir.xyz);
}
#endif
void main(){
vec4 pos = vec4(inPosition, 1.0);
gl_Position = g_WorldViewProjectionMatrix * pos;
texCoord = inTexCoord;
#ifdef SEPERATE_TEXCOORD
texCoord2 = inTexCoord2;
#endif
#ifdef SEPERATE_TEXCOORD2
texCoord3 = inTexCoord3;
#endif
vec3 wvPosition = (g_WorldViewMatrix * pos).xyz;
vec3 wvNormal = normalize(g_NormalMatrix * inNormal);
vec3 viewDir = normalize(-wvPosition);
//vec4 lightColor = g_LightColor[gl_InstanceID];
//vec4 lightPos = g_LightPosition[gl_InstanceID];
//vec4 wvLightPos = (g_ViewMatrix * vec4(lightPos.xyz, lightColor.w));
//wvLightPos.w = lightPos.w;
vec4 wvLightPos = (g_ViewMatrix * vec4(g_LightPosition.xyz,clamp(g_LightColor.w,0.0,1.0)));
wvLightPos.w = g_LightPosition.w;
vec4 lightColor = g_LightColor;
#if defined(NORMALMAP) || defined(NORMALMAP_1) || defined(NORMALMAP_2) || defined(NORMALMAP_3) && !defined(VERTEX_LIGHTING)
vec3 wvTangent = normalize(g_NormalMatrix * inTangent.xyz);
vec3 wvBinormal = cross(wvNormal, wvTangent);
mat3 tbnMat = mat3(wvTangent, wvBinormal * -inTangent.w,wvNormal);
mat = vec3(1.0) * tbnMat;
mat = normalize(mat);
vPosition = wvPosition * tbnMat;
vViewDir = viewDir * tbnMat;
lightComputeDir(wvPosition, lightColor, wvLightPos, vLightDir);
vLightDir.xyz = (vLightDir.xyz * tbnMat).xyz;
#elif !defined(VERTEX_LIGHTING)
vNormal = wvNormal;
vPosition = wvPosition;
vViewDir = viewDir;
lightComputeDir(wvPosition, lightColor, wvLightPos, vLightDir);
#ifdef V_TANGENT
vNormal = normalize(g_NormalMatrix * inTangent.xyz);
vNormal = -cross(cross(vLightDir.xyz, vNormal), vNormal);
#endif
#endif
//computing spot direction in view space and unpacking spotlight cos
// spotVec = (g_ViewMatrix * vec4(g_LightDirection.xyz, 0.0) );
// spotVec.w = floor(g_LightDirection.w) * 0.001;
// lightVec.w = fract(g_LightDirection.w);
lightColor.w = 1.0;
#ifdef MATERIAL_COLORS
AmbientSum = (m_Ambient * g_AmbientLightColor).rgb;
DiffuseSum = m_Diffuse * lightColor;
SpecularSum = (m_Specular * lightColor).rgb;
#else
AmbientSum = vec3(0.2, 0.2, 0.2) * g_AmbientLightColor.rgb; // Default: ambient color is dark gray
DiffuseSum = lightColor;
SpecularSum = (m_Specular * lightColor).rgb;
// SpecularSum = vec3(0.0);
#endif
#ifdef VERTEX_COLOR
AmbientSum *= inColor.rgb;
DiffuseSum *= inColor;
#endif
#ifdef VERTEX_LIGHTING
vertexLightValues = computeLighting(wvPosition, wvNormal, viewDir, wvLightPos);
#endif
#if defined (REFLECTION) || defined (IBL) || defined(FOG_SKY) || defined(IBL_SIMPLE)
vec3 worldPos = (g_WorldMatrix * pos).xyz;
I = normalize( g_CameraPosition - worldPos ).xyz;
#endif
#if defined (REFLECTION) || defined (IBL) || defined(IBL_SIMPLE)
//Reflection vectors calculation
vec3 N = normalize( (g_WorldMatrix * vec4(inNormal, 0.0)).xyz );
refVec = reflect(I, N);
iblVec = refVec;
#endif
#ifdef FOG
fog_z = gl_Position.z;
#endif
}[/java]