Shader patch

For collaboration on developing the mod capabilities of VS; request new features, report bugs, or suggest improvements

Moderator: Mod Contributor

Postby klauss » Mon Apr 07, 2008 7:41 am

First try removing the nigtside from the .system file. I believe it must be it, because of how it's implemented (it was a fixed-function GL trick that may do bad things to shaders). If that solves it, we'll look into fixing it later.

If that fails to fix it, remove all shininess from the shaders. I believe it may be a dataset problem, giving extreme shininess values to the shaders (too low or too high or something).

I'm quite confident the first one will work, tho.
Oíd mortales, el grito sagrado...
Call me "Menes, lord of Cats"
Wing Commander Universe
User avatar
klauss
Elite
Elite
 
Posts: 7243
Topics: 55
Joined: Mon Apr 18, 2005 7:40 am
Location: LS87, Buenos Aires, República Argentina

Share On:

Share on Facebook Facebook Share on Twitter Twitter Share on Digg Digg

Postby pyramid » Mon Apr 07, 2008 8:03 am

klauss wrote:First try removing the nigtside from the .system file.

Not sure I get this right. The definition that was used for the above file:
Code: Select all
<Planet name="Broadway" file="planets/university.png|planets/specular.png">
<Citylights file="planets/university_light.png" />
</Planet>

I.e. diffuse + specular + glow. There is no nightside as such, as you can only define textures that always cover the full planet. Do you mean the citylights?

Also note that I used the shader from PU svn, not the latest developments posted here, so self shadowing might still not be considered in the previous images.

As klauss says, planets would need a completely different shader anyway, so not sure if it's worth the effort testing planets shading with the shader that is being developed for units?
User avatar
pyramid
Expert Mercenary
Expert Mercenary
 
Posts: 960
Topics: 44
Joined: Wed Jun 14, 2006 6:02 pm
Location: Somewhere in the vastness of space

Postby chuck_starchaser » Mon Apr 07, 2008 8:48 am

