CineMut shader family - Opaque

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

Moderator: Mod Contributor

Post Reply
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Post by chuck_starchaser »

That's true! His dad rides a Harley, doesn't he? But last I'd heard him and his dad were in fist-punch terms. I'll email him just in case. Thanks for the idea.
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Post by chuck_starchaser »

Small addition before breakfast:

Image

Well, small indeed; but it's fully welded, so, not so insignificant ;-)
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:On other news, I've worked a bit on the materials. New set of textures:
http://wcjunction.com/temp_images/tex_00001.png
http://wcjunction.com/temp_images/tex_10001.png
http://wcjunction.com/temp_images/tex_20001.png
http://wcjunction.com/temp_images/tex_30001.png
http://wcjunction.com/temp_images/tex_40001.png
http://wcjunction.com/temp_images/moto_PRT.png
And new shader; this one has the squared prt's; forgot to remove them; has some detail tweaks, and cant't remember what else. Oh, yeah, new prt decoding.
http://wcjunction.com/temp_images/cinemut_opaque.fp
You'd better backup your current shader, though; I hope all the GI-related stuff is back the way it was, but I can't guarantee.
Maybe I missed a post, but is there a technique file for the shader?
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Post by chuck_starchaser »

Yes; here's my whole techniques folder:
http://wcjunction.com/temp_images/techniques.rar
It should already be there, if you check out Klauss' techniques branch, tho.
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 »

Thanks. Unfortunately on my cheap ATI Mobility Radeon M7 I can't test anything (even with the latest drivers) with techniques in that the model shows but without textures:

Code: Select all

Compilation of technique cinemut_opaque failed... trying default
Cause: Error compiling program vp:"zwrite" fp:"zwrite"
Compilation of technique default failed... trying fixed
Cause: Error compiling program vp:"zwrite" fp:"zwrite"
Before that:

Code: Select all

OpenGL Extensions supported: GL_WIN_swap_hint GL_EXT_bgra GL_EXT_paletted_texture
OpenGL::GL_EXT_compiled_vertex_array unsupported
OpenGL::GL_EXT_multi_draw_arrays unsupported
OpenGL::Accurate Fog Distance unsupported
OpenGL::Generic Texture Compression unsupported
OpenGL::S3TC Texture Compression unsupported
OpenGL::Multitexture unsupported
OpenGL::TextureCubeMapExt unsupported
OpenGL::S3TC Texture Clamp-to-Edge unsupported
OpenGL::S3TC Texture Clamp-to-Border unsupported
OpenGL::EXTColorTable unsupported
Compilation of technique fixed failed... trying fixed5
Cause: Error compiling program vp:"fixed8" fp:"fixed"
Compilation of technique fixed5 failed... trying fixedgl
Cause: Error compiling program vp:"fixed5" fp:"fixed"
Compilation of technique fixed_simple failed... trying fixedgl
Cause: Error compiling program vp:"fixed5" fp:"fixed_simple"
:(

I'll test it later at home.
klauss
Elite
Elite
Posts: 7243
Joined: Mon Apr 18, 2005 2:40 pm
Location: LS87, Buenos Aires, República Argentina

Post by klauss »

You seem not to have an accelerated driver at all.
Hence I doubt the phrase (even with the latest drivers)
;)
Oíd mortales, el grito sagrado...
Call me "Menes, lord of Cats"
Wing Commander Universe
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 »

Indeed. Previously I haven't seen a very well hidden option (under Troubleshooting :?: :!: ) to enable Hardware Acceleration.

As compared to before, most of the GL extensions look much better:

Code: Select all

OpenGL Extensions supported: GL_ARB_multitexture GL_EXT_texture_env_add GL_EXT_compiled_vertex_array GL_S3_s3tc GL_ARB_occlusion_query GL_ARB_texture_border_clamp GL_ARB_texture_compression GL_ARB_texture_cube_map GL_ARB_texture_env_add GL_ARB_texture_env_combine GL_ARB_texture_env_crossbar GL_ARB_texture_env_dot3 GL_ARB_texture_mirrored_repeat GL_ARB_transpose_matrix GL_ARB_vertex_blend GL_ARB_vertex_buffer_object GL_ARB_window_pos GL_ATI_envmap_bumpmap GL_ATI_map_object_buffer GL_ATI_texture_env_combine3 GL_ATI_texture_mirror_once GL_ATI_vertex_array_object GL_ATI_vertex_streams GL_ATIX_texture_env_combine3 GL_ATIX_texture_env_route GL_EXT_abgr GL_EXT_bgra GL_EXT_clip_volume_hint GL_EXT_draw_range_elements GL_EXT_fog_coord GL_EXT_multi_draw_arrays GL_EXT_packed_pixels GL_EXT_point_parameters GL_EXT_rescale_normal GL_EXT_secondary_color GL_EXT_separate_specular_color GL_EXT_stencil_wrap GL_EXT_texgen_reflection GL_EXT_texture3D GL_EXT_texture_compression_s3tc GL_EXT_texture_cube_map GL_EXT_texture_edge_clamp GL_EXT_texture_env_combine GL_EXT_texture_env_dot3 GL_EXT_texture_filter_anisotropic GL_EXT_texture_lod_bias GL_EXT_texture_object GL_EXT_texture_rectangle GL_EXT_vertex_array GL_HP_occlusion_test GL_NV_texgen_reflection GL_NV_blend_square GL_NV_occlusion_query GL_SGI_color_matrix GL_SGIS_texture_edge_clamp GL_SGIS_texture_border_clamp GL_SGIS_texture_lod GL_SGIS_generate_mipmap GL_SGIS_multitexture GL_SUN_multi_draw_arrays GL_WIN_swap_hint WGL_EXT_extensions_string WGL_EXT_swap_control 
OpenGL::GL_EXT_compiled_vertex_array unsupported
OpenGL::GL_EXT_multi_draw_arrays supported
OpenGL::Accurate Fog Distance unsupported
OpenGL::Generic Texture Compression supported
OpenGL::S3TC Texture Compression supported
OpenGL::Multitexture supported (3 units)
OpenGL::TextureCubeMapExt supported
OpenGL::S3TC Texture Clamp-to-Edge supported
OpenGL::S3TC Texture Clamp-to-Border supported
OpenGL::EXTColorTable unsupported

