Home Technical Talk

Shader - UV-less Anistropic shader?

polycounter lvl 12
Offline / Send Message
Ace-Angel polycounter lvl 12
Hey peeps,

As the title says, I was wondering if anyone knew of any paper that discussed the code of a UV-less Aniso shader, which worked more with the pixel/vertex information and Normal maps.

Cheers.

Replies

  • Farfarer
    Options
    Offline / Send Message
    Doesn't Ward allow that?

    Wrote one for someone a while back, but I've not got access to the shader code right now :/
  • chronic
    Options
    Offline / Send Message
    chronic polycounter lvl 10
    ati's rendermonkey tool has an example of one
  • Ace-Angel
    Options
    Offline / Send Message
    Ace-Angel polycounter lvl 12
    @Far: No idea which Ward you mean, sorry. I tried Aniso-Ward, but it still needs UV's in my case, based upon this code here: http://content.gpwiki.org/index.php/D3DBook:%28Lighting%29_Ward

    Here is an example in node format what the shader might look like, and the UV edge issue that can pop up ( in UDK for example: http://www.polycount.com/forum/showthread.php?t=102440 )

    @Chronic: That might be the solution, but I'm lost in this part:
    // Grab an angle to rotate the tangent around the normal
    // This is done to create a slightly bumpy feeling
    float angle = noiseScale * (texture3D(Noise, vPos) - 0.5).x;

    // Our angle is within the [-PI, PI] range and we need both
    // the sine and cosine. Perfect for the sincos function,
    // which will save us some hardware instructions over separate
    // sin and cos calls.
    float cosA, sinA;
    sinA = sin(angle);
    cosA = cos(angle);


    // Rotate tangent around the normal
    vec3 tang = sinA * vTangent + cosA * vBinormal;

    // Do the anisotropic lighting
    float diffuse = clamp( dot( oglLightDir.xyz, vNormal ), 0.0, 1.0 );
    float cs = -dot(viewVec, tang);
    float sn = sqrt(1.0 - cs * cs);
    float cl = dot(oglLightDir.xyz, tang);
    float sl = sqrt(1.0 - cl * cl);
    float specular = pow( clamp( (cs * cl + sn * sl), 0.0, 1.0 ), 32.0);

    I don't understand what they mean by "sinA = sinAngle" with Pi being involved, since it looks like they're using a 3DTexture to project the 'Bump' map? To which I don't have access to my other application.

    Also, almost forgot, my Unwrap's of my models don't face all the same direction, which is what I'm trying to avoid in the first place.

    I hope I'm not coming off too problematic, it's just that it's been frustrating me for about a week with his issue.
  • chronic
    Options
    Offline / Send Message
    chronic polycounter lvl 10
    I dont have the ability to explain the fine details of how that aniso function works, but here are some ideas

    the angle is in radians, thats why they reference PI, except instead of being 0 to 2PI its -PI to PI but this doesn't really matter I think

    you dont need to worry about the 3dtexture, the angle can be a user input float value

    sin and cos are translating angle into -1 to 1 values

    here is a compact version of the relevent code, maybe that helps more
    //adapted from anisotropic.fx from ati rendermonkey example file - based on Steve Westin Brushed Metal work
    float3 anisotropic (float3 normalTexture, float3 L, float3 V, float3 N, float3 Bn, float3 Tn, float roughness, float angle)
    {
      float cosA, sinA;
      sincos(angle, sinA, cosA); //gives back the sin of angle and cos of angle into sinA and cosA variables - faster than doing each seperatly
      float3 Ta = sinA*Tn + cosA*Bn;
      if(useNormalMap) Ta = sinA*(Tn*normalTexture.r) + cosA*(Bn*normalTexture.g); //vary the world normal and binormal by the texture normalmap x and y - but dont remap the normalmap to -1,1  keep as 0,1 - dont normalize it will negate the effect of multiply by scalar
      float cs = -dot(V, Ta);
      float sn = sqrt(1 - cs * cs);
      float cl = dot(L, Ta);
      float sl = sqrt(1 - cl * cl);
    
      return pow(max(0.f,cs*cl + sn*sl), roughness);
    }
    
  • Ace-Angel
    Options
    Offline / Send Message
    Ace-Angel polycounter lvl 12
    Hey Chronic,

    Much appreciated for the quick write up, but unfortunately I don't have access to Sincos function in my app, only low level math, would it be possible to to get said 'function' with low level math?

    Cheers.
  • JamesWild
    Options
    Offline / Send Message
    JamesWild polycounter lvl 8
    Got a list of the methods you have access to? It looks like it just does a sin and cos of the same angle to me, and could be replaced by:

    sinA = sin( angle );
    cosA = cos( angle );

    But I'm guessing you know that and don't have sin/cos...
  • chronic
    Options
    Offline / Send Message
    chronic polycounter lvl 10
    It is beyond my skill to rewrite that function without the sin, cos, and i dont think it would be possible anyways.

    I always wanted to try using a carefully crafted lit-sphere image to fake an anisotropic highlight, the downside is it would not change with the direction of the lights but maybe thats ok. just make your lit-sphere image black and white and you can add it on top of your other shading just like you would do with the normal spec. you could even control rotation interactivly to some degree by spinning the image around its center (instead of repainting the image).
  • equil
    Options
    Offline / Send Message
    you don't need sin/cos for this.

    technically you're gonna end up using the UVs anyway since a bivariate distribution (stretched in 2 dimensions. what ward/ashikhmin-shirley/bivariate beckmann etc does) relies on the tangent and bitangent, which in turn are calculated from the uvs, so i'm not sure what you mean. the models don't really care about the uvs as long as you have those 3 vectors though (normal, tangent, bitangent), so one way is to simply feed in a tangentmap with your normalmap (and calculate the bitangent in the shader). then you can at least have per-pixel anisotropic directions, if that's what you're after.
  • Ace-Angel
    Options
    Offline / Send Message
    Ace-Angel polycounter lvl 12
    @James: I do, but I think they're broken :(

    @Chronic: Haha, that's an idea I can do, will try, cheers!

    @Equil: Yeah, I think you're right, I will paint an Aniso direction map my UV islands instead, should do the trick, cheers!
Sign In or Register to comment.