I think Klauss means the city lights texture.
Here's the current shader code, not yet on PU's SVN. It has the self-shadow function restored, and soft penumbras...
(Specially good for planets... ;-))
PLUS, it lowers shininess even more (spec's red and green terms cubed before averaging).
PLUS, it has specular spot brightness modulation by shininess.

Code: Select all
uniform int light_enabled[gl_MaxLights];
uniform int max_light_enabled;
uniform sampler2D diffuseMap;
uniform sampler2D envMap;
uniform sampler2D specMap;
uniform sampler2D glowMap;
uniform sampler2D normalMap;
uniform sampler2D damageMap;
uniform sampler2D detail0Map;
uniform sampler2D detail1Map;
uniform vec4 cloaking;
uniform vec4 damage;
uniform vec4 envColor;

vec3 matmul(vec3 tangent, vec3 binormal, vec3 normal,vec3 lightVec) {
  return vec3(dot(lightVec,tangent),dot(lightVec,binormal),dot(lightVec,normal));
}
vec3 imatmul(vec3 tangent, vec3 binormal, vec3 normal,vec3 lightVec) {
  return lightVec.xxx*tangent+lightVec.yyy*binormal+lightVec.zzz*normal;
}

vec2 EnvMapGen(vec3 f) {
   float fzp1=f.z+1.0;
   float m=2.0*sqrt(f.x*f.x+f.y*f.y+(fzp1)*(fzp1));
   return vec2(f.x/m+.5,f.y/m+.5);
}

float bias(float f){ return f*0.5+0.5; }
vec2  bias(vec2 f) { return f*0.5+vec2(0.5); }
vec3  bias(vec3 f) { return f*0.5+vec3(0.5); }
vec4  bias(vec4 f) { return f*0.5+vec4(0.5); }

float expand(float f){ return f*2.0-1.0; }
vec2  expand(vec2 f) { return f*2.0-vec2(1.0); }
vec3  expand(vec3 f) { return f*2.0-vec3(1.0); }
vec4  expand(vec4 f) { return f*2.0-vec4(1.0); }

float lerp(float f, float a, float b){return (1.0-f)*a+f*b; }
vec2  lerp(float f, vec2 a, vec2 b) { return (1.0-f)*a+f*b; }
vec3  lerp(float f, vec3 a, vec3 b) { return (1.0-f)*a+f*b; }
vec4  lerp(float f, vec4 a, vec4 b) { return (1.0-f)*a+f*b; }

//float selfshadowStep(float VNdotL) { return step(0.0,VNdotL); } // fast but hard selfshadow function
float selfshadowStep(float VNdotL) { return smoothstep(0.0,0.125,VNdotL); } // costly but soft and nice selfshadow function
//float shininessMap(float shininess, vec4 specmap) { return clamp(specmap.a*shininess,1.0,255.0); } // alpha-based shininess modulation

float shininessMap(float shininess, vec4 specmap) // luma-based shininess modulation
{
  float3 temp = specmap.rgb;
  temp *= specmap.rgb;
  temp *= specmap.rgb;
  temp.b = (temp.r+temp.g)*0.75;
  return clamp( temp.b*shininess, 1.0, 255.0 );
}

float shininess2Lod(float shininess) { return max(0.0,7.0-log2(shininess+1.0))+3.0*(1.0+envColor.a); }

float limited_shininessMap(float shininess, float specmap)
{
  float limit = 50; //50^2 is 2500. 2500*0.001 = 2.5 --enough risk of saturation!
  float shine = shininessMap(shininess,specmap);
  return (shine*limit)/(shine+limit);
}

float shininess_to_brightness(float shininess)
{
  return 0.001 * shininess * shininess;
}

float lightspot_brightness( float shininess, float specmap )
{
  return limited_shininessMap( shininess, specmap ) * shininess_to_brightness( shininess );
}

void lightingLight(
   in vec3 light, in vec3 normal, in vec3 vnormal, in vec3 eye, in vec3 reflection,
   in vec4 lightDiffuse, in float lightAtt,
   in vec4 diffusemap, in vec4 specmap, in float shininess,
   in vec4 ambientProduct,
   inout vec3 diffuse, inout vec3 specular)
{
   float NdotL = dot(normal,light);
   float VNdotL= dot(vnormal,light);
   float s = 1.0 - (NdotL*NdotL);
   float RdotL = dot(reflection,light);
   float selfshadow = selfshadowStep(VNdotL);
   float temp = clamp( NdotL - (0.94 * s * s * s * s * NdotL) + 0.005, 0.0, 1.01 );
   specular += ( selfshadow * pow(clamp(RdotL,0.0,1.0), lightspot_brightness(shininess,specmap)) * lightDiffuse.rgb * lightAtt );
   diffuse  += ( selfshadow * temp * lightDiffuse.rgb * lightAtt );
}

#define lighting(name, lightno_gl, lightno_tex) \
void name( \
   in vec3 normal, in vec3 vnormal, in vec3 eye, in  vec3 reflection, \
   in vec4 diffusemap, in vec4 specmap, \
   inout vec3 diffuse, inout vec3 specular) \
{ \
   lightingLight( \
      normalize(gl_TexCoord[lightno_tex].xyz), normal, vnormal, eye, reflection, \
      gl_FrontLightProduct[lightno_gl].diffuse, \
      gl_TexCoord[lightno_tex].w, \
      diffusemap, specmap, gl_FrontMaterial.shininess, \
      gl_FrontLightProduct[lightno_gl].ambient, \
      diffuse, specular); \
}

lighting(lighting0, 0, 5)
lighting(lighting1, 1, 6)

vec3 lightingClose(in vec3 diffuse, in vec3 specular, in vec3 ambient, in vec4 diffusemap, in vec4 specmap)
{
   return (diffuse + ambient) * diffusemap.rgb + specular * specmap.rgb;
}

vec3 envMapping(in vec3 reflection, in float gloss, in vec4 specmap)
{
   float envLod = shininess2Lod(gloss);//shininessMap(shininess,specmap));
   return texture2DLod(envMap, EnvMapGen(reflection), envLod).rgb * specmap.rgb * vec3(2.0);
}

void main()
{
  // Retrieve normals
  vec3 iNormal=gl_TexCoord[1].xyz;
  vec3 iTangent=gl_TexCoord[2].xyz;
  vec3 iBinormal=gl_TexCoord[3].xyz;
  vec3 vnormal=iNormal;
  //vec3 normal=normalize(imatmul(iTangent,iBinormal,iNormal,expand(texture2D(normalMap,gl_TexCoord[0].xy).yxz)*vec3(-1.0,1.0,1.0)));
  vec3 normal=normalize(imatmul(iTangent,iBinormal,iNormal,expand(texture2D(normalMap,gl_TexCoord[0].xy).wyz)));
 
  // Other vectors
  vec3 eye = gl_TexCoord[4].xyz;
  vec3 reflection = -reflect(eye,normal);
 
  // Init lighting accumulators
  vec3 diffuse = vec3(0.0);
  vec3 specular= vec3(0.0);
  vec3 ambient = vec3(0.0);
 
  // Sample textures
  vec4 damagecolor = texture2D(damageMap , gl_TexCoord[0].xy);
  vec4 diffusecolor= texture2D(diffuseMap, gl_TexCoord[0].xy);
  vec4 speccolor   = texture2D(specMap   , gl_TexCoord[0].xy);
  vec4 glowcolor   = texture2D(glowMap   , gl_TexCoord[0].xy);
  //sanity enforcement:
  float temp = 1.0 - max( diffusecolor.r, max( diffusecolor.g, diffusecolor.b ) );
  speccolor.r = min( speccolor.r, temp );
  speccolor.g = min( speccolor.g, temp );
  speccolor.b = min( speccolor.b, temp );
 
  vec4 diffusemap  = lerp(damage.x, diffusecolor, damagecolor);
  vec4 specmap     = speccolor;
  float specdamage = clamp(1.0 - dot(damagecolor.xyz,vec3(1.0/3.0)) * damage.x * 2.0, 0.0, 1.0);
  specmap.rgb     *= specdamage;
  specmap.a       *= bias(specdamage);
  float gloss      = shininessMap(gl_FrontMaterial.shininess,specmap);
 
  // Do lighting for every active light
  if (light_enabled[0] != 0)
     lighting0(normal, vnormal, eye, reflection, diffusemap, specmap, diffuse, specular);
  if (light_enabled[1] != 0)
     lighting1(normal, vnormal, eye, reflection, diffusemap, specmap, diffuse, specular);

  vec4 result;
  result.rgb  = lightingClose(diffuse, specular, ambient, diffusemap, specmap)
              + glowcolor.rgb
              + envMapping(reflection,gloss,specmap);
  result.a = diffusemap.a;
  result *= cloaking.rrrg;
 
  gl_FragColor = result;
}
User avatar
chuck_starchaser
Elite
Elite
 
Posts: 8014
Topics: 195
Joined: Thu Sep 04, 2003 9:03 pm
Location: Montreal

Postby klauss » Mon Apr 07, 2008 5:39 pm

I do mean the citylights.
Oíd mortales, el grito sagrado...
Call me "Menes, lord of Cats"
Wing Commander Universe
User avatar
klauss
Elite
Elite
 
Posts: 7243
Topics: 55
Joined: Mon Apr 18, 2005 7:40 am
Location: LS87, Buenos Aires, República Argentina

Postby pyramid » Tue Apr 08, 2008 4:34 pm

Disabling the citylights and appending specular only without shininess doesn't seem to help.
User avatar
pyramid
Expert Mercenary
Expert Mercenary
 
Posts: 960
Topics: 44
Joined: Wed Jun 14, 2006 6:02 pm
Location: Somewhere in the vastness of space

Postby klauss » Tue Apr 08, 2008 6:14 pm

Weird. I'm out of ideas. I guess it's debugging time.
Oíd mortales, el grito sagrado...
Call me "Menes, lord of Cats"
Wing Commander Universe
User avatar
klauss
Elite
Elite
 
Posts: 7243
Topics: 55
Joined: Mon Apr 18, 2005 7:40 am
Location: LS87, Buenos Aires, República Argentina

Postby chuck_starchaser » Tue Apr 08, 2008 7:02 pm

Alright, well, the shader isn't using the shininess from the alpha channel. Could it be that having an alpha channel at all there is hurting things? It doesn't with the Tarsus; but if planets are different from regular units..,

You could try with this modified shader, see if it makes any difference. This one reads shininess from the spec texture's alpha:
Code: Select all
uniform int light_enabled[gl_MaxLights];
uniform int max_light_enabled;
uniform sampler2D diffuseMap;
uniform sampler2D envMap;
uniform sampler2D specMap;
uniform sampler2D glowMap;
uniform sampler2D normalMap;
uniform sampler2D damageMap;
uniform sampler2D detail0Map;
uniform sampler2D detail1Map;
uniform vec4 cloaking;
uniform vec4 damage;
uniform vec4 envColor;

vec3 matmul(vec3 tangent, vec3 binormal, vec3 normal,vec3 lightVec) {
  return vec3(dot(lightVec,tangent),dot(lightVec,binormal),dot(lightVec,normal));
}
vec3 imatmul(vec3 tangent, vec3 binormal, vec3 normal,vec3 lightVec) {
  return lightVec.xxx*tangent+lightVec.yyy*binormal+lightVec.zzz*normal;
}

vec2 EnvMapGen(vec3 f) {
   float fzp1=f.z+1.0;
   float m=2.0*sqrt(f.x*f.x+f.y*f.y+(fzp1)*(fzp1));
   return vec2(f.x/m+.5,f.y/m+.5);
}

float bias(float f){ return f*0.5+0.5; }
vec2  bias(vec2 f) { return f*0.5+vec2(0.5); }
vec3  bias(vec3 f) { return f*0.5+vec3(0.5); }
vec4  bias(vec4 f) { return f*0.5+vec4(0.5); }

float expand(float f){ return f*2.0-1.0; }
vec2  expand(vec2 f) { return f*2.0-vec2(1.0); }
vec3  expand(vec3 f) { return f*2.0-vec3(1.0); }
vec4  expand(vec4 f) { return f*2.0-vec4(1.0); }

float lerp(float f, float a, float b){return (1.0-f)*a+f*b; }
vec2  lerp(float f, vec2 a, vec2 b) { return (1.0-f)*a+f*b; }
vec3  lerp(float f, vec3 a, vec3 b) { return (1.0-f)*a+f*b; }
vec4  lerp(float f, vec4 a, vec4 b) { return (1.0-f)*a+f*b; }

float shininessMap(float shininess, vec4 specmap) { return clamp(specmap.a*shininess,1.0,255.0); } // alpha-based shininess modulation

//float shininessMap(float shininess, vec4 specmap) // luma-based shininess modulation
{
  float3 temp = specmap.rgb;
  temp *= specmap.rgb;
  temp *= specmap.rgb;
  temp.b = (temp.r+temp.g)*0.75;
  return clamp( temp.b*shininess, 1.0, 255.0 );
}

float shininess2Lod(float shininess) { return max(0.0,7.0-log2(shininess+1.0))+3.0*(1.0+envColor.a); }

float limited_shininessMap(float shininess, float specmap)
{
  float limit = 50; //50^2 is 2500. 2500*0.001 = 2.5 --enough risk of saturation!
  float shine = shininessMap(shininess,specmap);
  return (shine*limit)/(shine+limit);
}

float shininess_to_brightness(float shininess)
{
  return 0.001 * shininess * shininess;
}

float lightspot_brightness( float shininess, float specmap )
{
  return limited_shininessMap( shininess, specmap ) * shininess_to_brightness( shininess );
}

void lightingLight(
   in vec3 light, in vec3 normal, in vec3 vnormal, in vec3 eye, in vec3 reflection,
   in vec4 lightDiffuse, in float lightAtt,
   in vec4 diffusemap, in vec4 specmap, in float shininess,
   in vec4 ambientProduct,
   inout vec3 diffuse, inout vec3 specular)
{
   float VNdotLx4= clamp( 4.0 * dot(vnormal,light), 0.0, 1.0 ); // <-***** modified
   float NdotL = clamp( dot(normal,light), -1.0, VNdotLx4 ); // <-***** modified
   float RdotL = clamp( dot(reflection,light), 0.0, VNdotLx4 ); // <-***** modified
   float s = 1.0 - (NdotL*NdotL); //soft penumbra stuff
   //float selfshadow = selfshadowStep(VNdotL); // <-***** removed
   float temp = clamp( NdotL - (0.94 * s * s * s * s * NdotL) + 0.005, 0.0, 1.01 ); //soft penumbra stuff
   specular += ( pow( RdotL, lightspot_brightness(shininess,specmap)) * lightDiffuse.rgb * lightAtt ); // <-***** modified
   diffuse  += ( temp * lightDiffuse.rgb * lightAtt );
}

#define lighting(name, lightno_gl, lightno_tex) \
void name( \
   in vec3 normal, in vec3 vnormal, in vec3 eye, in  vec3 reflection, \
   in vec4 diffusemap, in vec4 specmap, \
   inout vec3 diffuse, inout vec3 specular) \
{ \
   lightingLight( \
      normalize(gl_TexCoord[lightno_tex].xyz), normal, vnormal, eye, reflection, \
      gl_FrontLightProduct[lightno_gl].diffuse, \
      gl_TexCoord[lightno_tex].w, \
      diffusemap, specmap, gl_FrontMaterial.shininess, \
      gl_FrontLightProduct[lightno_gl].ambient, \
      diffuse, specular); \
}

lighting(lighting0, 0, 5)
lighting(lighting1, 1, 6)

vec3 lightingClose(in vec3 diffuse, in vec3 specular, in vec3 ambient, in vec4 diffusemap, in vec4 specmap)
{
   return (diffuse + ambient) * diffusemap.rgb + specular * specmap.rgb;
}

vec3 envMapping(in vec3 reflection, in float gloss, in vec4 specmap)
{
   float envLod = shininess2Lod(gloss);//shininessMap(shininess,specmap));
   return texture2DLod(envMap, EnvMapGen(reflection), envLod).rgb * specmap.rgb * vec3(2.0);
}

void main()
{
  // Retrieve normals
  vec3 iNormal=gl_TexCoord[1].xyz;
  vec3 iTangent=gl_TexCoord[2].xyz;
  vec3 iBinormal=gl_TexCoord[3].xyz;
  vec3 vnormal=iNormal;
  //vec3 normal=normalize(imatmul(iTangent,iBinormal,iNormal,expand(texture2D(normalMap,gl_TexCoord[0].xy).yxz)*vec3(-1.0,1.0,1.0)));
  vec3 normal=normalize(imatmul(iTangent,iBinormal,iNormal,expand(texture2D(normalMap,gl_TexCoord[0].xy).wyz)));
 
  // Other vectors
  vec3 eye = gl_TexCoord[4].xyz;
  vec3 reflection = -reflect(eye,normal);
 
  // Init lighting accumulators
  vec3 diffuse = vec3(0.0);
  vec3 specular= vec3(0.0);
  vec3 ambient = vec3(0.0);
 
  // Sample textures
  vec4 damagecolor = texture2D(damageMap , gl_TexCoord[0].xy);
  vec4 diffusecolor= texture2D(diffuseMap, gl_TexCoord[0].xy);
  vec4 speccolor   = texture2D(specMap   , gl_TexCoord[0].xy);
  vec4 glowcolor   = texture2D(glowMap   , gl_TexCoord[0].xy);
  //sanity enforcement:
  float temp = 1.0 - max( diffusecolor.r, max( diffusecolor.g, diffusecolor.b ) );
  speccolor.r = min( speccolor.r, temp );
  speccolor.g = min( speccolor.g, temp );
  speccolor.b = min( speccolor.b, temp );
 
  vec4 diffusemap  = lerp(damage.x, diffusecolor, damagecolor);
  vec4 specmap     = speccolor;
  float specdamage = clamp(1.0 - dot(damagecolor.xyz,vec3(1.0/3.0)) * damage.x * 2.0, 0.0, 1.0);
  specmap.rgb     *= specdamage;
  specmap.a       *= bias(specdamage);
  float gloss      = shininessMap(gl_FrontMaterial.shininess,specmap);
 
  // Do lighting for every active light
  if (light_enabled[0] != 0)
     lighting0(normal, vnormal, eye, reflection, diffusemap, specmap, diffuse, specular);
  if (light_enabled[1] != 0)
     lighting1(normal, vnormal, eye, reflection, diffusemap, specmap, diffuse, specular);

  vec4 result;
  result.rgb  = lightingClose(diffuse, specular, ambient, diffusemap, specmap)
              + glowcolor.rgb
              + envMapping(reflection,gloss,specmap);
  result.a = diffusemap.a;
  result *= cloaking.rrrg;
  gl_FragColor = result;
}
User avatar
chuck_starchaser
Elite
Elite
 
Posts: 8014
Topics: 195
Joined: Thu Sep 04, 2003 9:03 pm
Location: Montreal

Postby chuck_starchaser » Wed Apr 09, 2008 7:19 am

Fresnel added to fragment shader:

Image

The way it works, for now, is, it detects transparency and assumes it represents glass, and so it applies fresnel factor to reflections and 1-fresnel to transparency. I'm not sure it's working correctly yet, but the look of glass is improved, somehow or other, so I'm releasing the shader code as is. Just think of it as a "beta" fragment shader... To try it, go to the /programs folder, make a backup of highshader.fp, and copy/paste the code below:
Code: Select all
uniform int light_enabled[gl_MaxLights];
uniform int max_light_enabled;
uniform sampler2D diffuseMap;
uniform sampler2D envMap;
uniform sampler2D specMap;
uniform sampler2D glowMap;
uniform sampler2D normalMap;
uniform sampler2D damageMap;
uniform sampler2D detail0Map;
uniform sampler2D detail1Map;
uniform vec4 cloaking;
uniform vec4 damage;
uniform vec4 envColor;

vec3 matmul(vec3 tangent, vec3 binormal, vec3 normal,vec3 lightVec) {
  return vec3(dot(lightVec,tangent),dot(lightVec,binormal),dot(lightVec,normal));
}
vec3 imatmul(vec3 tangent, vec3 binormal, vec3 normal,vec3 lightVec) {
  return lightVec.xxx*tangent+lightVec.yyy*binormal+lightVec.zzz*normal;
}

vec2 EnvMapGen(vec3 f) {
   float fzp1=f.z+1.0;
   float m=2.0*sqrt(f.x*f.x+f.y*f.y+(fzp1)*(fzp1));
   return vec2(f.x/m+.5,f.y/m+.5);
}

float bias(float f){ return f*0.5+0.5; }
vec2  bias(vec2 f) { return f*0.5+vec2(0.5); }
vec3  bias(vec3 f) { return f*0.5+vec3(0.5); }
vec4  bias(vec4 f) { return f*0.5+vec4(0.5); }

float expand(float f){ return f*2.0-1.0; }
vec2  expand(vec2 f) { return f*2.0-vec2(1.0); }
vec3  expand(vec3 f) { return f*2.0-vec3(1.0); }
vec4  expand(vec4 f) { return f*2.0-vec4(1.0); }

float lerp(float f, float a, float b){return (1.0-f)*a+f*b; }
vec2  lerp(float f, vec2 a, vec2 b) { return (1.0-f)*a+f*b; }
vec3  lerp(float f, vec3 a, vec3 b) { return (1.0-f)*a+f*b; }
vec4  lerp(float f, vec4 a, vec4 b) { return (1.0-f)*a+f*b; }

//float shininessMap(float shininess, vec4 specmap) { return clamp(specmap.a*shininess,1.0,255.0); } // alpha-based shininess modulation

float shininessMap(float shininess, vec4 specmap) // luma-based shininess modulation
{
  float3 temp = specmap.rgb;
  temp *= specmap.rgb;
  temp *= specmap.rgb;
  temp.b = (temp.r+temp.g)*0.75;
  return clamp( temp.b*shininess, 1.0, 255.0 );
}

float shininess2Lod(float shininess) { return max(0.0,7.0-log2(shininess+1.0))+3.0*(1.0+envColor.a); }

float limited_shininessMap(float shininess, float specmap)
{
  float limit = 50; //50^2 is 2500. 2500*0.001 = 2.5 --enough risk of saturation!
  float shine = shininessMap(shininess,specmap);
  return (shine*limit)/(shine+limit);
}

float shininess_to_brightness(float shininess)
{
  return 0.001 * shininess * shininess;
}

float lightspot_brightness( float shininess, float specmap )
{
  return limited_shininessMap( shininess, specmap ) * shininess_to_brightness( shininess );
}

void lightingLight(
   in vec3 light, in vec3 normal, in vec3 vnormal, in vec3 eye, in vec3 reflection,
   in vec4 lightDiffuse, in float lightAtt,
   in vec4 diffusemap, in vec4 specmap, in float shininess,
   in vec4 ambientProduct,
   inout vec3 diffuse, inout vec3 specular)
{
   float VNdotLx4= clamp( 4.0 * dot(vnormal,light), 0.0, 1.0 ); // <-***** modified
   float NdotL = clamp( dot(normal,light), -1.0, VNdotLx4 ); // <-***** modified
   float RdotL = clamp( dot(reflection,light), 0.0, VNdotLx4 ); // <-***** modified
   float s = 1.0 - (NdotL*NdotL); //soft penumbra stuff
   //float selfshadow = selfshadowStep(VNdotL); // <-***** removed
   float temp = clamp( NdotL - (0.94 * s * s * s * s * NdotL) + 0.005, 0.0, 1.01 ); //soft penumbra stuff
   specular += ( pow( RdotL, lightspot_brightness(shininess,specmap)) * lightDiffuse.rgb * lightAtt ); // <-***** modified
   diffuse  += ( temp * lightDiffuse.rgb * lightAtt );
}

#define lighting(name, lightno_gl, lightno_tex) \
void name( \
   in vec3 normal, in vec3 vnormal, in vec3 eye, in  vec3 reflection, \
   in vec4 diffusemap, in vec4 specmap, \
   inout vec3 diffuse, inout vec3 specular) \
{ \
   lightingLight( \
      normalize(gl_TexCoord[lightno_tex].xyz), normal, vnormal, eye, reflection, \
      gl_FrontLightProduct[lightno_gl].diffuse, \
      gl_TexCoord[lightno_tex].w, \
      diffusemap, specmap, gl_FrontMaterial.shininess, \
      gl_FrontLightProduct[lightno_gl].ambient, \
      diffuse, specular); \
}

lighting(lighting0, 0, 5)
lighting(lighting1, 1, 6)

vec3 lightingClose(in vec3 diffuse, in vec3 specular, in vec3 ambient, in vec4 diffusemap, in vec4 specmap)
{
   return (diffuse + ambient) * diffusemap.rgb + specular * specmap.rgb;
}

vec3 envMapping(in vec3 reflection, in float gloss, in vec4 specmap)
{
   float envLod = shininess2Lod(gloss);//shininessMap(shininess,specmap));
   return texture2DLod(envMap, EnvMapGen(reflection), envLod).rgb * specmap.rgb * vec3(2.0);
}

void main()
{
  // Retrieve normals
  vec3 iNormal=gl_TexCoord[1].xyz;
  vec3 iTangent=gl_TexCoord[2].xyz;
  vec3 iBinormal=gl_TexCoord[3].xyz;
  vec3 vnormal=iNormal;
  //vec3 normal=normalize(imatmul(iTangent,iBinormal,iNormal,expand(texture2D(normalMap,gl_TexCoord[0].xy).yxz)*vec3(-1.0,1.0,1.0)));
  vec3 normal=normalize(imatmul(iTangent,iBinormal,iNormal,expand(texture2D(normalMap,gl_TexCoord[0].xy).wyz)));
 
  // Other vectors
  vec3 eye = gl_TexCoord[4].xyz;
  vec3 reflection = -reflect(eye,normal);
  float VdotN = dot( eye, normal );
 
  // Init lighting accumulators
  vec3 diffuse = vec3(0.0);
  vec3 specular= vec3(0.0);
  vec3 ambient = vec3(0.0);
 
  // Sample textures
  vec4 damagecolor = texture2D(damageMap , gl_TexCoord[0].xy);
  vec4 diffusecolor= texture2D(diffuseMap, gl_TexCoord[0].xy);
  vec4 speccolor   = texture2D(specMap   , gl_TexCoord[0].xy);
  vec4 glowcolor   = texture2D(glowMap   , gl_TexCoord[0].xy);
 
  //sanity enforcement:
  float temp = 1.0 - max( diffusecolor.r, max( diffusecolor.g, diffusecolor.b ) );
  speccolor.r = min( speccolor.r, temp );
  speccolor.g = min( speccolor.g, temp );
  speccolor.b = min( speccolor.b, temp );
 
    //Fresnel:
  float is_transparent = diffusecolor.a;
  float tempf = 1.0 - VdotN; //or, 1 - cosine_of_view_to_normal_angle;
  is_transparent *= is_transparent;
  tempf *= tempf;
  is_transparent *= is_transparent;
  fresnel_reflection_factor = 0.0625 + 0.9375 * tempf;
  is_transparent = 1.0 - is_transparent;
  fresnel_reflection_factor *= is_transparent;
  fresnel_transparency_factor = 1.0 - fresnel_reflection_factor;
 
  vec4 diffusemap  = lerp(damage.x, diffusecolor, damagecolor);
  vec4 specmap     = speccolor;
  float specdamage = clamp(1.0 - dot(damagecolor.xyz,vec3(1.0/3.0)) * damage.x * 2.0, 0.0, 1.0);
  specmap.rgb     *= specdamage;
  specmap.a       *= bias(specdamage);
  float gloss      = shininessMap(gl_FrontMaterial.shininess,specmap);
 
  // Do lighting for every active light
  if (light_enabled[0] != 0)
     lighting0(normal, vnormal, eye, reflection, diffusemap, specmap, diffuse, specular);
  if (light_enabled[1] != 0)
     lighting1(normal, vnormal, eye, reflection, diffusemap, specmap, diffuse, specular);

  vec4 result;
  result.rgb  = lightingClose(diffuse, specular, ambient, diffusemap, specmap)
              + glowcolor.rgb
              + envMapping(reflection,gloss,specmap);
  //result.a = diffusemap.a;
  result.a = fresnel_transparency_factor;
  result *= cloaking.rrrg;
  gl_FragColor = result;
}
User avatar
chuck_starchaser
Elite
Elite
 
Posts: 8014
Topics: 195
Joined: Thu Sep 04, 2003 9:03 pm
Location: Montreal

Postby safemode » Wed Apr 09, 2008 7:43 am

there's no sense of thickness with the glass. Is there a way to opaquify the transparency increasingly near the edges of areas that curve.

otherwise it looks cool.
Ed Sweetman endorses this message.
safemode
Developer
Developer
 
Posts: 2150
Topics: 84
Joined: Sun Apr 22, 2007 6:17 pm
Location: Pennsylvania

Postby chuck_starchaser » Wed Apr 09, 2008 8:25 am

Well, fresnel does that very opaquification at shallow angles; but not so much taking into account the thickness of the glass as the fact that dielectrics let less light pass through --but reflect more-- at such angles. I guess thickness of the glass would not be hard to add, though it would play a minor role in the total opaquification.

The real problem right now is that glsl is not working. In debugging, I finally overrode the whole fresnel code and everything, and made every material almost perfectly trasparent by ending the glsl code with...
Code: Select all
.............
  result.a = 0.1; //clamp( alpha, fresnel_alpha, 1.0 );
  result *= cloaking.rrrg;
  gl_FragColor = result;
}
...and yet everything looks normal! How is it possible?!?!?!