Compilation of technique fixed failed... trying fixed5
Cause: Error compiling program vp:"fixed8" fp:"fixed"
Compilation of technique fixed5 failed... trying fixedgl
Cause: Error compiling program vp:"fixed5" fp:"fixed"
Compilation of technique fixed_simple failed... trying fixedgl
Cause: Error compiling program vp:"fixed5" fp:"fixed_simple"
...
Compilation of technique cinemut_opaque failed... trying default
Cause: Error compiling program vp:"zwrite" fp:"zwrite"
Compilation of technique default failed... trying fixed
Cause: Error compiling program vp:"zwrite" fp:"zwrite"
Still no cinemut *and* vs freezes when changing to pancam view (key 6) :roll: maybe cause it cannot find the shader. When disabling hardware acceleration, it works but without textures.

*EDIT*
On my linux machine (NV 8600 GT) there are no shader compile errors shown. However the app crashes with


Btw, what is the fallback for the cinemut for GPUs with only 3 texture units (supposed to be default)? I imagine it will be the last step after the current workflow is complete, but meanwhile it will break some low-end hardware.

Code: Select all

terminate called after throwing an instance of '__impl::InvalidParameters'
  what():  Cannot load texture file "cm_detail.png"
HereAborted
I can see 3 texture references in the techniques file:

Code: Select all

        <texture_unit src="decal:0" default="file:white.bmp" name="diffuseMap"/>
        <texture_unit src="file:cm_detail.png" name="detailMap"/>
        <texture_unit src="file:moto_PRT.png" name="prtMap"/>
Why are they hard coded and where do I get them from?

*EDIT2*
I've found the detail.png texture on page 8 of this post. It's fine when it goes uncompressed into the textures folder.

Now, my bike doesn't look as nice as yours. Can this be related with compression? Do all textures have to be compressed using DXT5?
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Post by chuck_starchaser »

pyramid wrote:Btw, what is the fallback for the cinemut for GPUs with only 3 texture units (supposed to be default)? I imagine it will be the last step after the current workflow is complete, but meanwhile it will break some low-end hardware.
Right now there's no fallback at all. You need compatible hardware or you're S.O.L. Reason being that the highend shader has to be finalized first; otherwise each time we change the shader we have to change its lower-end siblings.
I can see 3 texture references in the techniques file:

Code: Select all

        <texture_unit src="decal:0" default="file:white.bmp" name="diffuseMap"/>
        <texture_unit src="file:cm_detail.png" name="detailMap"/>
        <texture_unit src="file:moto_PRT.png" name="prtMap"/>
Why are they hard coded and where do I get them from?
Detail is hard-coded because it will be used by all models using CineMut. The purpose of detail is just to add subtle noise (clouds to shininess and dielectric blend channels; speckles to diffuse and specular; and hammer bumpiness to the normalmap) and nothing about it needs to be ship-specific; though there is a channel for control of the way detail is applied.
PRT shouldn't be hard-coded; maybe Klauss added it like that to save time producing a new bfxm.
*EDIT2*
I've found the detail.png texture on page 8 of this post. It's fine when it goes uncompressed into the textures folder.
It should never be compressed; detail.png should be what it is, a png with no compression, as compression is pretty pointless with a texture that is pure noise; and would take time to decompress for no size advantage. It's pretty small, anyways.
Now, my bike doesn't look as nice as yours. Can this be related with compression? Do all textures have to be compressed using DXT5?
Those textures are not compressed; well, they are png-compressed; non-lossy.
Could you show a screenshot of what you're getting?
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 »

What I see looks much less happy than your screens:
http://vegastrike.sourceforge.net/galle ... temId=9591

However I did not add the testbike_lights to the bfxm yet. Might this be the reason?

On a side note, the engine thrusters show that orientation is not Z>front Y>up, which doen't really matter for this test object.
Fendorin
Elite Venturer
Elite Venturer
Posts: 725
Joined: Mon Feb 26, 2007 6:01 pm
Location: France, Paris

