As I said I tweaked the Minnaert function and now I’ve got such a result. I would like to get a feedback from you CORE DEVS.
The main idea is to create a material as a velvet…
[java]
float lightComputeDiffuse(in vec3 norm, in vec3 lightdir, in vec3 viewdir){
#ifdef MINNAERT
float NdotL = max(0.0, dot(norm, lightdir));
float NdotV = max(0.0, dot(norm, viewdir));
return (max(NdotL,( pow(max( NdotV, 0.4), -1.0)) * (0.9 - NdotV))); //my formula
// return NdotL * pow(max(NdotL * NdotV, 0.1), -1.0) * 0.5;
#else
return max(0.0, dot(norm, lightdir));
#endif
}
[/java]
Screen:
Uploaded with ImageShack.us
Great work, but micro improvements are the fun part, improving fps by percent improving loops etc… don’t take it all from us ^^ Just kidding of course, great contributions
Can I see comparison of old minnaert vs. new minnaert? Also, why did you edit it? I essentially just copied it directly from Blender3D so if you edit it, it won’t be the right formula anymore.
Oh, now i understand… if i change a formula so i will get another shader…
minnaert works wor rendering in blender as far as i know…
I just actually want to get something like Fresnel.
Uploaded with ImageShack.us
Uploaded with ImageShack.us
As you see above the original formula of minnaert looks strange. it’s very contrast unusable.
What about such a formula:
[java]
return (NdotL*( pow(max (NdotV, 0.3), -1.0) * 0.5 ));[/java]
Uploaded with ImageShack.us
Just some update of my work with lighting material improvements:
1 I finally fixed minnaert function. I think it will be need to implement minnaert backlighting intensity (just like i did for specularIntensity).
2 I work with reflection improvements. Now reflection works through diffuseColor instead of specularColor. And reflection works with normal maps!!! But encoured with the problem of reflection with normals works incorrectly in the seams and some parts of rflections are flipped (like it was a problem with normal mapping in Alpha3). Nehon fixed the problem with normals and lighting. I hope he will help me with reflection too.
Formula for minnaert:
[java]
#ifdef MINNAERT
float NdotL = max(0.0, dot(norm, lightdir));
float NdotV = max(0.0, dot(norm, viewdir));
return (NdotL*( pow(max (NdotV, 0.2), -1.0) * 0.5 ));
//return NdotL * pow(max(NdotL* NdotV, 0.1), -1.0) * 0.5;
#else
return max(0.0, dot(norm, lightdir));
#endif
[/java]
Minnaert screens:
Uploaded with ImageShack.us
Uploaded with ImageShack.us
Formula for reflection:
[java]
#ifdef USE_REFLECTION
vec4 refColor = Optics_GetEnvColor(m_EnvMap, reflect(refVec.xyz, normal.xyz));
// Interpolate light specularity toward reflection color
// Multiply result by specular map
diffuseColor = mix(DiffuseSum, refColor, refVec.w);
DiffuseSum = vec4(1.0);
light.x = 1.0;
#endif
[/java]
Reflection screens:
Uploaded with ImageShack.us
Uploaded with ImageShack.us
You don’t have to do reflection through specular, just set diffuse color to 0 and specular to 1, it should have the same effect.
I don’t understand what you’re trying to achieve through the minnaert changes, that shading mode is generally used for cloth/velvet, not reflections
About Minnaert: the shading Minnaert is not usable with normal maps and I corrected it a bit. You see just static pictures, but if you will rotate objects you will understand. I’ll make video with comparison soon.
About Reflection: actually you will not get the same result if you have a normal map. At present, reflection does not count normals of normal map. So i try to change it. As you see above there are reflected models with normal map. Only normal map and reflection (no light). Reflections are distorted by normal map. It’s very important i suppose for realistic shading.
Hi guys, i’m about the end of writing the shader. I would like to host it somewhere with documentation and explanations. I can host it on GoogleCode, but possibly it would be better to host the shader in the JME branch?
I suppose that some things you will not want to implement to default Lighting shader, so i decided to host it under a name “LightBlow”. And BIG THANKS to momoko_fan, nehon, normen for some advices.
Features:
- Improved lighting calculations.
- Improved reflection calculations.
- Reflection map implementation with normal map alpha.
- Improved Minnaert calculations.
- Image Based Lighting with Albedo.
- Emissive map implementation with diffuse alpha.
- normalization of normals by default.
- Specular map implementation with normal map alpha.
- Specular intensity implementation.
- Switching -x/-y/-z normals for different normal maps (3dmax, blender, xnormal have different approaches).
- Clamping diffuseColor and specularColor by default (to get only (0.0, 1.0) intensity).
Just post the files here in code tags.
that looks good,
I especially like “- Switching -x/-y/-z normals for different normal maps (3dmax, blender, xnormal have different approaches).”
I think it could be added as the default lighting material, but first it need to be thoroughly tested
Nice work @mifth
Good news! thanks guys. I’ll post as soon as possible here.
Giys, I finished material improvements. I hope you will like it.
All features:
- Improved lighting calculations.
- Improved reflection calculations.
- Reflection map implementation with normal map alpha.
- Improved Minnaert calculations.
- Image Based Lighting with Albedo.
- Emissive map implementation with diffuse alpha.
- normalization of normals by default.
- Specular map implementation with normal map alpha.
- Specular intensity implementation.
- Switching -x/-y/-z normals for different normal maps (3dmax, blender, xnormal have different approaches).
- Clamping diffuseColor and specularColor by default (to get only (0.0, 1.0) intensity).
- Hemispherical lighting.
- “Specular Color” now can be used for specular maps too.
- “No attenuation” switches off att parameter. Increase fps a bit,
- AphaMap is renamed to Alpha_A_Dif. it uses diffuse alpha channel.
- USE_REFLECTION is renamed to REFLECTION.
My little video introduction to the features:
http://www.youtube.com/watch?v=knROh_3o2uo
I'll write full description soon..
The code is downloadable from:
http://code.google.com/p/jme-glsl-shaders/downloads/list - entire JMP project.
If someone wants to change something or share with his thoughts, so you are welcome.
Future features which i did not make:
- Using Emissive map as Glow Map (for glow shader).
- make static Image Based Lighting. Dynamic IBL works like reflection.
- Fog Color based on IBL Map. It was made in Lugaru project and looks cool.
Hm is there a good audio version of the video? I hardly understand anything at all
have a try to look it on youtube and use 480p/720p instead of 360p.
For those who don’t want to download entire project here is the code of shaders:
Sample of usage the shader in the code:
[java]
TextureKey skyhi = new TextureKey(“Textures/Water256.dds”, true);
skyhi.setGenerateMips(true);
skyhi.setAsCube(true);
final Texture texhi = assetManager.loadTexture(skyhi);
rootNode.attachChild(SkyFactory.createSky(assetManager, texhi, false));
TextureKey skylow = new TextureKey(“Textures/Water32.dds”, true);
skylow.setGenerateMips(true);
skylow.setAsCube(true);
final Texture texlow = assetManager.loadTexture(skylow);
Spatial char_boy = assetManager.loadModel(“Models/jme_lightblow/sphere.j3o”);
mat = new Material(assetManager, “MatDefs/LightBlow.j3md”);
mat.setTexture(“DiffuseMap”, assetManager.loadTexture(“Models/jme_lightblow/jme_lightblow_dif.png”));
mat.setTexture(“NormalMap”, assetManager.loadTexture(“Models/jme_lightblow/jme_lightblow_nor.png”));
mat.setTexture(“IblMap”, texlow);
// mat.setFloat(“iblIntensity”, 1.5f);
// mat.setTexture(“RefMap”, texhi);
// mat.setBoolean(“Ref_A_Nor”, true);
// mat.setFloat(“RefPower”, 1.2f);
// mat.setFloat(“RefIntensity”, 1.5f);
// mat.setBoolean(“EmissiveMap”, true);
// mat.setBoolean(“Alpha_A_Dif”, true);
// mat.setBoolean(“Specular_Lighting”, true);
// mat.setBoolean(“Spec_A_Dif”, true);
// mat.setFloat(“SpecIntensity”, 2.0f);
// mat.setBoolean(“Hemi_Lighting”, true);
// mat.setBoolean(“Minnaert”, true);
// mat.setFloat(“MinnaertInt”, 1.3f);
// mat.setBoolean(“Nor_Inv_X”, true);
// mat.setBoolean(“Nor_Inv_Y”, true);
// mat.setBoolean(“Nor_Inv_Z”, true);
// mat.setFloat(“AlphaDiscardThreshold”, 0.7f);
// mat.setColor(“Specular”, new ColorRGBA(1.0f,1.0f,0.0f,1.0f));
// mat.setFloat(“Shininess”, 5.0f);
char_boy.setMaterial(mat);
rootNode.attachChild(char_boy);
[/java]
Vertex Shader:
[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 = vec4(1.0);
uniform float m_Shininess;
uniform vec4 g_LightColor;
uniform vec4 g_LightPosition;
uniform vec4 g_AmbientLightColor;
varying vec2 texCoord;
varying vec4 AmbientSum;
varying vec4 DiffuseSum;
varying vec4 SpecularSum;
attribute vec3 inPosition;
attribute vec2 inTexCoord;
attribute vec3 inNormal;
#ifdef HQ_ATTENUATION
varying vec3 lightVec;
#endif
#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;
#endif
#if defined(REFLECTION) || defined(IBL)
uniform vec3 g_CameraPosition;
uniform mat4 g_WorldMatrix;
varying vec4 refVec;
varying vec4 iblVec;
#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);
#ifdef ATTENUATION
float dist = length(tempVec);
lightDir.w = clamp(1.0 - position.w * dist * posLight, 0.0, 1.0);
lightDir.xyz = tempVec / vec3(dist);
#ifdef HQ_ATTENUATION
lightVec = tempVec;
#endif
#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){
#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 diffuseFactor = lightComputeDiffuse(wvNorm, lightDir.xyz);
#if defined(SPECULAR_LIGHTING) && defined(VERTEX_LIGHTING)
float specularFactor = lightComputeSpecular(wvNorm, wvViewDir, lightDir.xyz, m_Shininess);
//specularFactor = step(0.01, diffuseFactor);
return vec2(diffuseFactor, specularFactor) * vec2(lightDir.w);
#endif
#if !defined(SPECULAR_LIGHTING) && defined(VERTEX_LIGHTING)
return vec2(diffuseFactor, 0.0) * vec2(lightDir.w);
#endif
}
#endif
void main(){
vec4 temp;
vec4 pos = vec4(inPosition, 1.0);
gl_Position = g_WorldViewProjectionMatrix * pos;
texCoord = inTexCoord;
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, g_LightColor.w));
wvLightPos.w = g_LightPosition.w;
vec4 lightColor = g_LightColor;
#if defined(NORMALMAP) && !defined(VERTEX_LIGHTING)
vec3 wvTangent = normalize(g_NormalMatrix * inTangent.xyz);
vec3 wvBinormal = cross(wvNormal, wvTangent);
mat3 tbnMat = mat3(wvTangent, wvBinormal * -inTangent.w,wvNormal);
mat3 tbnMat2 = mat3(wvTangent, wvBinormal , 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
lightColor.w = 1.0;
#ifdef MATERIAL_COLORS
// AmbientSum = m_Ambient * g_AmbientLightColor;
DiffuseSum = m_Diffuse * lightColor;
SpecularSum = m_Specular * lightColor;
#else
AmbientSum = vec4(0.2, 0.2, 0.2, 1.0) * g_AmbientLightColor; // Default: ambient color is dark gray
DiffuseSum = lightColor;
SpecularSum = m_Specular * lightColor;
#endif
#ifdef VERTEX_COLOR
AmbientSum = inColor;
DiffuseSum = inColor;
#endif
#ifdef VERTEX_LIGHTING
vec2 light = computeLighting(wvPosition, wvNormal, viewDir, wvLightPos);
AmbientSum.a = light.x;
SpecularSum.a = light.y;
#endif
#if defined (REFLECTION) || defined (IBL)
//Reflection vectors calculation
vec3 worldPos = (g_WorldMatrix * pos).xyz;
vec3 I = normalize( g_CameraPosition - worldPos ).xyz;
vec3 N = normalize( (g_WorldMatrix * vec4(inNormal, 0.0)).xyz );
refVec.xyz = reflect(I, N);
// refVec.xyz = normalize(refVec.xyz);
iblVec.xyz = refVec.xyz;
//refVec.w = m_FresnelParams.x + m_FresnelParams.y * pow(1.0 + dot(I, N), m_FresnelParams.z);
#endif
}
[/java]
Fragment Shader:
[java]
#import “Common/ShaderLib/Optics.glsllib”
#define ATTENUATION
//#define HQ_ATTENUATION
varying vec2 texCoord;
varying vec4 AmbientSum;
varying vec4 DiffuseSum;
varying vec4 SpecularSum;
#ifndef VERTEX_LIGHTING
varying vec3 vPosition;
varying vec3 vViewDir;
varying vec4 vLightDir;
varying vec3 mat;
#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
uniform float m_AlphaDiscardThreshold;
#ifndef VERTEX_LIGHTING
uniform float m_Shininess = 1.0;
uniform float m_SpecIntensity = 1.0;
#ifdef HQ_ATTENUATION
uniform vec4 g_LightPosition;
varying vec3 lightVec;
#endif
#ifdef IBL
varying vec4 iblVec;
uniform ENVMAP m_IblMap;
uniform float m_iblIntensity = 1.0;
#endif
#ifdef REFLECTION
// uniform float m_ReflectionPower;
uniform float m_RefPower = 1.0;
uniform float m_RefIntensity = 1.0;
varying vec4 refVec;
uniform ENVMAP m_RefMap;
#endif
#ifdef MINNAERT
uniform float m_MinnaertInt = 1.0;
#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 (MINNAERT)
float NdotL = max(0.0, dot(norm, lightdir));
float NdotV = max(0.0, dot(norm, viewdir));
return (NdotL( pow(max (NdotV, 0.13), -1.0 * m_MinnaertInt) * 0.5 ));
//return (max(NdotL,( pow(max( NdotV, 0.3), -1.0)) * 0.5 * (0.8 - NdotV))); //my formula
//return NdotL * pow(max(NdotL NdotV, 0.1), -1.0) * 0.5;
#elif !defined (MINNAERT) && defined(HEMI_LIGHTING)
return (0.5 + 0.5 * dot(norm, lightdir)) * (0.5 + 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){
#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)/(p*p)) / (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);
#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
#if defined(SPECULAR_LIGHTING)
float specularFactor = lightComputeSpecular(wvNorm, wvViewDir, wvLightDir, m_Shininess);
specularFactor = (specularFactor * step(1.0, m_Shininess)) * m_SpecIntensity;
return vec2(diffuseFactor, specularFactor) * vec2(att);
#endif
#if !defined(SPECULAR_LIGHTING)
return vec2(diffuseFactor, 0.0) * vec2(att);
#endif
}
#endif
void main(){
vec2 newTexCoord;
#if defined(PARALLAXMAP) || defined(NORMALMAP_PARALLAX)
float h;
#ifdef PARALLAXMAP
h = texture2D(m_ParallaxMap, texCoord).r;
#else
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
float alpha = 1.0;
// float alpha = DiffuseSum.a * diffuseColor.a;
#if defined (ALPHA_A_DIF) && defined (DIFFUSEMAP)
alpha = DiffuseSum.a * diffuseColor.a;
#endif
if(alpha < m_AlphaDiscardThreshold){
discard;
}
#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;
#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
#ifdef VERTEX_LIGHTING
vec2 light = vec2(AmbientSum.a, SpecularSum.a);
#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
#if defined(SPECULAR_LIGHTING) && defined(VERTEX_LIGHTING)
gl_FragColor = AmbientSum * diffuseColor +
DiffuseSum * diffuseColor * light.x +
SpecularSum * specularColor * light.y;
#endif
#if !defined(SPECULAR_LIGHTING) && defined(VERTEX_LIGHTING)
gl_FragColor = AmbientSum * diffuseColor +
DiffuseSum * diffuseColor * light.x;
#endif
#else
vec4 lightDir = vLightDir;
lightDir.xyz = normalize(lightDir.xyz);
vec2 light = computeLighting(vPosition, normal, vViewDir.xyz, lightDir.xyz);
#ifdef COLORRAMP
diffuseColor.rgb *= texture2D(m_ColorRamp, vec2(light.x, 0.0)).rgb;
specularColor.rgb *= texture2D(m_ColorRamp, vec2(light.y, 0.0)).rgb;
#endif
// Workaround, since it is not possible to modify varying variables
vec4 SpecularSum2 = SpecularSum;
#ifdef IBL
// IBL - Image Based Lighting. The lighting based on either cube map or sphere map.
#if defined (IBL) && defined (NORMALMAP)
vec4 iblLight = Optics_GetEnvColor(m_IblMap, (iblVec.xyz - (mat.xyz * normal.xyz))*5.0);
#elif defined (IBL) && !defined (NORMALMAP)
vec4 iblLight = Optics_GetEnvColor(m_IblMap, iblVec.xyz);
#endif
//Albedo - multiplies diffuse and IBL. ***
AmbientSum += iblLight * m_iblIntensity;
#endif
#if defined(EMISSIVEMAP) && defined(DIFFUSEMAP)
//Illumination based on diffuse map alpha chanel.
float emissiveTex = texture2D(m_DiffuseMap, texCoord).a;
//diffuseColor = max(diffuseColor, emissiveSum);
light.x = light.x + 1.1 * emissiveTex;
//light.x = max(light.x, 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)5.0);
#elif defined (REFLECTION) && !defined (NORMALMAP)
vec4 refGet = Optics_GetEnvColor(m_RefMap, refVec.xyz);
#endif
vec4 refColor = refGet * m_RefPower;
float refTex = 1.0;
#if defined(REF_A_NOR) && defined(NORMALMAP)
refTex = texture2D(m_NormalMap, texCoord).a * m_RefIntensity;
diffuseColor += refColor * refTex;
#elif defined(REF_A_DIF) && !defined(REF_A_NOR) && defined(DIFFUSEMAP)
refTex = texture2D(m_DiffuseMap, texCoord).a * m_RefIntensity;
diffuseColor += refColor * refTex;
#else
diffuseColor += refColor;
#endif
light.x = max(light.x, refGet refTex * 0.5);
#endif
diffuseColor = clamp(diffuseColor, 0.0, 1.0);
specularColor = clamp(specularColor, 0.0, 1.0);
#if defined(SPECULAR_LIGHTING) && !defined(VERTEX_LIGHTING)
gl_FragColor = AmbientSum * diffuseColor +
DiffuseSum * diffuseColor * light.x +
SpecularSum2 * specularColor * light.y;
#endif
#if !defined(SPECULAR_LIGHTING) && !defined(VERTEX_LIGHTING)
gl_FragColor = AmbientSum * diffuseColor +
DiffuseSum * diffuseColor * light.x;
#endif
#endif
gl_FragColor.a = alpha;
}
[/java]
MatDef Material (Please, change your own location for LightBlow.Frag and LightBlow.vert):
[java]
MaterialDef Phong Lighting {
MaterialParameters {
// No attenuation increases fps
Boolean No_Attenuation
// Output emission from the diffuse map
Boolean EmissiveMap
// Output alpha from the diffuse map
Boolean Alpha_A_Dif
// Switch Normal Map xyz(rgb) channels
Boolean Nor_Inv_X
Boolean Nor_Inv_Y
Boolean Nor_Inv_Z
// IBL Map for Image Based Lighting
TextureCubeMap IblMap
// Image Based Lighting Intensity
Float iblIntensity
// Switch Hemispherical Lighting on/off
Boolean Hemi_Lighting
// Switch specular lighting on/off
Boolean Specular_Lighting
// Specular intensity
Float SpecIntensity
// Output specular from the normal map
Boolean Spec_A_Nor
// Output specular from the diffuse map
Boolean Spec_A_Dif
// Output reflection from the normal map
Boolean Ref_A_Nor
// Output reflection from the diffuse map
Boolean Ref_A_Dif
// Reflection Intensity
Float RefPower
// Reflection normal map alpha channel Intensity
Float RefIntensity
// Minnaert Intensity
Float MinnaertInt
// Compute vertex lighting in the shader
// For better performance
Boolean VertexLighting
// Use more efficent algorithms to improve performance
Boolean LowQuality
// Improve quality at the cost of performance
Boolean HighQuality
// Apha threshold for fragment discarding
Float AlphaDiscardThreshold
// Normal map is in BC5/ATI2n/LATC/3Dc compression format
Boolean LATC
// Use the provided ambient, diffuse, and specular colors
Boolean UseMaterialColors
// Activate shading along the tangent, instead of the normal
// Requires tangent data to be available on the model.
Boolean VTangent
// Use minnaert diffuse instead of lambert
Boolean Minnaert
// Use ward specular instead of phong
Boolean WardIso
// Use vertex color as an additional diffuse color.
Boolean UseVertexColor
// Ambient color
Color Ambient
// Diffuse color
Color Diffuse : Color
// Specular color
Color Specular
// Specular power/shininess
Float Shininess
// Diffuse map
Texture2D DiffuseMap
// Normal map
Texture2D NormalMap
// Specular/gloss map
Texture2D SpecularMap
// Parallax/height map
Texture2D ParallaxMap
// Color ramp, will map diffuse and specular values through it.
Texture2D ColorRamp
// Texture of the glowing parts of the material
Texture2D GlowMap
// The glow color of the object
Color GlowColor
// Parameters for fresnel
// X = bias
// Y = scale
// Z = power
// Vector3 FresnelParams
// Ref Map for reflection
TextureCubeMap RefMap
// the ref map is a spheremap and not a cube map
Boolean SphereMap
}
Technique {
LightMode MultiPass
VertexShader GLSL100: Shaders/LightBlow.vert
FragmentShader GLSL100: Shaders/LightBlow.frag
WorldParameters {
WorldViewProjectionMatrix
NormalMatrix
WorldViewMatrix
ViewMatrix
CameraPosition
WorldMatrix
}
Defines {
ALPHA_A_DIF : Alpha_A_Dif
NO_ATTENUATION : No_Attenuation
EMISSIVEMAP : EmissiveMap
NOR_INV_X : Nor_Inv_X
NOR_INV_Y : Nor_Inv_Y
NOR_INV_Z : Nor_Inv_Z
IBL : IblMap
HEMI_LIGHTING : Hemi_Lighting
SPECULAR_LIGHTING : Specular_Lighting
SPEC_A_NOR : Spec_A_Nor
SPEC_A_DIF : Spec_A_Dif
REF_A_NOR : Ref_A_Nor
REF_A_DIF : Ref_A_Dif
LATC : LATC
VERTEX_COLOR : UseVertexColor
VERTEX_LIGHTING : VertexLighting
ATTENUATION : Attenuation
MATERIAL_COLORS : UseMaterialColors
V_TANGENT : VTangent
MINNAERT : Minnaert
WARDISO : WardIso
LOW_QUALITY : LowQuality
HQ_ATTENUATION : HighQuality
DIFFUSEMAP : DiffuseMap
NORMALMAP : NormalMap
SPECULARMAP : SpecularMap
PARALLAXMAP : ParallaxMap
COLORRAMP : ColorRamp
REFLECTION : RefMap
SPHERE_MAP : SphereMap
}
}
Technique PreShadow {
VertexShader GLSL100 : Common/MatDefs/Shadow/PreShadow.vert
FragmentShader GLSL100 : Common/MatDefs/Shadow/PreShadow.frag
WorldParameters {
WorldViewProjectionMatrix
WorldViewMatrix
}
Defines {
DIFFUSEMAP_ALPHA : DiffuseMap
}
RenderState {
FaceCull Off
DepthTest On
DepthWrite On
PolyOffset 5 0
ColorWrite Off
}
}
Technique PreNormalPass {
VertexShader GLSL100 : Common/MatDefs/SSAO/normal.vert
FragmentShader GLSL100 : Common/MatDefs/SSAO/normal.frag
WorldParameters {
WorldViewProjectionMatrix
WorldViewMatrix
NormalMatrix
}
Defines {
DIFFUSEMAP_ALPHA : DiffuseMap
}
RenderState {
}
}
Technique FixedFunc {
LightMode FixedPipeline
}
Technique GBuf {
VertexShader GLSL100: Common/MatDefs/Light/GBuf.vert
FragmentShader GLSL100: Common/MatDefs/Light/GBuf.frag
WorldParameters {
WorldViewProjectionMatrix
NormalMatrix
WorldViewMatrix
WorldMatrix
}
Defines {
VERTEX_COLOR : UseVertexColor
MATERIAL_COLORS : UseMaterialColors
V_TANGENT : VTangent
MINNAERT : Minnaert
WARDISO : WardIso
DIFFUSEMAP : DiffuseMap
NORMALMAP : NormalMap
SPECULARMAP : SpecularMap
PARALLAXMAP : ParallaxMap
}
}
Technique FixedFunc {
LightMode FixedPipeline
}
Technique Glow {
VertexShader GLSL100: Common/MatDefs/Misc/SimpleTextured.vert
FragmentShader GLSL100: Common/MatDefs/Light/Glow.frag
WorldParameters {
WorldViewProjectionMatrix
}
Defines {
HAS_GLOWMAP : GlowMap
HAS_GLOWCOLOR : GlowColor
}
}
}
[/java]
@mifth : Hey , It’s definitely good I might say Copy and paste it to test in my case , BIG thank and have a good day man!
No problem :). If you find any problems just give me to know.
Some of the changes are good, I have some comments though:
Hemi Lighting
It just squares the NdotL component, its not real hemisphere lighting.
The best way to have real hemisphere lighting is probably through your IBL (image based lighting)
Reflection
I dont understand, why you removed the fresnel equation. Currently your reflection calculation does not represent the real world phenomenon. Adding the reflection result to the diffuse color is not correct.
Setting uniform values
Setting the uniform values right in the shader, like:
[java]uniform float m_ABC = 1.0; [/java]
Is not compliant with the GLSL specification before GLSL 3.3, your shader will not work on old video cards.
Limiting diffuse/specular colors to 1
It is not a bug that the colors are not limited to 1, it is a feature. For HDR (High Dynamic Range) rendering, you want the colors to represent the actual luminance of the object. For example, the sun would have a color with magnitudes like 300,000 to represent its actual brightness. This will then get scaled down by the tone mapping algorithm.
Here’s an example video to demonstrate:
http://www.youtube.com/watch?v=I4Ot1ZXf_HE
Notice how many of the values used in the video are greater than 1
Emission map
In my opinion, emission map should be the same as the glow map. Generally, something will glow because it emits light (when the bloom filter is set up in this way).