Meanwhile, I did find some bugs. Here's my current fresnel code, though it's NOT working, since writing to the alpha channel of the result seems to have no effect.... :-/
Code: Select all
    //Fresnel:
  float alpha = diffusecolor.a;
  float fresnel_alpha = 1.0 - clamp( dot( eye, normal ), 0.0, 1.0 );
  alpha *= alpha;
  fresnel_alpha *= fresnel_alpha;
  alpha *= alpha;
  fresnel_alpha = 0.0625 + ( 0.9375 * fresnel_alpha );

  vec4 diffusemap  = lerp(damage.x, diffusecolor, damagecolor);
  vec4 specmap     = speccolor;
  float specdamage = clamp(1.0 - dot(damagecolor.xyz,vec3(1.0/3.0)) * damage.x * 2.0, 0.0, 1.0);
  specmap.rgb     *= specdamage;
  specmap.a       *= bias(specdamage);
  float gloss      = shininessMap(gl_FrontMaterial.shininess,specmap);
 
  // Do lighting for every active light
  if (light_enabled[0] != 0)
     lighting0(normal, vnormal, eye, reflection, diffusemap, specmap, diffuse, specular);
  if (light_enabled[1] != 0)
     lighting1(normal, vnormal, eye, reflection, diffusemap, specmap, diffuse, specular);

  vec4 result;
  result.rgb  = lightingClose(diffuse, specular, ambient, diffusemap, specmap)
              + glowcolor.rgb
              + envMapping(reflection,gloss,specmap);
  //result.a = diffusemap.a;
  result.a = clamp( alpha, fresnel_alpha, 1.0 );
  result *= cloaking.rrrg;
  gl_FragColor = result;
}
User avatar
chuck_starchaser
Elite
Elite
 