Post by Fendorin »

i don't understand what is it exactly Cinemut???
i can't understand your sentences
my english isn't so techincal maybe?
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Post by chuck_starchaser »

pyramid wrote:What I see looks much less happy than your screens:
http://vegastrike.sourceforge.net/galle ... temId=9591
That is definitely wrong; and the worst part is that I've seen stuff like that while working on the shader, like full of tar black stains like that, but now I can't remember when did that happen or what the solution was... :-/
However I did not add the testbike_lights to the bfxm yet. Might this be the reason?
No, the lights mesh will be specifying the CineMut FireGlass shader, which doesn't exist yet
On a side note, the engine thrusters show that orientation is not Z>front Y>up, which doen't really matter for this test object.
Yeah, I know; I always have trouble with axes...

Where did you get the shader from? Here's my last shader, prior to Klauss' most recent edits:

Code: Select all

//NEW SHADER (high end)
uniform int light_enabled[gl_MaxLights];
uniform int max_light_enabled;
//samplers
uniform samplerCube cubeMap;
uniform sampler2D diffMap;   //1-bit alpha in alpha, for alpha-testing only
uniform sampler2D specMap;   //log256(shininess) in alpha
uniform sampler2D glowMap;   //ambient occlusion in alpha
uniform sampler2D normMap;   //U in .rgb; V in alpha (special encoding; see norm_decode())
uniform sampler2D damgMap;   //"dielectricness" in blue, specular blend in alpha
uniform sampler2D detailMap; //.rgb adds to diffuse, subtracts from spec; alpha mods shininess
//other uniforms
uniform vec4 cloakdmg; //.rg=cloak, .ba=damage
#define cloak_alpha() ((cloakdmg.rrrg))
#define damage() ((cloakdmg.b))
#define inv_damage() ((1.0-cloakdmg.b))
//envColor won't be needed, since we're fetching it from the envmap

//NOTE: Since the term "binormal" has been rightly deprecated, I use "cotangent" instead :)

//general subroutines:

float lerp( in float f, in float a, in float b)
{
    return (1.0-f)*a + f*b;
}
vec3 lerp( in float f, in vec3 a, in vec3 b)
{
    return (1.0-f)*a + f*b;
}
vec3 fastnormalize( in vec3 v ) //less accurate than normalize() but should use less instructions
{
    float tmp = dot( v, v );
    tmp = 1.5 - (0.5*tmp);
    return tmp * v;
}
float make_signed( in float zero_to_one_signed )
{
    return zero_to_one_signed - 127.0/256.0;
}
vec3 imatmul( in vec3 tan, in vec3 cotan, in vec3 norm, in vec3 texnorm )
{
    return normalize( texnorm.xxx*tan + texnorm.yyy*cotan + texnorm.zzz*norm );
}

//decoding subroutines:

void detail_blend_decode( in float dmgblend, out float bump, out float tex )
{
    float temp = (dmgblend-127.0/256.0)*2.0;
    bump = clamp( temp, 0.0, 1.0 );
    tex = clamp( -temp, 0.0, 1.0 );
}
float DBSRF( in float dielectric_blend_input, in float shininess_input )
{
    float temp1 = dielectric_blend_input * (1.0-dielectric_blend_input);
    float temp2 = shininess_input * (1.0-shininess_input);
    return temp1 / (temp1+temp2+0.0001);
}
/* The LaGrande normalmap noodle does away with the z-term for the normal by encoding U & V
as 0.5*tan( angle ), where angle is arcsin( U ) or arcsin( V ), respectively. To fit that
into a 0-1 range, we multiply by 0.5 once again, and add 0.5.
To reverse the encoding, we first subtract 0.5, then multiply by four, fill the z term with
1.0, and normalize. But multiplying by four is not needed if instead we fill the z term with
0.25, instead; *then* normalize :D
Here we've broken up the normalization, since there's no need to fully denormalize before
adding the normalmap, damage and detail normals. Just subtractin 0.5 is enough. And there's
also no point in normalizing before imatmul(); so normalization is done inside imatmul().
 */
