Shader patch

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

Moderator: Mod Contributor

loki1950
The Shepherd
Posts: 5799
Joined: Fri May 13, 2005 8:37 pm
Location: Ottawa
Contact:

Post by loki1950 »

Yes :D :D the terminator does indeed look much better are you getting any rotation of the planet if so awesome.

Enjoy the Choice :)
my box::HP Envy i5-6400 @2Q70GHzx4 8 Gb ram/1 Tb(Win10 64)/3 Tb Mint 19.2/GTX745 4Gb acer S243HL K222HQL
Q8200/Asus P5QDLX/8 Gb ram/WD 2Tb 2-500 G HD/GF GT640 2Gb Mint 17.3 64 bit Win 10 32 bit acer and Lenovo ideapad 320-15ARB Win 10/Mint 19.2
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Post by chuck_starchaser »

Sorry, I was editing my post. Glad that worked. I'm fixing the shader so that when the material is a dielectric (which we indicate by alpha 0.1), the shader will ignore specularity, and simply replace it with a grey-scale fresnel factor specularity. Give me 10 to 20 minutes....
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Post by chuck_starchaser »

DAMN! No, I can't do that in the shader. If I did, the continents would become specular.
You'll need for the oceans to be white in specular.
I'll modify the noodle.

DAMN! That's going to make the shininess go up like crazy.
What to do? What to do?
Thinking....
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Post by chuck_starchaser »

Okay, this is a very hard problem. For now, make the oceans white in specular, and use this shader:

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) // alpha-based shininess modulation
{
  float result = clamp(specmap.a*shininess,1.0,255.0);
  return result * result;
}
/*
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;
}
The only difference with this shader is that it doesn't compute shininess from specularity, but reads it from the alpha channel of the specular texture. Unfortunately, most models don't have shininess in the spec map's alpha channel, so this will ONLY work for planets. I'll work out some other solution in the meantime...
pyramid
Expert Mercenary
Expert Mercenary
Posts: 988
Joined: Thu Jun 15, 2006 1:02 am
Location: Somewhere in the vastness of space
Contact:

Post by pyramid »

chuck_starchaser wrote:...it doesn't compute shininess from specularity, but reads it from the alpha channel of the specular texture...
Works fine as well. I was using the specular map with shininess in alpha (by the noodle) anyway (with the factors reset to 0.5).
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Post by chuck_starchaser »

No, the problem is that the other shader doesn't even look at the shininess in the alpha channel; it computes shininess from spec color using an ad-hoc formula. The problem is that oceans are as specular as glass, but of much lower shininess (from orbital distance), so my "standard" shader can't do them justice; --either the shininess will be right, but the specularity too low; or the specularity will be right, but the shininess too high.

Ah, this gives me an idea!

I'll be back...
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Post by chuck_starchaser »

BINGO!

Simplest solution!

Go back to using my "standard" shader. Make oceans white in spec.
Specularity and fresnel will be exactly right, but shininess will be ultra glossy.
So, then we need to bring the shininess down at the "planet xmesh" level.
Unfortunately, this doesn't seem to be in vegastrike.config.
I'll have a look at the code after I come back from dinner.
klauss
Elite
Elite
Posts: 7243
Joined: Mon Apr 18, 2005 2:40 pm
Location: LS87, Buenos Aires, República Argentina

Post by klauss »

I don't believe you'll be able to implement that kind of detail map. Not right now.
First, you'd need a globally applied texture. This could be useful in many ways... like lookup tables. So I might add that, if it's not too much trouble (I hope not).

The auto-mapping to 16x16 pixels is another issue. I don't see an easy way to do that. For now, if I were you, I'd settle with a fixed repeat factor (just make it high enough). We'll improve that later if needed.
Oíd mortales, el grito sagrado...
Call me "Menes, lord of Cats"
Wing Commander Universe
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Post by chuck_starchaser »

Ok, thanks! Good enough. If you can get that globally applied texture to work, I'll do the rest.
And while you're at it, if you can get the "texture packing version" variable into xmesh, that would rock.

Alrighty, my claws a sheathed, my belly full, back to work. Let's see where's the shininess power for planets is set...
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Post by chuck_starchaser »

Hellcat wrote:All of this is set in the system XML file including the alpha

parsed in line 1018 of star_system_xml.cpp
SPOWER is the value you want to change that

you could change DALPHA as well to change the diffuse GL alpha value
pyramid
Expert Mercenary
Expert Mercenary
Posts: 988
Joined: Thu Jun 15, 2006 1:02 am
Location: Somewhere in the vastness of space
Contact:

Post by pyramid »

Not sure which thread contains the latest shader version. But the question here is: once the release has been done, can we commit this shader patch to svn.? It looks so much nicer than the release shader ;-)
ace123
Lead Network Developer
Lead Network Developer
Posts: 2560
Joined: Sun Jan 12, 2003 9:13 am
Location: Palo Alto CA
Contact:

Post by ace123 »

We did an initial tag, but one or two things have changed...

Tomorrow should be fine to commit, after the dust has settled.
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Post by chuck_starchaser »

This is my most current version:

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) // alpha-based shininess modulation
{
  float result = clamp(specmap.a*shininess,1.0,255.0);
  return result * result;
}
*/
float shininessMap(float shininess, vec4 specmap) // luma-based shininess modulation
{
  float3 temp = specmap.rgb;
  temp *= specmap.rgb;
  temp.b = (temp.r+temp.g)*0.5;
  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 );
   float NdotL = clamp( dot(normal,light), -1.0, VNdotLx4 );
   float RdotL = clamp( dot(reflection,light), 0.0, VNdotLx4 );
   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
   specular += ( pow( RdotL, lightspot_brightness(shininess,specmap)) * lightDiffuse.rgb * lightAtt );
   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(4.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 );
  fresnel_alpha = 1.0-fresnel_alpha;
  fresnel_alpha *= fresnel_alpha; //to account for inner surface reflection
  fresnel_alpha = 1.0-fresnel_alpha;

  // 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)
              + fresnel_alpha*glowcolor.rgb
              + (envMapping(reflection,gloss,specmap)*fresnel_alpha);
  result *= cloaking.rrrg;
  gl_FragColor = result;
}
There's also room for some optimizations I never got around to do. If there's any compatibility problems due to having a few instructions too many, let me know and I'll massage the code down.
pyramid
Expert Mercenary
Expert Mercenary
Posts: 988
Joined: Thu Jun 15, 2006 1:02 am
Location: Somewhere in the vastness of space
Contact:

Post by pyramid »

Great. Let me test a bit and wait for some feedback on the current release. By next week I shall commit this if there is nothing indicating the contrary.
pyramid
Expert Mercenary
Expert Mercenary
Posts: 988
Joined: Thu Jun 15, 2006 1:02 am
Location: Somewhere in the vastness of space
Contact:

Post by pyramid »

I was almost ready to commit but have noticed that planet atmospheres have no gradient at least on my card with the latest drivers (linux & nvidia 8600). I am using the last update from the PU svn repo. Strangely, this effect was not reproducible on my win box (ati chipset), so I am wondering if this is compile or library related. Maybe you guys have some hint where to start looking.

This isn't a big blocking point and since we have been discussing a different shader for planets anyway for the other topics like specularity, I am ready to commit the above mentioned version.

EDIT:
This is what I get on planet atmospheres with the shader:
Image

Can anybody reproduce this effect with the PU shaders? Any hint on how to proceed with this?

EDIT2:
I made a clean compile, re-installed my previous nVidia drivers and used the original VS shaders and seem to get the same effect, so I think that's somehow related to my box, though no idea what could be wring here.
Obviously it's nothing related to the shaders.
safemode
Developer
Developer
Posts: 2150
Joined: Mon Apr 23, 2007 1:17 am
Location: Pennsylvania
Contact:

Post by safemode »

Ok, i double checked to make sure DXT5 isn't to blame again. It's not.

My only guess is that it could be due to smooth lines disabling some kind of blending going on .... or perhaps another change affecting how the alpha blending is done.

not really my area of experience since it's not related to anything i've played with so far.
Ed Sweetman endorses this message.
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Post by chuck_starchaser »

Damn! Sorry, I didn't notice your post till now. I've no idea what may be causing that. Thing is, I'm not sure we have atmospheres in PU; I think we do, but perhaps a different kind. And I'm XP-only, for now, myself; but I haven't heard any PU users complain of atmospheres looking thick.
What kind of atmosphere is that, anyways? Why's it so much bigger than the planet? IOW, are you sure that's an atmosphere and not some halo, fog or fawg construct?
I know that the shader has no say on blending mode. The shader can go as far as computing the fragment's rgb color as well as alpha; but if the blending mode specified in the xmesh is ONE ONE, then alpha is ignored, and the rgb values are added.
The only thing I can think of is that maybe the fresnel part of the shader may be confusing the blending mode of air with that of glass, and applying fresnel to the atmo...
klauss
Elite
Elite
Posts: 7243
Joined: Mon Apr 18, 2005 2:40 pm
Location: LS87, Buenos Aires, República Argentina

Post by klauss »

That's a funnel thingy that does not use shaders at all. I just checked.

BTW, I can confirm the rainbow thingy is indeed the funnel - I have 97.46 drivers and the clouds look perfectly fine beneath the rainbow, but I do see the rainbow. Besides, as you rotate around the planet, the rainbow "wiggles" just as the funnel usually does. In short: it is the funnel.

I tried reverting several changes in mesh_gfx and gl_texture that I thought could be responsible and nothing. It's quite mind-boggling. I believe it must be some kind of GL state mess. It looks as if there was a texture unit active that shouldn't.

Edit: FIXED!
Steps to fix:
svn up && make vegastrike