Posts: 8014
Topics: 195
Joined: Thu Sep 04, 2003 9:03 pm
Location: Montreal

Postby chuck_starchaser » Wed Apr 09, 2008 10:54 am

I would have been catmeat if Klauss hadn't been online...
Problems fixed:

Image

Code: Select all
uniform int light_enabled[gl_MaxLights];
uniform int max_light_enabled;
uniform sampler2D diffuseMap;
uniform sampler2D envMap;
uniform sampler2D specMap;
uniform sampler2D glowMap;
uniform sampler2D normalMap;
uniform sampler2D damageMap;
uniform sampler2D detail0Map;
uniform sampler2D detail1Map;
uniform vec4 cloaking;
uniform vec4 damage;
uniform vec4 envColor;

vec3 matmul(vec3 tangent, vec3 binormal, vec3 normal,vec3 lightVec) {
  return vec3(dot(lightVec,tangent),dot(lightVec,binormal),dot(lightVec,normal));
}
vec3 imatmul(vec3 tangent, vec3 binormal, vec3 normal,vec3 lightVec) {
  return lightVec.xxx*tangent+lightVec.yyy*binormal+lightVec.zzz*normal;
}

vec2 EnvMapGen(vec3 f) {
   float fzp1=f.z+1.0;
   float m=2.0*sqrt(f.x*f.x+f.y*f.y+(fzp1)*(fzp1));
   return vec2(f.x/m+.5,f.y/m+.5);
}

float bias(float f){ return f*0.5+0.5; }
vec2  bias(vec2 f) { return f*0.5+vec2(0.5); }
vec3  bias(vec3 f) { return f*0.5+vec3(0.5); }
vec4  bias(vec4 f) { return f*0.5+vec4(0.5); }

float expand(float f){ return f*2.0-1.0; }
vec2  expand(vec2 f) { return f*2.0-vec2(1.0); }
vec3  expand(vec3 f) { return f*2.0-vec3(1.0); }
vec4  expand(vec4 f) { return f*2.0-vec4(1.0); }

float lerp(float f, float a, float b){return (1.0-f)*a+f*b; }
vec2  lerp(float f, vec2 a, vec2 b) { return (1.0-f)*a+f*b; }
vec3  lerp(float f, vec3 a, vec3 b) { return (1.0-f)*a+f*b; }
vec4  lerp(float f, vec4 a, vec4 b) { return (1.0-f)*a+f*b; }

//float shininessMap(float shininess, vec4 specmap) { return clamp(specmap.a*shininess,1.0,255.0); } // alpha-based shininess modulation

float shininessMap(float shininess, vec4 specmap) // luma-based shininess modulation
{
  float3 temp = specmap.rgb;
  temp *= specmap.rgb;
  temp *= specmap.rgb;
  temp.b = (temp.r+temp.g)*0.75;
  return clamp( temp.b*shininess, 1.0, 255.0 );
}

float shininess2Lod(float shininess) { return max(0.0,7.0-log2(shininess+1.0))+3.0*(1.0+envColor.a); }

float limited_shininessMap(float shininess, float specmap)
{
  float limit = 50; //50^2 is 2500. 2500*0.001 = 2.5 --enough risk of saturation!
  float shine = shininessMap(shininess,specmap);
  return (shine*limit)/(shine+limit);
}

float shininess_to_brightness(float shininess)
{
  return 0.001 * shininess * shininess;
}

float lightspot_brightness( float shininess, float specmap )
{
  return limited_shininessMap( shininess, specmap ) * shininess_to_brightness( shininess );
}

void lightingLight(
   in vec3 light, in vec3 normal, in vec3 vnormal, in vec3 eye, in vec3 reflection,
   in vec4 lightDiffuse, in float lightAtt,
   in vec4 diffusemap, in vec4 specmap, in float shininess,
   in vec4 ambientProduct,
   inout vec3 diffuse, inout vec3 specular)
{
   float VNdotLx4= clamp( 4.0 * dot(vnormal,light), 0.0, 1.0 ); // <-***** modified
   float NdotL = clamp( dot(normal,light), -1.0, VNdotLx4 ); // <-***** modified
   float RdotL = clamp( dot(reflection,light), 0.0, VNdotLx4 ); // <-***** modified
   float s = 1.0 - (NdotL*NdotL); //soft penumbra stuff
   //float selfshadow = selfshadowStep(VNdotL); // <-***** removed
   float temp = clamp( NdotL - (0.94 * s * s * s * s * NdotL) + 0.005, 0.0, 1.01 ); //soft penumbra stuff
   specular += ( pow( RdotL, lightspot_brightness(shininess,specmap)) * lightDiffuse.rgb * lightAtt ); // <-***** modified
   diffuse  += ( temp * lightDiffuse.rgb * lightAtt );
}

#define lighting(name, lightno_gl, lightno_tex) \
void name( \
   in vec3 normal, in vec3 vnormal, in vec3 eye, in  vec3 reflection, \
   in vec4 diffusemap, in vec4 specmap, \
   inout vec3 diffuse, inout vec3 specular) \
{ \
   lightingLight( \
      normalize(gl_TexCoord[lightno_tex].xyz), normal, vnormal, eye, reflection, \
      gl_FrontLightProduct[lightno_gl].diffuse, \
      gl_TexCoord[lightno_tex].w, \
      diffusemap, specmap, gl_FrontMaterial.shininess, \
      gl_FrontLightProduct[lightno_gl].ambient, \
      diffuse, specular); \
}

lighting(lighting0, 0, 5)
lighting(lighting1, 1, 6)

vec3 lightingClose(in vec3 diffuse, in vec3 specular, in vec3 ambient, in vec4 diffusemap, in vec4 specmap)
{
   return (diffuse + ambient) * diffusemap.rgb + specular * specmap.rgb;
}

vec3 envMapping(in vec3 reflection, in float gloss, in vec4 specmap)
{
   float envLod = shininess2Lod(gloss);//shininessMap(shininess,specmap));
   return texture2DLod(envMap, EnvMapGen(reflection), envLod).rgb * specmap.rgb * vec3(2.0);
}