vec2 dUdV_first_decode( vec2 raw_dudv )
{
    return raw_dudv - vec2( 127.0/256.0 );
}
vec3 dUdV_final_decode( vec2 blend_of_first_decode )
{
    vec3 temp;
    temp.rg = blend_of_first_decode;
    temp.b = 0.25;
    return temp; //might as well normalize after imatmul
}
float dielectricblend_decode( in float linear_input )
{
    float temp1 = linear_input - 0.5;
    float temp2 = temp1 * temp1;
    return temp1/(1.8*temp2+0.55) + 0.5;
}
float dielectric_decode( in float linear_input )
{
    return (1.0625+linear_input) / (1.0625-linear_input);
}
float ambient_LOD( in float dielectric_k )
{
    float temp = 1.0 / dielectric_k;
    return 4.0 * (temp*temp - temp) + 9.0;
}
float is_metal_decode( in float specdiffbalance )
{
    float tmp1 = 19.6444*(specdiffbalance-0.583333);
    float tmp2 = sqrt(1+tmp1*tmp1);
    return 0.5*tmp1/tmp2+0.5024772;
}
float nonzerok_decode( in float linear_k_input )
{
    float temp = linear_k_input * linear_k_input;
    temp *= ( temp * 20000.0 );
    return temp / (temp+1);
}
void distribute_gloss
(
  in float is_metal, in float is_dielectric, in float gloss_in,
  out vec2 linear_glosses
)
{
    // Shininess CTRL goes to metallic spec for metals; dielectric gloss for non-metals;
    // and the defaults are min for both; except when dielectric k is 0/trivial we want
    // to max-out shininess for fgloss, as it will be used for dual specularity metals
    // rather than for dielectric, Fresnel shininess.
    // This whole routine works with linear, 0-1 values (input representation) in & out,
    // rather than with actual shininess values. Outputs to a vec2 with both glosses
    linear_glosses.x = is_metal * gloss_in;
    linear_glosses.y = lerp( is_metal, gloss_in, 1.0-is_dielectric );
}
vec2 lin_gloss_2_LOD( in vec2 lin_gloss )
{
    //The following is an approximation of the true formula. It avoids
    //using a logarithm, plus it makes better use of env-map mipmaps.
    //The true formula would be 8+log2( tan( spotlight radial angle ) )
    //The approximation is 15.2*(x^3+1.07)*(0.92-x) + 8.5*x - 6.0; but
    //we do it for 2 shininesses simultaneously, using vec2 in and out.
    vec2 temp1 = lin_gloss * lin_gloss * lin_gloss + vec2( 1.07 );
    vec2 temp2 = vec2( 0.92 ) - lin_gloss;
    return temp1 * temp2 * 15.2 + lin_gloss * 8.5 - vec2( 6.0 );
}
vec2 lin_gloss_2_exp( in vec2 lin_gloss )
{
    /* The formula used to compute shininess from alpha is just an ad-hoc formula
    that produces *useful* linearites across the alpha range; --with gradual change
    at the bottom of the curve, but rising fast at the top. Almost linear with the
    radius of specular light-spots, but not quite. Input and output are vec2, so
    that two shininesses (one for metallic, one for dielectric specularities) are
    computed in one shot. Using the formula (1.0625+x)/(1.0625-x) cubed. */
    vec2 temp1 = vec2( 1.0625 );
    vec2 temp2 = (temp1+lin_gloss) / (temp1-lin_gloss);
    temp1 = temp2 * temp2 * temp2;
    /*  tests:
     Alpha  Shininess Angular radius of specular highlights
      0/256     1.000 67.08
      1/256     1.022 66.35 1.10% angular decrement
     32/256     2.032 47.06
     33/256     2.078 46.53 1.14%
     64/256     4.215 32.67
     65/256     4.315 32.29 1.18%
     96/256     9.141 22.19
     97/256     9.375 21.91 1.28%
    128/256    21.433 14.49
    129/256    22.051 14.29 1.40%
    160/256    57.385  8.86
    161/256    59.360  8.71 1.72%
    192/256   195.112  4.80
    193/256   203.928  4.70 2.13%
    224/256  1103.370  2.02
    225/256  1182.430  1.95 3.59%
    254/256 24953.974  0.42
    255/256 29791.000  0.39 7.69% */
    /* limit to 1 degree radius (shininess of 4500) by product over sum; so
    that point source lights don't become single pixels on reflections */
    vec2 temp3 = vec2( 4500.0 );
    return temp1 * temp3 / (temp1+temp3);
}
vec3 envMappingLOD( in vec3 direction, in float LoD )
{
    vec4 result = textureCubeLod( cubeMap, direction, LoD );
    return result.rgb * result.a;
}

//Per-light called subroutines and macros:

float selfshadow_step( in float cosa )
{
    float temp1 = 77.7 * cosa;
    float temp2 = temp1 * temp1;
    return 0.5 * temp1 / sqrt( 1.0 + temp2 ) + 0.5;
}
void soft_penumbra_NdotL
(
  in vec3 normal, in vec3 vnormal, in vec3 light,
  out float selfshadow, out float NdotL, out float vNdotL
)
{
    vec2 result;
    float cosa = dot( vnormal, light );
    result.x = dot( normal, light );
    result.y = cosa;
    float ss = selfshadow_step( cosa );
    result += vec2( 0.02 );
    result *= ( 0.97 * ss );
    vNdotL = clamp( result.y, 0.0, 1.0 );
    selfshadow = ss;
    NdotL = clamp( result.x, 0.0, sqrt(vNdotL) );
}
float fresnel( in float cosa, in float k )
{
   float tmp1 = sqrt(1.0-(1.0-cosa*cosa)/(k*k));
   float tmp2 = k*cosa;
   float tmp3 = k*tmp1;
   float tmp4 = (tmp1-tmp2)/(tmp1+tmp2+0.0001);
   tmp1 = (cosa-tmp3)/(cosa+tmp3+0.0001);
   return 0.5*(tmp1*tmp1+tmp4*tmp4);
}
void perlite
(
  in vec3 light, in vec3 normal, in vec3 vnormal, in vec3 reflection,
  in vec3 lightDiffuse, in float lightAtt,
  in float fresnel_blend, in float k, in vec2 ltd_glosses,
  inout vec3 DLacc, inout vec3 MSacc, inout vec3 FSacc
)
{
	float selfshadow, NdotL, vNdotL;
	soft_penumbra_NdotL( normal, vnormal, light, selfshadow, NdotL, vNdotL );
	//cos of reflection to light angle
	float RdotL = clamp( dot( reflection, light), 0.0, 4.0*vNdotL );
    //  precalculate some factors used more than once
    vec3 incident_light = lightDiffuse.rgb * lightAtt * selfshadow;
    float fresnel_refl = fresnel_blend * fresnel( NdotL, k );
    vec3 reflected_light = incident_light * fresnel_refl;
    vec3 refracted_light = incident_light * (1.0-fresnel_refl);
    float ltd_Mgloss = ltd_glosses.x;
    float ltd_Fgloss = ltd_glosses.y;
    //  * DL - diffuse light: Needs to be multiplied by
    //  (1-fresnel_blend*fresnel reflection), from light vector
    DLacc += ( NdotL * refracted_light );
    //  * MS - metallic specularity: Modulated by
    //  (1-fresnel_blend*fresnel reflection), also, and
    //  metallic shininess phong. And we also multiply by the
    //  shininess, as smaller spots get more light concentration
    MSacc += ( pow( NdotL, ltd_Mgloss ) * ltd_Mgloss * refracted_light ); 
    //  * FS - fresnel specularity: Doesn't need fresnel, really,
    //  as the only fresnel applicable is view-vector-dependent,
    //  which can be applied afterwards, to the accumulated value;
    //  so, we'll multiply the accumulator by view fresnel after...
    FSacc += ( pow( NdotL, ltd_Fgloss ) * ltd_Fgloss ); //*reflected_light);
}
#define lighting(name, lightno_gl, lightno_tex) \
void name( \
   in vec3 normal, in vec3 vnormal, in  vec3 reflection, \
   in float k_blend, in float k_const, in vec2 limited_glosses, \
   inout vec3 DL_acc, inout vec3 MS_acc, inout vec3 FS_acc) \
{ \
    perlite( normalize(gl_TexCoord[lightno_tex].xyz), \
      normal, vnormal, reflection, \
      gl_FrontLightProduct[lightno_gl].diffuse.rgb, \
      gl_TexCoord[lightno_tex].w, \
      k_blend, k_const, limited_glosses, \
      DL_acc, MS_acc, FS_acc); \
}
lighting(lite0, 0, 5)
lighting(lite1, 1, 6)

//final blend subroutines:

vec3 multibounce_color( in vec3 color, in float refl_factor, in float blend )
{
    /* After light's penetrated the outer dielectric & is about to hit the inner, opaque
    layer below, instead of *= color, use this to account for multiple inner bouncings
    The formula is: *= (c-refL*c)/(1-refL*c), where refL is the fresnel reflectivity and
    c is the color of the material under the dielectric coating. But blended materials,
    such as plastics, are only partially covered by a specular dielectric layer, so we do
    have to allow some pure color reflectivity; thus the "blend" thing... */
    vec3 temp = color * refl_factor;
    return blend*(color-temp)/(vec3(1.0)-temp) + (1.0-blend)*color;
}
vec3 final_blend
(
 in vec3 DLacc, in vec3 MSacc, in vec3 FSacc, //DL=DiffuseLight; MS=MetallicSpec; FS=FresnelSpec
 in vec3 AMBenv, in vec3 MSenv, in vec3 FSenv, //Environment mapped counterparts
 in vec3 view_vec, in vec3 norm_vec, in vec3 glow,
 in vec3 diff_color, in vec3 spec_color,
 in float dielectric_blend, in float dielectric_k, in float AO
)
{
    float NdotV = clamp( dot( norm_vec, view_vec ), 0.0, 1.0 );
    float AO_fresnel_reflection = (1.0-dielectric_k)/(1.0+dielectric_k );
    AO_fresnel_reflection *= AO_fresnel_reflection;
    float reflection = fresnel( NdotV, dielectric_k );
    float diffAOfactor = sqrt(AO);
    float MspecAOfactor = AO * AO;
    float FspecAOfactor = AO * diffAOfactor;
    //Begin with the accumulated direct light (diffuse lighting)
    vec3 final_acc = (DLacc*diffAOfactor);
    //Add ambient light minus fresnel-reflected (note that amb reflection IS the envmapping)
    final_acc += ( AMBenv * AO * (1.0-AO_fresnel_reflection) );
    //multiply by the diffuse color
    final_acc *= multibounce_color( diff_color, reflection, dielectric_blend );
    //MSenv is multiplied by 1-fresnel to account for partial reflection on entering dielectric
    final_acc += (  ( MSacc + (MSenv*(1.0-reflection)) ) *
         multibounce_color( spec_color, reflection, dielectric_blend ) * MspecAOfactor  );
    //Both diffuse and metallic spec have to exit the dielectric. So, we'd multiply by the
    //refraction, here. However, multibounce_color() already took care of it, so, nought to do.
    //We just add fresnel specularity and... By the way, NOW we will multiply by fresnel
    //reflectivity from view angle --remember we didn't in perlite():
    final_acc += ( (FSacc+FSenv) * dielectric_blend * reflection * FspecAOfactor );
    return final_acc + glow;
}

