Skidmarks and shaders

Alexander Knoll

NEVER GIVE UP!!
Hello all,
i know this is a old tread, and maybe the wrong place for my question, so sorry at first...
ok now...i'm playing many times with track conversions, as you know, and many times i'm using skidmarks at some places...braking markers etc...the most time it looks ok, but some times its to weak and you nearly can't see them....i use this shader:

shader_skid~vf_standard_transparent
{
sort_offset=2
layer0
{
map=skid.dds
blendfunc=blend
alphafunc=greater 10
depthwrite=0
depthfunc=lequal
}
}


...is there a way without editing the texture to make them less visible?
Here a pic to show what i try to explain...the marks in the middle are from Racer, left and right are my test skids...



THX for help...

Alex
 
I think their appearance is totally driven by the alpha map because of the blendfunc=blend.

I'm not sure you really need alphafunc here unless you have lots of them overlapping... though I can't be 100% sure.
I've just been messing with transparency stuff again recently for my wire fence shading and the results can often be quite contrary to what you'd expect.

What does depthfunc=lequal do? I didn't even know a depthfunc existed these days...!?


But any way, I think you'll need to edit the texture. Can you show us the texture?

Really we need a new texture/shader for skids... one that controls gloss too...

Rubber can be hard coded as a rubber albedo value, then red can control say gloss, green can do specular (if you want to have details in the actual mark I suppose), and blue can do the mask...

Hmmm. I think Camsinny and I did one a few years back but never got around to posting it up. It probably needs more tweaks but it's probably well worth using over any current shaders you might be considering...


Ah, this is where Camsinny and I got to:
Code:
//
// Standard, but burns through the alpha channel
// Useful for road specularity where you use the alpha channel as a specular map.
//

#include "../../../renderer/shaders/atmosphere.cg"
#include "../../../renderer/shaders/lighting.cg"
#include "../../../renderer/shaders/shadowmapping.cg"

// Vertex to pixel shader structure
struct v2p
{
  //float3 Position            : POSITION;
  float4 Position            : TEXCOORD4; //POSITION;
    //float3 Color             : COLOR;
    float3 normal           : TEXCOORD5;
    float3 RayleighColor    : TEXCOORD2;
    float3 MieColor            : TEXCOORD3;
    float3 tc0              : TEXCOORD0;
    float3 Direction        : TEXCOORD1;
    float  extinction        : TEXCOORD6;
};

void main(
  // In
  in v2p IN,

  // Out
  out float4 outColor : COLOR0,
#ifdef CSM_MRT
  out float4 outShadow : COLOR1,
#endif

  // Constants
  uniform sampler2D baseMap : TEXUNIT0,
  uniform float3    lightDirection,
  uniform float3    lightColor,
  uniform float3    lightAmbient,
  uniform float3    eyePosW,
  uniform float     atmosRayleigh,
  uniform float     atmosMie,
  uniform float3    Ke,
  uniform float3    Ka,
  uniform float3    Kd,
  uniform float3    Ks,
  uniform float     shininess,
  uniform float     sunny,
  uniform float     exposure
#ifdef CSM
  // shadow mapping
,uniform sampler2D    shadowArray  : TEXUNIT7,
  uniform float4x4                smTexMatArray[SM_MAX_SPLITS],
  uniform float smSplits
#endif
)
{
  float3 skyColor;

#ifdef CSM
  // Output shadowing and normals
  float shadow = GetShadowFactor(IN.Position, IN.normal,shadowArray, smTexMatArray, smSplits, lightDirection)*sunny;
  //outShadow.rgb = IN.normal;
#else
  const float shadow=1;
#endif

  // Get sky gradient color
  skyColor.rgb=GetSkyColor(lightDirection,IN.Direction,IN.RayleighColor,IN.MieColor,atmosRayleigh,atmosMie,lightColor,lightAmbient);

  // Get base texture color
  float4 baseCol=tex2D(baseMap,IN.tc0);

  // Specular map
  Ks*=baseCol.a;
  shininess/=(baseCol.a*8);

  // Lighting
  float3 ambient,diffuse,specular;
  LightingSun(Ke,Ka,Kd,Ks,shininess,lightDirection,lightColor,lightAmbient,IN.Position,IN.normal,eyePosW,
    ambient,diffuse,specular);
  float3 sdColor=baseCol*diffuse+specular; //*baseCol.a;
  float3 ambientColor=baseCol*(ambient+Ke);
  //float3 ambientColor=(baseCol*(ambient+Ke))+(lightAmbient*baseCol.a*Ks);
  //baseCol.rgb=baseCol*(ambient+Ke)+baseCol*diffuse+(specular*((int)outShadow.a))*baseCol.a;

  // HDR toning of sky
  //skyColor.rgb=1.0-exp(-exposure*skyColor.rgb);

#ifdef CSM_MRT
  // Mix sky with texture color based on atmospheric influence
  outColor.rgb=lerp(skyColor,ambientColor,IN.extinction);
  //outShadow.rgb=lerp(skyColor,sdColor,IN.extinction);
  outShadow.rgb=sdColor*IN.extinction;
  outShadow.a=shadow;

  // Blending
  outColor.a=baseCol.a;
#else
  // Mix sky with texture color based on atmospheric influence
  outColor.rgb=lerp(skyColor,ambientColor+sdColor*shadow,IN.extinction);
  // Blending
  outColor.a=baseCol.a;
#endif
}
Code:
vf_spec_gloss_a
{
  vertex_shader
  {
    file=standard_v.cg
  }
  fragment_shader
  {
    file=cg/standard_burn_gloss_a_f.cg
  }
}

Code:
shader_skids~vf_spec_gloss_a
{
  shininess=250
  specular=0.55 0.55 0.55 1
  layer0
  {
    map=texture\skids.tga
    ;blend makes it look very nice but maybe a bit slower?
    blendfunc=blend
    ;alpha to coverage and alphafunc  make it faster but ugly!
    ;alpha_to_coverage=1
    ;alphafunc=gequal 50
  }
}


It could probably be tweaked/updated more... just fiddle around with textures to get the 'look' you want.

Here it just sees a heavier alpha as more glossy and more opaque... which is possibly not correct but it's close enough it feels. Ideally you could optimise this shader loads as per rgb channel split and hard coded albedo for rubber.

From memory my texture was just solid black rgb (probably should be more like very dark black like 5,5,5 rgb or something)
Alpha texture I just drew with my graphics tablet with a special brush... I just built up lots of lighter layers and then increasingly fewer more heavy layers for the really heavy skid marks.

In the end it looked pretty ok! Obviously with lots of time you could make it look super nice!

Dave
 

Latest News

Online or Offline racing?

  • 100% online racing

    Votes: 76 7.1%
  • 75% online 25% offline

    Votes: 114 10.7%
  • 50% online 50% offline

    Votes: 155 14.6%
  • 25% online 75% offline

    Votes: 293 27.5%
  • 100% offline racing

    Votes: 422 39.7%
  • Something else, explain in comment

    Votes: 4 0.4%
Back
Top