void main()
{
  // Retrieve normals
  vec3 iNormal=gl_TexCoord[1].xyz;
  vec3 iTangent=gl_TexCoord[2].xyz;
  vec3 iBinormal=gl_TexCoord[3].xyz;
  vec3 vnormal=iNormal;
  //vec3 normal=normalize(imatmul(iTangent,iBinormal,iNormal,expand(texture2D(normalMap,gl_TexCoord[0].xy).yxz)*vec3(-1.0,1.0,1.0)));
  vec3 normal=normalize(imatmul(iTangent,iBinormal,iNormal,expand(texture2D(normalMap,gl_TexCoord[0].xy).wyz)));
 
  // Other vectors
  vec3 eye = gl_TexCoord[4].xyz;
  vec3 reflection = -reflect(eye,normal);
 
  // Init lighting accumulators
  vec3 diffuse = vec3(0.0);
  vec3 specular= vec3(0.0);
  vec3 ambient = vec3(0.0);
 
  // Sample textures
  vec4 damagecolor = texture2D(damageMap , gl_TexCoord[0].xy);
  vec4 diffusecolor= texture2D(diffuseMap, gl_TexCoord[0].xy);
  vec4 speccolor   = texture2D(specMap   , gl_TexCoord[0].xy);
  vec4 glowcolor   = texture2D(glowMap   , gl_TexCoord[0].xy);
 
  //sanity enforcement:
  float temp = 1.0 - max( diffusecolor.r, max( diffusecolor.g, diffusecolor.b ) );
  speccolor.r = min( speccolor.r, temp );
  speccolor.g = min( speccolor.g, temp );
  speccolor.b = min( speccolor.b, temp );
 
  //Fresnel:
  float alpha = diffusecolor.a * gl_FrontMaterial.diffuse.a;
  float fresnel_alpha = 1.0 - clamp( dot( eye, normal ), 0.0, 1.0 );
  alpha *= alpha;
  fresnel_alpha *= fresnel_alpha;
  alpha *= alpha;
  fresnel_alpha = 0.0625 + ( 0.9375 * fresnel_alpha );

  vec4 diffusemap  = lerp(damage.x, diffusecolor, damagecolor);
  vec4 specmap     = speccolor;
  float specdamage = clamp(1.0 - dot(damagecolor.xyz,vec3(1.0/3.0)) * damage.x * 2.0, 0.0, 1.0);
  specmap.rgb     *= specdamage;
  specmap.a       *= bias(specdamage);
  float gloss      = shininessMap(gl_FrontMaterial.shininess,specmap);
 
  // Do lighting for every active light
  if (light_enabled[0] != 0)
     lighting0(normal, vnormal, eye, reflection, diffusemap, specmap, diffuse, specular);
  if (light_enabled[1] != 0)
     lighting1(normal, vnormal, eye, reflection, diffusemap, specmap, diffuse, specular);

  vec4 result;
  result.rgb  = lightingClose(diffuse, specular, ambient, diffusemap, specmap)
              + glowcolor.rgb
              + envMapping(reflection,gloss,specmap);
  //result.a = diffusemap.a;
  result.rgb *= clamp( alpha, fresnel_alpha, 1.0 );
  result.a *= sqrt( clamp( alpha, fresnel_alpha, 1.0 ) );
  result *= cloaking.rrrg;
  gl_FragColor = result;
}

But one has to change the xmesh to give a low alpha value to the diffuse window material.

EDIT:
What makes it much better is ONE INVSRCALPHA in xmesh:

Image

This adds some cost on the CPU side, Klauss was saying, because then the meshes have to be sorted; but the engine is gpu-bound, so I don't think this is much of an issue. I may be wrong.

So, to sum up:
To try this shader, you need to paste it into highshader.fp, and then use mesher to convert meshes for windows to xmesh, edit the xmesh to have diffuse alpha = 0.1 and preferably blend mode ONE INVSRCALPHA. Example for MiningBase.xmesh material:
Code: Select all
<Mesh scale="1.000000" reverse="0" forcetexture="0" sharevert="0" polygonoffset="0.000000" blend="ONE INVSRCALPHA"  texture="blank.png" >
<Material power="100.000000" cullface="1" reflect="1" lighting="1" usenormals="1">
   <Ambient Red="0.300000" Green="0.300000" Blue="0.300000" Alpha="0.000000"/>
   <Diffuse Red="1.000000" Green="1.000000" Blue="1.000000" Alpha="0.100000"/>
   <Emissive Red="0.000000" Green="0.000000" Blue="0.000000" Alpha="1.000000"/>
   <Specular Red="1.000000" Green="1.000000" Blue="1.000000" Alpha="1.000000"/>
</Material>

For your convenience, I'm uploading the modified MiningBase.bfxm; just throw it into /units/MiningBase/
http://deeplayer.com/pu/lagrande/shader ... gBase.bfxm

EDIT2:
Modified the code above to include glass thickness effects (just for you, safemode; because you're a nice guy... ;-)).

Image

Well, the glass thickness effect is not working too well yet; gonna play with it some more tonight. Problem is, where do we specify the "tint"? Should be the diffuse color, but I don't know what the diffuse color is, or even where it comes from. Says "texture = blank.png"... My mind blanks at that...

Now, I wish increasing the number of polies in these bubbles was as easy...
Gotta do something about poor old Serenity...

EDIT3:
Changed the code above again; small bug...

Image

Now those glass things finally look like glass...

Image

Problem now is the spheremaps: small, blurry, pixelated, deformish and dark (requiring the shader to double the gain on env mapping). With spheremaps so blurry, glass will always look frosty.
We need to get cubemaps working...

EDIT4:
No, there's another problem: The far side of the glass seems to be reflecting as well, like it's a two-sided material. Well, this is good and bad. It's good in the sense of transparency. It is bad in terms of reflections.
Why? Don't both sides of a piece of glass reflect?
Technically, yes, BUT, in our case, the far side of the glass is reflecting through the bloody station. We ain't got specular occlusion. The simplest solution would be to make the material one-sided; but then we lose the transparency benefits of a two-sided material. What to do?
User avatar
chuck_starchaser
Elite
Elite
 
Posts: 8014
Topics: 195
Joined: Thu Sep 04, 2003 9:03 pm
Location: Montreal

Postby pyramid » Wed Apr 09, 2008 3:13 pm

I have copied the code to default.fp instead of highend.fp
Now it looks much better with the self shadowing enabled and with city lights. :-)
The specular spot is a bit too sharp for a planet, but not to the point of becoming disturbing.
However the ocean is too bright on the night side and too reddish already far from the day/night border (it starts where you begin seeing the lights on the left side of the planet). This is not influenced by the city lights, i.e. removing them doesn't change the ocean coloring neither does exchanging spec map for speconly.
Haven't played too much with the system lighting, so not sure what its influence might be.
In any case, the planet already looks much more vivid than with the original shader.
Image
User avatar
pyramid
Expert Mercenary
Expert Mercenary
 
Posts: 960
Topics: 44
Joined: Wed Jun 14, 2006 6:02 pm
Location: Somewhere in the vastness of space

Postby safemode » Wed Apr 09, 2008 3:55 pm

well, the ocean looks like it's made of plastic, and without an atmosphere, it's hard to tell what the shader will do with the hazing effect it has on what's beneath it.


from pictures of earth from space (real ones, not doctored or rendered or post-processed) I've seen all over google, oceans just tend to get somewhat brighter when facing towards the sun, but even so, there are dark patches where it's deep, and light patches where it's really shallow. Tone down the specular for oceans like a whole lot.
Ed Sweetman endorses this message.
safemode
Developer
Developer
 
Posts: 2150
Topics: 84
Joined: Sun Apr 22, 2007 6:17 pm
Location: Pennsylvania

Postby klauss » Wed Apr 09, 2008 4:03 pm