//main:

void main()
{
    //READ INTPUT DATA:
    //get interpolated, per-vertex data
    vec2 texcoords2 = gl_TexCoord[0].xy;
    vec3 vnormal_v3 = fastnormalize( gl_TexCoord[1].xyz );
    vec3 tangent_v3 = gl_TexCoord[2].xyz;
    vec3 cotangent_v3 = gl_TexCoord[3].xyz;
    vec3 eye_v3 = gl_TexCoord[4].xyz;
    //get texture data needed for detail and normal computations first
    vec4 DMG_in4 = texture2D( damgMap,texcoords2 );
    vec4 DET_in4 = texture2D( detailMap,16.0*texcoords2 );
    vec4 NOR_in4 = texture2D( normMap,texcoords2 );
    //then the rest
    vec4 SPC_in4 = texture2D( specMap,texcoords2 );
    vec4 COL_in4 = texture2D( diffMap,texcoords2 );
    vec4 GLO_in4 = texture2D( glowMap,texcoords2 );
    // computed vectors
    vec3 reflection_v3 = -reflect(eye_v3,vnormal_v3);
    //UNPACK:
    //we use a macro table to ease possible future changes to the texture packing:
    #define _matcolor_in_ ((COL_in4.rgb))
    #define _matalpha_in_ ((COL_in4.a))
    #define _damage_dUdV_ ((DMG_in4.rb))
    #define _detailblend_ ((DMG_in4.g))
    #define _damageAOdrk_ ((DMG_in4.a))
    #define _specdiffbal_ ((SPC_in4.r))
    #define _dielblendin_ ((SPC_in4.g))
    #define _dielectrkin_ ((SPC_in4.b))
    #define _shininessin_ ((SPC_in4.a))
    #define _glowcolorin_ ((GLO_in4.rgb))
    #define _ambientoccl_ ((GLO_in4.a))
    #define _normalmapin_ ((vec2(0.3333*(NOR_in4.r+NOR_in4.g+NOR_in4.b),NOR_in4.a)))
    #define _detail_dUdV_ ((DET_in4.rb))
    #define _detail_wild_ ((DET_in4.g))
    #define _detailgloss_ ((DET_in4.a))
    /* The most urgent item to unpack is the detail texture data because at its minimum
    level, detail provides dithering to hide DXT quantization; but such dithering needs
    to be applied before non-linear transformations. Keep in mind that all four rgba
    channels of the detail texture will be scaled to use the full 0-1 range. Minimum
    detail application to a channel will be where full range matches 1 channel step. */
    ///////////////////////////////////////////////////////////////////////////
    //CORE SHADER A.I. --MATERIAL FAMILY DETECTION:
    //characterize the material to determine how to interpret shininess, detail, etc.:
    float ismetal_ch1 = is_metal_decode( _specdiffbal_ );
    //"nonzerok" is short for "has dielectric k greater than 1.2 or so"
    float nonzerok_ch1 = nonzerok_decode( _dielectrkin_ );
    //dielectric blend to shininess relevance factor:
    float relevance_factor = DBSRF( _dielblendin_, _shininessin_ );
    ///////////////////////////////////////////////////////////////////////////
    //Manage distribution of detail texture application:
    float bump_det_fac1, nonbump_det_fac1;
    // decide: bumpy detail or textury detail?
    detail_blend_decode( _detailblend_, bump_det_fac1, nonbump_det_fac1 );
    // metallic vs non-metallic textury detail deciding fate of detail.green:
    float dielectricblend_detail = ismetal_ch1 * nonbump_det_fac1;
    float diffuse_detail = nonbump_det_fac1 - dielectricblend_detail;
    // metallic shininess detail mostly deciding fate of detail.alpha:
    float adjusted_gloss = nonbump_det_fac1 * make_signed(_detailgloss_);
    float gloss_detail = ismetal_ch1 * adjusted_gloss;
    // for non-metals, dilectric balance vs shininess relevance spells fate of detail.alpha:
    dielectricblend_detail += ( (adjusted_gloss - gloss_detail) * relevance_factor );
    //Apply details and damage:
    float damage = cloakdmg.b;
    float integrity = 1.0 - damage;
    // to normal:
    vec2 dUdV_in2 = dUdV_first_decode(_normalmapin_);
    dUdV_in2 += ( dUdV_first_decode(_damage_dUdV_) * damage );
    dUdV_in2 += ( dUdV_first_decode(_detail_dUdV_) * (bump_det_fac1+1.0/32.0) );
    // to diff/spec balance and glow:
    float diffuse_jitter = (diffuse_detail+1.0/32.0) * make_signed(_detail_wild_);
    float specdiffbal_in1 = _specdiffbal_ + diffuse_jitter;
    vec3 glow_in3 = _glowcolorin_ + vec3( diffuse_jitter );
    // to shininess:
    float s_gloss_det = make_signed(_detailgloss_);
    float shininess_in = _shininessin_ + (gloss_detail+1.0/256.0)*s_gloss_det;
    // to dielectric blend:
    float dielectricblend_in1 = _dielblendin_ + (dielectricblend_detail+1.0/64.0)*s_gloss_det;
    // to ambient occlusion:
    float AO_darkener1 = lerp( damage(), 1.0, _damageAOdrk_ );
    float ao_mat1 = _ambientoccl_ * AO_darkener1;
    //Non-linear transformations, rangings, and any unpacking left:
    // diffuse, alpha and specular:
    vec3 spec_mat3 = _matcolor_in_ * _specdiffbal_;
    vec3 diff_mat3 = _matcolor_in_ - spec_mat3;
    vec3 glow_mat3 = glow_in3 * glow_in3 * inv_damage(); //de-gamma & damage fade
    // shininess CTRL goes to metallic spec for metals; dielectric gloss for non-metals;
    // and the defaults are min for both; except when dielectric k is 0/trivial we want to
    // max out shininess for fgloss, as it will be used for dual specularity metals
    vec2 lin_gloss2, gloss_lod2, glosses2;
    distribute_gloss( ismetal_ch1, nonzerok_ch1, shininess_in, lin_gloss2 );
    gloss_lod2 = lin_gloss_2_LOD( lin_gloss2 );
    glosses2 = lin_gloss_2_exp( lin_gloss2 );
    // compute final normal
    vec3 tmp3 = dUdV_final_decode( dUdV_in2 );
    vec3 normal_v3 = imatmul( tangent_v3, cotangent_v3, vnormal_v3, tmp3 );
    // dielectric stuff:
    float dielec_blend_mat1 = dielectricblend_decode( dielectricblend_in1 );
    float dielectric_k_mat1 = dielectric_decode( _dielectrkin_ );
    // LOD for ambient lighting:
    float ambient_lod1 = ambient_LOD( dielectric_k_mat1 );
    //texture fetches (dependent on normal)
    vec3 ambenv_il3 = envMappingLOD( normal_v3, ambient_lod1 ); //ambient env mapping
    vec3 MSenv_il3 = envMappingLOD( reflection_v3, gloss_lod2.x ); //metallic spec env mapping
    vec3 FSenv_il3 = envMappingLOD( reflection_v3, gloss_lod2.y ); //fresnel spec env mapping
    //END OF UNPACKING
    ///////////////////////////////////////////////////////////////////////////
    //PER-LIGHT COMPUTATIONS
    // initialize accumulators
    vec3 DL_acc3, MS_acc3, FS_acc3;
    DL_acc3 = MS_acc3 = FS_acc3 = vec3( 0.0 );
    // then loop:
    if( light_enabled[0] != 0 )
      lite0
      (
        normal_v3,vnormal_v3,reflection_v3,
        dielec_blend_mat1,dielectric_k_mat1,glosses2,
        DL_acc3,MS_acc3,FS_acc3
      );
    if( light_enabled[1] != 0 )
      lite1
      (
        normal_v3,vnormal_v3,reflection_v3,
        dielec_blend_mat1,dielectric_k_mat1,glosses2,
        DL_acc3,MS_acc3,FS_acc3
      );
    //FINAL BLEND
    //////vec3 reflection_v3 = -reflect(eye_v3,vnormal_v3);
    vec4 result4;
    result4.rgb = final_blend
    (
      DL_acc3, MS_acc3, FS_acc3, ambenv_il3, MSenv_il3, FSenv_il3,
      eye_v3, vnormal_v3, glow_mat3, diff_mat3, spec_mat3,
      dielec_blend_mat1, dielectric_k_mat1, ao_mat1
    );
    result4.a = _matalpha_in_;
    //ALPHA and CLOAK
    result4.rgb *= _matalpha_in_; //mul by 1-bit alpha interpolated
    result4 *= cloak_alpha();
    //WRITE
    gl_FragColor = result4;
}
Here's also my modified modelview.system:

Code: Select all

<system name="Modelview" background="backgrounds/blue" nearstars="500" stars="1000" starspread="150" scalesystem="1000">
<Light>
	<ambient red="0.000000" green="0.000000" blue="0.000000"/>
	<diffuse red="0.5" green="0.5" blue="0.5"/>
	<specular red="0.5" green="0.5" blue="0.5"/>
</Light>
<Light>
	<ambient red="0.000000" green="0.000000" blue="0.000000"/>
	<diffuse red="0.5" green="0.5" blue="0.5"/>
	<specular red="0.5" green="0.5" blue="0.5"/>
</Light>
<Planet name="Cephid_17 A" file="stars/white_star.texture" ri="0.000000" rj="0.000000" rk="0.000000" si="0.000000" sj="0.000000" sk="0.000000" radius="746000.000000" x="0" y="0" z="0"  Red="0.5" Green="0.5" Blue="0.5" ReflectNoLight="true" light="0">
</Planet>
</system>
@Fendorin: CineMut is a family of shaders, coming soon. They will require a new texture packing; but will allow you to specify "Real Materials", like you'll be able to have part of the ship using titanium, and then you could have a part of the ship that's painted gray, high gloss; and next to it a piece of gray plastic; and all three materials will look gray, yet they will look distinctly like metal, paint and plastic.
Last edited by chuck_starchaser on Fri Aug 29, 2008 1:02 am, edited 1 time in total.
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 »

