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

## 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

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

##### Share on other sites

pretty cool, seems perfect for shading metalsurfaces in dark zones with lights.

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 14
• 30
• 9
• 16
• 22