The specular spot is alright, it only needs fresnel effects. (ie, when looked at from that angle, it should be a lot less bright, but sharpness is ok - believe me, I've studied satellite photos until I dreamed with them).

And chuck, those domes still lack some of the absorption effects you were aiming at by changing the blending mode. Perhaps alpha drops too low. The more tangential the eye vector is to the surface (ie, the more perpendicular to the normal, or the lower the cos(eye, normal) ), the more opaque (higher alpha) the dome should be. It should visibly darken or tint what's inside the dome. Use the diffuse color as tint, and multiply the diffuse part (and not the reflection part) by the alpha.
Oíd mortales, el grito sagrado...
Call me "Menes, lord of Cats"
Wing Commander Universe
User avatar
klauss
Elite
Elite
 
Posts: 7243
Topics: 55
Joined: Mon Apr 18, 2005 7:40 am
Location: LS87, Buenos Aires, República Argentina

Postby chuck_starchaser » Wed Apr 09, 2008 4:31 pm

@Pyramid:
As Klauss says, the size of the light spot is pretty much exactly right; but as he says as well, it needs fresnel. Maybe I could enable fresnel globally for planets, but I'm not sure where the planet mesh is. If anyone knows, the thing to do is change the diffuse material's alpha to 0.1. The blending is ONE ZERO, I imagine, so the change shouldn't make planets transparent; but my shader will see that 0.1 alpha and will think it's glass, and apply fresnel.
Actually, I need to change the shader so that only reflections are affected. It will take minutes....

The other problem, the bigger one: Oceans are red because there's red ambient light there. Somebody poured buckets of ambient red light into that system. Now, my shader ignores ambient light, so I'm not sure how it's getting there; but it's there, somehow. Maybe, again, if someone knows where the planet mesh is, changing ambient light to 0, 0, 0, 1 might do the trick. If not, you can edit the system and get rid of the damned ambient light, or put it down to a more reasonable 0.0625, 0, 0; --not the typical craziness one sees around like 0.2 or 0.3.

@Klauss:
Yeah, I know; that's why I said it was "sort of working". I'm not sure why the glass doesn't seem to be darkening stuff you see through. It's as if the blending mode were still ONE ONE. I'll experiment a bit. I checked the texture for the glass and it's black, so it should darken.

EDIT:
DAMN! Maybe it's NOT ambient light, but environment mapping. The whole sky in that system is red, and the water is reflecting it.
The shader works! :D
Try it in a system with a less crazy background.
What I see I need to do to that noodle is to lower specularity for the ocean. Problem with that is that shininess will go down drastically, and the spot will get a lot bigger; but that's a lesser evil.
Pyramid, for now, just darken the whole specular texture by 25% or so.
User avatar
chuck_starchaser
Elite
Elite
 
Posts: 8014
Topics: 195
Joined: Thu Sep 04, 2003 9:03 pm
Location: Montreal

Postby chuck_starchaser » Wed Apr 09, 2008 5:16 pm

Alright, here it is; this shader's fresnel only modulates specular spots and environment mapping by the fresnel factor:
Code: Select all
uniform int light_enabled[gl_MaxLights];
uniform int max_light_enabled;
uniform sampler2D diffuseMap;
uniform sampler2D envMap;
uniform sampler2D specMap;
uniform sampler2D glowMap;
uniform sampler2D normalMap;
uniform sampler2D damageMap;
uniform sampler2D detail0Map;
uniform sampler2D detail1Map;
uniform vec4 cloaking;
uniform vec4 damage;
uniform vec4 envColor;

vec3 matmul(vec3 tangent, vec3 binormal, vec3 normal,vec3 lightVec) {
  return vec3(dot(lightVec,tangent),dot(lightVec,binormal),dot(lightVec,normal));
}
vec3 imatmul(vec3 tangent, vec3 binormal, vec3 normal,vec3 lightVec) {
  return lightVec.xxx*tangent+lightVec.yyy*binormal+lightVec.zzz*normal;
}

vec2 EnvMapGen(vec3 f) {
   float fzp1=f.z+1.0;
   float m=2.0*sqrt(f.x*f.x+f.y*f.y+(fzp1)*(fzp1));
   return vec2(f.x/m+.5,f.y/m+.5);
}

float bias(float f){ return f*0.5+0.5; }
vec2  bias(vec2 f) { return f*0.5+vec2(0.5); }
vec3  bias(vec3 f) { return f*0.5+vec3(0.5); }
vec4  bias(vec4 f) { return f*0.5+vec4(0.5); }

float expand(float f){ return f*2.0-1.0; }
vec2  expand(vec2 f) { return f*2.0-vec2(1.0); }
vec3  expand(vec3 f) { return f*2.0-vec3(1.0); }
vec4  expand(vec4 f) { return f*2.0-vec4(1.0); }

float lerp(float f, float a, float b){return (1.0-f)*a+f*b; }
vec2  lerp(float f, vec2 a, vec2 b) { return (1.0-f)*a+f*b; }
vec3  lerp(float f, vec3 a, vec3 b) { return (1.0-f)*a+f*b; }
vec4  lerp(float f, vec4 a, vec4 b) { return (1.0-f)*a+f*b; }

//float shininessMap(float shininess, vec4 specmap) { return clamp(specmap.a*shininess,1.0,255.0); } // alpha-based shininess modulation

float shininessMap(float shininess, vec4 specmap) // luma-based shininess modulation
{
  float3 temp = specmap.rgb;
  temp *= specmap.rgb;
  temp *= specmap.rgb;
  temp.b = (temp.r+temp.g)*0.75;
  return clamp( temp.b*shininess, 1.0, 255.0 );
}

float shininess2Lod(float shininess) { return max(0.0,7.0-log2(shininess+1.0))+3.0*(1.0+envColor.a); }

float limited_shininessMap(float shininess, float specmap)
{
  float limit = 50; //50^2 is 2500. 2500*0.001 = 2.5 --enough risk of saturation!
  float shine = shininessMap(shininess,specmap);
  return (shine*limit)/(shine+limit);
}

float shininess_to_brightness(float shininess)
{
  return 0.001 * shininess * shininess;
}

float lightspot_brightness( float shininess, float specmap )
{
  return limited_shininessMap( shininess, specmap ) * shininess_to_brightness( shininess );
}

void lightingLight(
   in vec3 light, in vec3 normal, in vec3 vnormal, in vec3 eye, in vec3 reflection,
   in vec4 lightDiffuse, in float lightAtt,
   in vec4 diffusemap, in vec4 specmap, in float shininess,
   in vec4 ambientProduct,
   inout vec3 diffuse, inout vec3 specular)
{
   float VNdotLx4= clamp( 4.0 * dot(vnormal,light), 0.0, 1.0 ); // <-***** modified
   float NdotL = clamp( dot(normal,light), -1.0, VNdotLx4 ); // <-***** modified
   float RdotL = clamp( dot(reflection,light), 0.0, VNdotLx4 ); // <-***** modified
   float s = 1.0 - (NdotL*NdotL); //soft penumbra stuff
   //float selfshadow = selfshadowStep(VNdotL); // <-***** removed
   float temp = clamp( NdotL - (0.94 * s * s * s * s * NdotL) + 0.005, 0.0, 1.01 ); //soft penumbra stuff
   specular += ( pow( RdotL, lightspot_brightness(shininess,specmap)) * lightDiffuse.rgb * lightAtt ); // <-***** modified
   diffuse  += ( temp * lightDiffuse.rgb * lightAtt );
}

#define lighting(name, lightno_gl, lightno_tex) \
void name( \
   in vec3 normal, in vec3 vnormal, in vec3 eye, in  vec3 reflection, \
   in vec4 diffusemap, in vec4 specmap, \
   inout vec3 diffuse, inout vec3 specular) \
{ \
   lightingLight( \
      normalize(gl_TexCoord[lightno_tex].xyz), normal, vnormal, eye, reflection, \
      gl_FrontLightProduct[lightno_gl].diffuse, \
      gl_TexCoord[lightno_tex].w, \
      diffusemap, specmap, gl_FrontMaterial.shininess, \
      gl_FrontLightProduct[lightno_gl].ambient, \
      diffuse, specular); \
}

lighting(lighting0, 0, 5)
lighting(lighting1, 1, 6)

vec3 lightingClose(in vec3 diffuse, in vec3 specular, in vec3 ambient, in vec4 diffusemap, in vec4 specmap)
{
   return (diffuse + ambient) * diffusemap.rgb + specular * specmap.rgb;
}

vec3 envMapping(in vec3 reflection, in float gloss, in vec4 specmap)
{
   float envLod = shininess2Lod(gloss);//shininessMap(shininess,specmap));
   return texture2DLod(envMap, EnvMapGen(reflection), envLod).rgb * specmap.rgb * vec3(2.0);
}

void main()
{
  // Retrieve normals
  vec3 iNormal=gl_TexCoord[1].xyz;
  vec3 iTangent=gl_TexCoord[2].xyz;
  vec3 iBinormal=gl_TexCoord[3].xyz;
  vec3 vnormal=iNormal;
  //vec3 normal=normalize(imatmul(iTangent,iBinormal,iNormal,expand(texture2D(normalMap,gl_TexCoord[0].xy).yxz)*vec3(-1.0,1.0,1.0)));
  vec3 normal=normalize(imatmul(iTangent,iBinormal,iNormal,expand(texture2D(normalMap,gl_TexCoord[0].xy).wyz)));
 
  // Other vectors
  vec3 eye = gl_TexCoord[4].xyz;
  vec3 reflection = -reflect(eye,normal);
 
  // Init lighting accumulators
  vec3 diffuse = vec3(0.0);
  vec3 specular= vec3(0.0);
  vec3 ambient = vec3(0.0);
 
  // Sample textures
  vec4 damagecolor = texture2D(damageMap , gl_TexCoord[0].xy);
  vec4 diffusecolor= texture2D(diffuseMap, gl_TexCoord[0].xy);
  vec4 speccolor   = texture2D(specMap   , gl_TexCoord[0].xy);
  vec4 glowcolor   = texture2D(glowMap   , gl_TexCoord[0].xy);
 
  //sanity enforcement:
  float temp = 1.0 - max( diffusecolor.r, max( diffusecolor.g, diffusecolor.b ) );
  speccolor.r = min( speccolor.r, temp );
  speccolor.g = min( speccolor.g, temp );
  speccolor.b = min( speccolor.b, temp );
 
  //Fresnel:
  float alpha = diffusecolor.a * gl_FrontMaterial.diffuse.a;
  float fresnel_alpha = 1.0 - clamp( dot( eye, normal ), 0.0, 1.0 );
  alpha *= alpha;
  fresnel_alpha *= fresnel_alpha;
  alpha *= alpha;

  vec4 diffusemap  = lerp(damage.x, diffusecolor, damagecolor);
  vec4 specmap     = speccolor;
  float specdamage = clamp(1.0 - dot(damagecolor.xyz,vec3(1.0/3.0)) * damage.x * 2.0, 0.0, 1.0);
  specmap.rgb     *= specdamage;
  specmap.a       *= bias(specdamage);
  float gloss      = shininessMap(gl_FrontMaterial.shininess,specmap);
 
  fresnel_alpha = clamp( 0.0625 + ( 0.9375 * fresnel_alpha ), alpha, 1.0 );

  // Do lighting for every active light
  if (light_enabled[0] != 0)
     lighting0(normal, vnormal, eye, reflection, diffusemap, specmap, diffuse, specular);
  if (light_enabled[1] != 0)
     lighting1(normal, vnormal, eye, reflection, diffusemap, specmap, diffuse, specular);

  specular *= fresnel_alpha;
  vec4 result;
  result.rgb  = lightingClose(diffuse, specular, ambient, diffusemap, specmap)
              + glowcolor.rgb
              + (envMapping(reflection,gloss,specmap)*fresnel_alpha);
  result.a *= sqrt(sqrt(fresnel_alpha));
  result *= cloaking.rrrg;
  gl_FragColor = result;
}

Klauss, notice I square rooted fresnel alpha twice before writing it to result.a; and it makes little difference. Hold on...

Here:

Image

If you look near the edge on the right, you see a darkening streak.
So, it HAS the ability to darken, but it just doesn't seem to because there's so much nebuli getting reflected you never get any chance to notice any darkness, is what I think it is. And not just from one side...

A more serious problem is that the darn bubbles are reflecting from both sides. I don't know how. Hellcat doesn't know either. The bubbles' mesh is single-layer. Normals are pretty normal, pointing outwards. The mesh file says cull=1.

I'm not complaining, exactly; the far side being visible helps transparency-wise, I suppose; and glass does reflect from both sides; but the problem is that the inner reflections are going down through the mining base... Wish there was a way to stop just the reflections.
User avatar
chuck_starchaser
Elite
Elite
 
Posts: 8014
Topics: 195
Joined: Thu Sep 04, 2003 9:03 pm
Location: Montreal

Postby klauss » Wed Apr 09, 2008 6:48 pm

No, I think there's still a problem.

Try:

Code: Select all
  result.a *= sqrt(sqrt(fresnel_alpha));
  result.rgb  =
                 sqrt(sqrt(fresnel_alpha)) * lightingClose(diffuse, specular, ambient, diffusemap, specmap)
              + glowcolor.rgb
              + (envMapping(reflection,gloss,specmap)*fresnel_alpha);
Oíd mortales, el grito sagrado...
Call me "Menes, lord of Cats"
Wing Commander Universe
User avatar
klauss
Elite
Elite
 
Posts: 7243
Topics: 55
Joined: Mon Apr 18, 2005 7:40 am
Location: LS87, Buenos Aires, República Argentina

Postby chuck_starchaser » Wed Apr 09, 2008 8:08 pm

klauss wrote:No, I think there's still a problem.

Try:

Code: Select all
  result.a *= sqrt(sqrt(fresnel_alpha));
  result.rgb  =
                 sqrt(sqrt(fresnel_alpha)) * lightingClose(diffuse, specular, ambient, diffusemap, specmap)
              + glowcolor.rgb
              + (envMapping(reflection,gloss,specmap)*fresnel_alpha);


It didn't help. What helped, in the end, was multiplying glowcolor.rgb by alpha.
Somebody must have thought that glass always glows or something.
Now the glass is too dark. I think I need to cut down on the number of square roots...

EDIT:
With fourth root:

Image

With square root:

Image

Root-less:

Image

I think with square root looks best.
User avatar
chuck_starchaser
Elite
Elite
 
Posts: 8014
Topics: 195
Joined: Thu Sep 04, 2003 9:03 pm
Location: Montreal

Postby chuck_starchaser » Thu Apr 10, 2008 5:35 am

I even experimented with cubic root...

Image

...but no matter, any roots or powers I use end up producing strange artifacts, like that darker polygon you see above, on the far side of the bubble's reflections. I've no idea what causes them, but they seem to go away when I don't use any special roots or powers, so, I'm going to leave the final alpha at plain vanilla fresnel_alpha, for now.

The glass looks dark enough to me, though, ever since I multiplied glow by alpha, anyways:

Image

It's hard for me to concentrate on something as subtle as glass thickness effects when so much stuff looks horrible:

1) The polygonality of the bubble... --it needs a level of subdivision or two, really bad...