CineMut is a shader family, or simplified just a name for a shader, like highend, or default.
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:Where did you get the shader from?
I've got the the shader from one of your previous posts. Is this shader the CIneMut_Opaque? since the header says highend. Anyway with this one the bike is completely transparent = not visible at all.

*EDIT*
chuck_starchaser wrote:Those textures are not compressed; well, they are png-compressed; non-lossy.
I meant to ask which compression should they have for submission to data. You were assuming that there is such-and-such amount of bits available for each channel with DXT compression. For testing I have been using DXT5 compression. Is this ok for all textures?
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Post by chuck_starchaser »

That's really strange; I've no idea what would make the bike transparent, and I'm really drunk now. Maybe tomorrow night we can go step by step making sure your setup and mine are the same.
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 »

That *would* be cool. But I'll be out during weekend and next week might become very busy off-vs-life. Let's do it step-by-step here.
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Post by chuck_starchaser »

Alright, I'll try, but restaurants are about to close; I gotta go there now; I'll be back in an hour. You need the technique, the shader, the .system file, the line in units.csv, the bfxm, and the textures. The textures are presently all .png's. If you have the last posted of all these items, you should be good to go. One more: you need the environment map. No you don't; we were using the standard spheremap. That's why it looked like shit. As soon as I get back from dinner I'll try my shader setup again.
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:You need the technique, the shader, the .system file, the line in units.csv, the bfxm, and the textures. The textures are presently all .png's.
I have all that. Only I have dds compressed the textures and maybe just should try with the original png.
klauss
Elite
Elite
Posts: 7243
Joined: Mon Apr 18, 2005 2:40 pm
Location: LS87, Buenos Aires, República Argentina

Post by klauss »

When I get home, and that may be tomorrow, I'll post my latest versions of all. The problem with the black spots seem to suggest (thought may be anything else) that you're using a cubemap-like shader with a spheremap-like executable.
Oíd mortales, el grito sagrado...
Call me "Menes, lord of Cats"
Wing Commander Universe
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 »

Indeed, it looks like the shader is requiring CubeMap and I'm running on the latest trunk svn, which does not have your cubemap suport yet.
klauss
Elite
Elite
Posts: 7243
Joined: Mon Apr 18, 2005 2:40 pm
Location: LS87, Buenos Aires, República Argentina

Post by klauss »

I didn't commit it into trunk, I ran out of space on my HD for the required extra checkout ;)
It's on the audio branch.
Oíd mortales, el grito sagrado...
Call me "Menes, lord of Cats"
Wing Commander Universe
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 »

If it's just a matter of committing the corresponding files, i can do it:

Code: Select all

  Modified   /branches/audio/vegastrike/src/gfx/aux_texture.cpp
  Modified   /branches/audio/vegastrike/src/gfx/mesh_gfx.cpp
  Modified   /branches/audio/vegastrike/src/gfx/aux_texture.h
  Modified   /branches/audio/vegastrike/configure.ac
A better practice would be to commit minor changes directly to trunk (or synch trunk with your branch after commit) so that they are immediately available to the community.
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Post by chuck_starchaser »

pyramid wrote:Indeed, it looks like the shader is requiring CubeMap and I'm running on the latest trunk svn, which does not have your cubemap suport yet.
What I don't understand, Klauss, is how it ended up that my latest copy of the shader is set up for cubemaps, when in fact we never had cubemaps working, or did we? I'll see if I can revert it to use spheremaps, in the meantime. What I'm worried is probably the technique has to change (back) also?
charlieg
Elite Mercenary
Elite Mercenary
Posts: 1329
Joined: Thu Mar 27, 2003 11:51 pm
Location: Manchester, UK
Contact:

Post by charlieg »

You guys badly need some kind of versioning for this.

Register a googlecode.com or sharesource.org project (instant registration) and then you can work on it in isolation and branch etc and notably have an easy way of testing different versions of the shader and sharing the shader with other open source projects.
Free Gamer - free software games compendium and commentary!
FreeGameDev forum - open source game development community
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Post by chuck_starchaser »

Damn! You're so right! And we got SVN at the junction server; I could have set up a repo for shader work. I'll try to get it set up today.
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 »

Note: this is kinda off-topic, but I couldn't find a proper dev thread for cubemaps.

I've got vs compiled successfully on linux with cubemap support (assuming the 4 files above are representing all the required changes).

Now I get the following error when executing:

Code: Select all

vegastrike: src/gldrv/gl_state.cpp:61: GLenum GetGLTextureTarget(TEXTURE_TARGET): Assertion `false' failed.
I've put the blue.dds cubemapped texture by chuck (I found in this thread, I think) named as blue.texture into the textures/backgrounds folder and changed the system background statement to ="backgrounds/blue".. Seems not to be right.

What is the actual naming/folder schema for cubemapped background textures?
Post Reply