:D
Oíd mortales, el grito sagrado...
Call me "Menes, lord of Cats"
Wing Commander Universe
safemode
Developer
Developer
Posts: 2150
Joined: Mon Apr 23, 2007 1:17 am
Location: Pennsylvania
Contact:

Post by safemode »

the modifications to gl_texture.cpp shouldn't be needed. those PNG types were created by me to allow PNG to bypass compression on the fly, nothing is compressed anymore. And those types are no longer used.

Actually, those types (PNGRGB*) are where your vsimage modification were used. I _thought_ i had replaced them with the original code (what you inserted), apparently i dreamt that.
Ed Sweetman endorses this message.
pyramid
Expert Mercenary
Expert Mercenary
Posts: 988
Joined: Thu Jun 15, 2006 1:02 am
Location: Somewhere in the vastness of space
Contact:

Post by pyramid »

The name "atmosphere" was used in the physical sense and I have realized that it is actually different from the system definition naming where "atmosphere" defines the cloudmap and "fog" defines the atmospheric scattering, or the halo. The problem was obviously related to the halo.

The halo on Cephid_17 (from where the screen shot was taken) is exaggerated. Should not be, true. I'll need to review all the system files for such exaggerated definitions.

It is indeed very strange that nobody seemed to had trouble with that. It may be due to my new drivers or a combination of drivers, GPU, and glx versions. Or just nobody came across planets with atmospheres. Can't explain that.

While the patch fixed the rainbow artifact, the halo gradient still behaves in the same way on my system (with the current vs shaders).

EDIT:
I did a clean compile, removed all generated textures in .vegastrike and, voilà, it is perfect again.

Glad that the fix resolved the issue. Not being related to the shader or the DXT5 bug, we are good to continue implementing the new shaders in vs. Special thanks to chuck for this development.
safemode
Developer
Developer
Posts: 2150
Joined: Mon Apr 23, 2007 1:17 am
Location: Pennsylvania
Contact:

Post by safemode »

just to be clear then (since i'm at work and can't test). The blacklist is not needed ? In my own testing I did not need the black list any longer, this screwing up of png depth was the only issue i was having.

I cant believe i didn't put that code back in the file, I could have sworn I did. I can almost distinctly remember it. Argg...
Ed Sweetman endorses this message.
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Post by chuck_starchaser »

Just in the spirit of openness, there've been 3 recent versions of the shader, with some of them making shininess proportional to the cube of specularity; then went back to the square, can't remember why; and now back up to the fourth power... They all relate to the function ShininessMap()...

Square version:

Code: Select all

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

Cube version:

Code: Select all

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.5;
  return clamp( temp.b*shininess, 1.0, 255.0 );
}

Fourth power version:

Code: Select all

float shininessMap(float shininess, vec4 specmap) // luma-based shininess modulation
{
  float3 temp = specmap.rgb;
  temp *= specmap.rgb;
  temp *= specmap.rgb;
  temp *= specmap.rgb;
  temp.b = (temp.r+temp.g)*0.5;
  return clamp( temp.b*shininess, 1.0, 255.0 );
}
Frankly, I can't decide which one's "righter", since none of them are right, period; since shininess is unrelated to specularity, in the real world; so I wash my hands from it all. The only function we should have, really is,

Code: Select all

float shininessMap(float shininess, vec4 specmap) // alpha-based shininess modulation
{
  float result = clamp(specmap.a*shininess,1.0,255.0);
  return result * result;
}
but it's commented out because most models don't have shininess in spec alpha. But we can't have shininess in spec alpha for some models and the old hack for other models until Klauss is done with the Method variable for xmesh, so, let's just consider the present shader flawed by design. Take your pick...
pyramid
Expert Mercenary
Expert Mercenary
Posts: 988
Joined: Thu Jun 15, 2006 1:02 am
Location: Somewhere in the vastness of space
Contact:

Post by pyramid »

The new shaders are committed to svn. Thanks to chuck.

There will be a lot of rework on the unit textures required (as announced previously). Look for example in the Sol system, the stations have now all a strong blue specular color due to the blue background.

Other than that, I am concerned with the planets, particularly the atmosphere fog, which doesn't look very inviting, though I tuned it to the best settings with the current shader (see Cephid_17 or Sol). What is the way to integrate separate shaders for planets?
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Post by chuck_starchaser »

pyramid wrote:What is the way to integrate separate shaders for planets?
Klauss has some kick-ass planet shaders. All we need is to wait for Klauss to finish the Method variable in xmesh, so then you can ... Ehm... planets don't have xmeshes... well, technical details aside, we need to be able to specify a different shader, in a nutshell :D
ace123
Lead Network Developer
Lead Network Developer
Posts: 2560
Joined: Sun Jan 12, 2003 9:13 am
Location: Palo Alto CA
Contact:

Post by ace123 »

Would it be possible to add a "shader" column to units.csv? That way the planet entries in there can have a custom shader.

If klauss has a solution that is also fine... it would be cool to allow custom shaders for some units (For example jump points).
Post Reply