2) The complete lack of ambient occlusion: Those "buildings" should be painted with a darkening gradient towards the bottom, to fake the shadows of the ring ledge and other buildings.

3) Reflections of sky where the bubble should be reflecting structure... I'm going to make a specular texture for bubbles that darkens towards the rim, so one doesn't get so much reflection where, chances are, they should be reflecting darker, nearby stuff, rather than sky.

4) MOST IMPORTANTLY: The fact that the far side of the bubbles (the inside surface) is reflecting sky (from a direction below the picture), through the goddam station. Klauss, is there a way to stop that?


Here's the current shader code:
Code: Select all
uniform int light_enabled[gl_MaxLights];
uniform int max_light_enabled;
uniform sampler2D diffuseMap;
uniform sampler2D envMap;
uniform sampler2D specMap;
uniform sampler2D glowMap;
uniform sampler2D normalMap;
uniform sampler2D damageMap;
uniform sampler2D detail0Map;
uniform sampler2D detail1Map;
uniform vec4 cloaking;
uniform vec4 damage;
uniform vec4 envColor;

vec3 matmul(vec3 tangent, vec3 binormal, vec3 normal,vec3 lightVec) {
  return vec3(dot(lightVec,tangent),dot(lightVec,binormal),dot(lightVec,normal));
}
vec3 imatmul(vec3 tangent, vec3 binormal, vec3 normal,vec3 lightVec) {
  return lightVec.xxx*tangent+lightVec.yyy*binormal+lightVec.zzz*normal;
}

vec2 EnvMapGen(vec3 f) {
   float fzp1=f.z+1.0;
   float m=2.0*sqrt(f.x*f.x+f.y*f.y+(fzp1)*(fzp1));
   return vec2(f.x/m+.5,f.y/m+.5);
}

float bias(float f){ return f*0.5+0.5; }
vec2  bias(vec2 f) { return f*0.5+vec2(0.5); }
vec3  bias(vec3 f) { return f*0.5+vec3(0.5); }
vec4  bias(vec4 f) { return f*0.5+vec4(0.5); }

float expand(float f){ return f*2.0-1.0; }
vec2  expand(vec2 f) { return f*2.0-vec2(1.0); }
vec3  expand(vec3 f) { return f*2.0-vec3(1.0); }
vec4  expand(vec4 f) { return f*2.0-vec4(1.0); }

float lerp(float f, float a, float b){return (1.0-f)*a+f*b; }
vec2  lerp(float f, vec2 a, vec2 b) { return (1.0-f)*a+f*b; }
vec3  lerp(float f, vec3 a, vec3 b) { return (1.0-f)*a+f*b; }
vec4  lerp(float f, vec4 a, vec4 b) { return (1.0-f)*a+f*b; }

//float shininessMap(float shininess, vec4 specmap) { return clamp(specmap.a*shininess,1.0,255.0); } // alpha-based shininess modulation

float shininessMap(float shininess, vec4 specmap) // luma-based shininess modulation
{
  float3 temp = specmap.rgb;
  temp *= specmap.rgb;
  temp *= specmap.rgb;
  temp.b = (temp.r+temp.g)*0.75;
  return clamp( temp.b*shininess, 1.0, 255.0 );
}

float shininess2Lod(float shininess) { return max(0.0,7.0-log2(shininess+1.0))+3.0*(1.0+envColor.a); }

float limited_shininessMap(float shininess, float specmap)
{
  float limit = 50; //50^2 is 2500. 2500*0.001 = 2.5 --enough risk of saturation!
  float shine = shininessMap(shininess,specmap);
  return (shine*limit)/(shine+limit);
}

float shininess_to_brightness(float shininess)
{
  return 0.001 * shininess * shininess;
}

float lightspot_brightness( float shininess, float specmap )
{
  return limited_shininessMap( shininess, specmap ) * shininess_to_brightness( shininess );
}

void lightingLight(
   in vec3 light, in vec3 normal, in vec3 vnormal, in vec3 eye, in vec3 reflection,
   in vec4 lightDiffuse, in float lightAtt,
   in vec4 diffusemap, in vec4 specmap, in float shininess,
   in vec4 ambientProduct,
   inout vec3 diffuse, inout vec3 specular)
{
   float VNdotLx4= clamp( 4.0 * dot(vnormal,light), 0.0, 1.0 ); // <-***** modified
   float NdotL = clamp( dot(normal,light), -1.0, VNdotLx4 ); // <-***** modified
   float RdotL = clamp( dot(reflection,light), 0.0, VNdotLx4 ); // <-***** modified
   float s = 1.0 - (NdotL*NdotL); //soft penumbra stuff
   //float selfshadow = selfshadowStep(VNdotL); // <-***** removed
   float temp = clamp( NdotL - (0.94 * s * s * s * s * NdotL) + 0.005, 0.0, 1.01 ); //soft penumbra stuff
   specular += ( pow( RdotL, lightspot_brightness(shininess,specmap)) * lightDiffuse.rgb * lightAtt ); // <-***** modified
   diffuse  += ( temp * lightDiffuse.rgb * lightAtt );
}

#define lighting(name, lightno_gl, lightno_tex) \
void name( \
   in vec3 normal, in vec3 vnormal, in vec3 eye, in  vec3 reflection, \
   in vec4 diffusemap, in vec4 specmap, \
   inout vec3 diffuse, inout vec3 specular) \
{ \
   lightingLight( \
      normalize(gl_TexCoord[lightno_tex].xyz), normal, vnormal, eye, reflection, \
      gl_FrontLightProduct[lightno_gl].diffuse, \
      gl_TexCoord[lightno_tex].w, \
      diffusemap, specmap, gl_FrontMaterial.shininess, \
      gl_FrontLightProduct[lightno_gl].ambient, \
      diffuse, specular); \
}

lighting(lighting0, 0, 5)
lighting(lighting1, 1, 6)

vec3 lightingClose(in vec3 diffuse, in vec3 specular, in vec4 diffusemap, in vec4 specmap)
{
   return (diffuse*diffusemap.rgb) + (specular*specmap.rgb);
}

vec3 envMapping(in vec3 reflection, in float gloss, in vec4 specmap)
{
   float envLod = shininess2Lod(gloss);//shininessMap(shininess,specmap));
   return texture2DLod(envMap, EnvMapGen(reflection), envLod).rgb * specmap.rgb * vec3(2.0);
}

void main()
{
  // Retrieve normals
  vec3 iNormal=gl_TexCoord[1].xyz;
  vec3 iTangent=gl_TexCoord[2].xyz;
  vec3 iBinormal=gl_TexCoord[3].xyz;
  vec3 vnormal=iNormal;
  //vec3 normal=normalize(imatmul(iTangent,iBinormal,iNormal,expand(texture2D(normalMap,gl_TexCoord[0].xy).yxz)*vec3(-1.0,1.0,1.0)));
  vec3 normal=normalize(imatmul(iTangent,iBinormal,iNormal,expand(texture2D(normalMap,gl_TexCoord[0].xy).wyz)));
 
  // Other vectors
  vec3 eye = gl_TexCoord[4].xyz;
  vec3 reflection = -reflect(eye,normal);
 
  // Init lighting accumulators
  vec3 diffuse = vec3(0.0);
  vec3 specular= vec3(0.0);
 
  // Sample textures
  vec4 damagecolor = texture2D(damageMap , gl_TexCoord[0].xy);
  vec4 diffusecolor= texture2D(diffuseMap, gl_TexCoord[0].xy);
  vec4 speccolor   = texture2D(specMap   , gl_TexCoord[0].xy);
  vec4 glowcolor   = texture2D(glowMap   , gl_TexCoord[0].xy);
 
  //sanity enforcement:
  float temp = 1.0 - max( diffusecolor.r, max( diffusecolor.g, diffusecolor.b ) );
  speccolor.r = min( speccolor.r, temp );
  speccolor.g = min( speccolor.g, temp );
  speccolor.b = min( speccolor.b, temp );
 
  //Fresnel:
  float alpha = diffusecolor.a * gl_FrontMaterial.diffuse.a;
  float fresnel_alpha = 1.0 - clamp( dot( eye, normal ), 0.0, 1.0 );
  alpha *= alpha;
  fresnel_alpha *= fresnel_alpha;
  alpha *= alpha;

  vec4 diffusemap  = lerp(damage.x, diffusecolor, damagecolor);
  vec4 specmap     = speccolor;
  float specdamage = clamp(1.0 - dot(damagecolor.xyz,vec3(1.0/3.0)) * damage.x * 2.0, 0.0, 1.0);
  specmap.rgb     *= specdamage;
  specmap.a       *= bias(specdamage);
  float gloss      = shininessMap(gl_FrontMaterial.shininess,specmap);
 
  fresnel_alpha = clamp( 0.0625 + ( 0.9375 * fresnel_alpha ), alpha, 1.0 );

  // Do lighting for every active light
  if (light_enabled[0] != 0)
     lighting0(normal, vnormal, eye, reflection, diffusemap, specmap, diffuse, specular);
  if (light_enabled[1] != 0)
     lighting1(normal, vnormal, eye, reflection, diffusemap, specmap, diffuse, specular);

  vec4 result;
  specular *= fresnel_alpha;

  result.a = fresnel_alpha;
  result.rgb  = lightingClose(diffuse, specular, diffusemap, specmap)
              + (alpha*glowcolor.rgb)
              + (envMapping(reflection,gloss,specmap)*fresnel_alpha);
  result *= cloaking.rrrg;
  gl_FragColor = result;
}
Note: The multiplication of glowcolor by alpha is only there temporarily, until I find the way to get rid of the bubbles' glow. I just don't know where it comes from. The xmesh has emissive at zero, and there's no glow texture specified... :-/


