Jump to content
  • Advertisement
Sign in to follow this  

Spectral Accumulation Shader

This topic is 2084 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all,


My name is Vladeta Stojanovic and I'm currently working as a research assistant in visualisation and modelling at Abertay University (where I studied the undergrad Computer Games Technology). When not working on work related projects, I work on my own game prototypes and like to experiment with different rendering methods. In terms of shader programming, I'm very much influenced by the "cheap and easy" demo scene way of writting shader effects tongue.png

While messing around yesterday I came up with this shader (I decided to call it the "Spectral Accumulation Shader"). I discovered this somewhat by accident, as I originally wanted to write a simple Lambert diffuse shader and mess around with it (using some Blinn shading variations). 

Below is a screenshot of the shader used on standard testing models (Utah teapot, skull and the Stanford dragon):


And here is the HLSL code (compiled using shader model 3.0 and tested in XNA 4.0):


float4 _SpectralAccumShader(float3 _normal, float3 _eyeVector, float3 _vertexPosition, int occSteps, int spectralBands, float highlight_value) 
    float4 outColor = float4(0, 0, 0, 0);

    float3 lambert = saturate(dot(_normal, _eyeVector)); //switch eyeVector to lightPosition if using static light

    float3 halfway = normalize(lambert + eyeVector);

    float3 spectralMap = halfway - _normal;

    float3 depthMap = _vertexPosition / 100.0f;

    float occDistance = length(normalize(depthMap)); 
    float specDistance = length(normalize(spectralMap)); 

    for (int i = 0; i < occSteps; i++) 
        occDistance += dot(_normal, depthMap); 
        specDistance += dot(_normal, spectralMap); 

    occDistance /= occSteps;
    specDistance /= occSteps;

    float3 diffuseResult = float3(occDistance + specDistance, occDistance + specDistance, occDistance + specDistance);

    float3 spectralResult = diffuseResult;

    //Accumulate the colour spectrum
    for (int j = 0; j < spectralBands; j++) 
        //spectralResult *= cross(diffuseResult, spectralMap); //object space
        spectralResult *= cross(spectralMap, diffuseResult); //world space

    outColor = saturate(float4((diffuseResult * highlight_value) * spectralResult, 1.0f));

    return outColor;

I would like to get some feedback from the graphics experts on here if possible. You can feel free to use this shader in your own applications, as I would really like to see if other people can find good use for this technique. 

On a side note, I guess you can say that this is a cheap approximation of the Thin Film Interference shader presented in this article. I was recently also working on a ambient occlusion shader using the Optix API, thus this influenced me the idea of "banding" or accumulating different surface colour values. 

You can also check out more of my work on my website/portfolio

- Vlad

Edited by vlad_s

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!