Klauss, a second (third?) question for you: For the sake of Pyramid's work, we need to enable Fresnel for planets. We can enable it for the whole planet, since only water and ice have much specularity, anyways. To do this, we need to give the planet material's diffuse color a low value for alpha. This should be okay because their blending mode ought to be ONE ZERO, so alpha is ignored; but just so that my shader believes it's glass and applies fresnel. The question is ***where*** do we do this?

EDIT:
And yet a third (fourth?) question: How do I get a detail texture into the shader?
Let me make that very simple:
1) I ABSOLUTELY DON'T WANT the kind of detail texture that woud add to the burden on artists. I just want a special perlin noise that I'm about to start working on a special Blender noodle to produce it. Please, let's not argue about this anymore. Believe me: You're not going to get a single artist to actually produce a custom detail texture. Ever. Not even me. All I want is a bit of noise to I don't notice the pixels when I get close to something. The only purpose of it will be to mask DDS quantization and extend the range of perceived detail, globally, for all units and for all materials. So, I envision this as a 256x256 PNG in the main /textures/ folder.
2 ) We won't need any kind of scaling controls: All we need is an automatic scaling that will map it to to 16 x 16 pixels. So, in a 1024 x 2048 texture, for instance, it should tile 64 x 128 times. Why? See the Long Story further down.
3) We won't need any kind of blending and distances controls. Why? Because as the distance increases the the mipmap level of the detail texture increases; and by the fifth level it will be a solid color already.

And now, The Long Story:

There's two things a detail texture needs to balance: Making its tiling repetitiveness unnoticeable, and providing higher frequencies; while at the same time keeping its size manageable.
The detail texture needs to add frequencies starting from twice the pixel frequency of the main texture, at the highest.
I say at the highest, because quantization noise is not only visible at the pixel frequency but, in lesser amounts, at all its sub-harmonics, like half the pixel frequency, one third, etc.
So, for a detail texture to be really good, it should add a bit of noise at 0.75 of the pixel frequency of the main texture.
My plan is to produce 4 perlin noise textures, with relative ratios of 1, 1.7, 2.9 and 5 (going by cubic root of 5 ratios). These would be average perlin frequencies, each with its own harmonics. I'll assign these four perlins to the R, G, B and A channels. The lowest, red frequency, will map to 0.76 of the main texture's pixel frequency. The green perlin will map to 1.3 times the main texture's pixel frequency, and so on... to alpha channel's perlin frequency mapping to 3.8 times main texture pixel frequency. The amplitudes of the four channel perlins will be proportional to the square roots of their frequencies, except that the green channel needs only half as much noise as red and blue, and the alpha channel 1/8th as much, thus 1, 0.65, 1.7 and 0.55 respectively, --and relatively: gain will be maxed out overall, to make best use of the 8-bits per channel, and then brought down in intensity in the shader such that the red channel amplitude is about 0.7 of a dds red channel amplitude step, --subject to experimentation.
Now, the rgb channels will modulate the main diffuse texture additively, and the main specular texture subtractively, so as to minimize the overall visibility of the detail texture, for a given amount of modulation. The alpha channel will modulate shininess subtractively.
These modulations are to the incoming texture colors, of course; prior to lighting.

Now, the question of absolute frequencies:
Like I said, I envision this detail texture as a PNG (NOT a DDS), 256 x 256, always sitting in video ram and used globally. In every case, it maps to 16 x 16 texels of the textures it modulates. Therefore, the pixel frequencies for the rgba channels in the detail texture would be 16 divided by 0.76, 1.3, 2.2 and 3.8; --namely 21, 12.3, 7.3 and 4.2 texels typical.

Even in the case of red, at 21 texels frequency, 256/21 = 12.2 hills over its width, so I don't think the repetitiveness will be noticeable (specially at the low level of modulation we're talking about. But to make sure there are no frequencies lower, or even as low as half of the main texture's 2-texel frequency, I indend for the Blender noodle to subtract a 24-texel radius blur of the result from the result, while adding 50% gray, to make sure the color stays generally flat across the the detail texture.

But so, this is why the detail texture has to map to a fixed, 16x16 tile of any texture it modulates.
Last edited by chuck_starchaser on Thu Apr 10, 2008 7:34 am, edited 2 times in total.
User avatar
chuck_starchaser
Elite
Elite
 
Posts: 8014
Topics: 195
Joined: Thu Sep 04, 2003 9:03 pm
Location: Montreal

Postby klauss » Thu Apr 10, 2008 6:22 am

Planets are spheres generated in code. You'd have to check gfx/sphere.cpp to see where the parameters come, since I don't remember. That, or ask someone that does ;)

In any case what you need is not that, but the ability to specify different shaders for planets ( and hopefully glass ;) ). I'll take a shot at that when I get a chance.
Oíd mortales, el grito sagrado...
Call me "Menes, lord of Cats"
Wing Commander Universe
User avatar
klauss
Elite
Elite
 
Posts: 7243
Topics: 55
Joined: Mon Apr 18, 2005 7:40 am
Location: LS87, Buenos Aires, República Argentina

Postby safemode » Thu Apr 10, 2008 7:27 am

even planets are just triangular faceted geometric objects. Get up real close to one and they'll look just like that glass hemisphere.
Ed Sweetman endorses this message.
safemode
Developer
Developer
 
Posts: 2150
Topics: 84
Joined: Sun Apr 22, 2007 6:17 pm
Location: Pennsylvania

Postby chuck_starchaser » Thu Apr 10, 2008 7:46 am

klauss wrote:Planets are spheres generated in code. You'd have to check gfx/sphere.cpp to see where the parameters come, since I don't remember. That, or ask someone that does ;)

I'll check that out. Thanks!

In any case what you need is not that, but the ability to specify different shaders for planets ( and hopefully glass ;) ). I'll take a shot at that when I get a chance.
I totally agree, but in the short term I think it's better to stay with the "one shader fits all" paradigm, just for the moment. Reason being, I'm going to start working on the next gen shader, using the new texture packing, like tomorrow. (Well, I just want to get detail textures first. See the big EDIT to my previous post.) And, I'm not sure, but I think it would be easier to come up with a unified, next-gen shader first, and then modify it for planets and glass and volumetric things.

Please check my previous post's edit.

safemode wrote:even planets are just triangular faceted geometric objects. Get up real close to one and they'll look just like that glass hemisphere.
I think we all know that. That's not the issue, though; the question is how/where to give them a material that has diffuse alpha of 0.1, --so that my shader will be fooled to think they are made of glass, and apply fresnel to the reflections on them.

EDIT:
Found it! In vegastrike.config, change
Code: Select all
      <color name="planet_mat_diffuse" r="1" g="1" b="1" a="1.0"/>
to
Code: Select all
      <color name="planet_mat_diffuse" r="1" g="1" b="1" a="0.1"/>
User avatar
chuck_starchaser
Elite
Elite
 
Posts: 8014
Topics: 195
Joined: Thu Sep 04, 2003 9:03 pm
Location: Montreal

Postby pyramid » Thu Apr 10, 2008 3:17 pm

Here we go with the latest results:
* config updated to alpha=0.1
* newest shader code
* space background set to black
* all system lights set to white (ambient rgb 0, diffuse rgb 0.85, specular rgb 0)
* sun light set to rgb 0.75
* added atmosphere for testing

Specularity, shininess, citylights, and atmosphere work fine.

The oceans are still reddish on the night side, though not so much. I played a bit with the factors for specular in the noodle. The reddiness disappears with low values (and so does the specularity :-(). Since the color of the night ocean changes with the background and the specularity, there must be a connection here. There is no change whatsoever from adjusting lights or atmosphere.

Latest image:
Image
Last edited by pyramid on Thu Apr 10, 2008 4:23 pm, edited 1 time in total.
User avatar
pyramid
Expert Mercenary
Expert Mercenary
 
Posts: 960
Topics: 44
Joined: Wed Jun 14, 2006 6:02 pm
Location: Somewhere in the vastness of space

Postby chuck_starchaser » Thu Apr 10, 2008 4:08 pm

pyramid wrote:* space background set to black

Did you delete .vegastrike/textures/backgrounds? If the red spheremap is still there, it will still be used for environment mapping. You can delete all the textures in that folder; they will be recreated automatically.

EDIT:
You may also need to put the specularity factor in the noodle back up, as fresnel lowers it ... Hmm... I wonder if fresnel shouldn't just ***overwrite*** specularity, rather than multiply it...
Hold on, give me 15 minutes.
Last edited by chuck_starchaser on Thu Apr 10, 2008 4:27 pm, edited 1 time in total.
User avatar
chuck_starchaser
Elite
Elite
 
Posts: 8014
Topics: 195
Joined: Thu Sep 04, 2003 9:03 pm
Location: Montreal

Postby pyramid » Thu Apr 10, 2008 4:22 pm

chuck_starchaser wrote:Did you delete .vegastrike/textures/backgrounds?

I alwyas, but always always always forget to do that when testing :oops:.

Et voilà, complete success, it's spectacular! I love the smooth transition between day and night:
Image
User avatar
pyramid
Expert Mercenary
Expert Mercenary
 
Posts: 960
Topics: 44
Joined: Wed Jun 14, 2006 6:02 pm
Location: Somewhere in the vastness of space


PreviousNext

Return to Modding Engine Room

Who is online

Users browsing this forum: No registered users and 1 guest