# Procedural Planets and Interference with other Shaders

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

## Recommended Posts

Hi all, it's been a while since I visited the forums, but lately I've been a bit bored so I pulled out one of my old game engines and started tinkering. So, for the last couple days I've been building a pretty nice procedural planet algorithm, details below. I'm actually very pleased with the results from the procedural planets, but for some reason the planet shader doesn't play nice with another shader I'm using, a custom shield shader for the ships.

But before I get into that, here's some pretty pictures of the procedural planets I'm generating:
[sharedmedia=gallery:albums:341]

Basically I'm using the technique described in GPU Gems with 8 octaves of noise, but with 3D wavelet noise instead of perlin noise and some fancy interpolation between bands (using a mixture of additive and multiplicative). Every aspect of the process is deterministically randomized from a seed integer, including lighting parameters, diffuse/specular colors, noise band granularity, noise band weights, noise band interpolation models, and the degree to which the normals are perturbed by the normal map. The random values are initially evenly distributed from 0-1 then passed through filters to favor values that produce more realistic planets (for instance we typically don't want planets that are neon colors).

Particularly cool is the effect given by combining additive and multiplicative interpolation by evaluating both with different weights and linearly interpolating the result. This really increases the diversity of the look of the surface. A code sample is below:

float4 nAdd = float4(0, 0, 0, 0); float4 nMult = float4(1, 1, 1, 1); for (int x = 0; x < BandCount; ++x) { // NOTE: the noise lookup in this code example is 4D because it includes a 3D normal for normal mapping along with the 1D noise float4 lookup = NoiseLookup(pos * BandScales[x]); nAdd += lookup * AdditiveWeights[x]; nMult *= lookup * MultiplicativeWeights[x]; } return nAdd * AdditiveBlend + nMult * (1 - AdditiveBlend);

However, like I said I'm a bit stumped by a wierd artifact I'm getting. The custom shield shader (shown below) causes a very bizarre effect on the planet, and I can't seem to figure out why. If I don't draw any shields, the wierdness goes away and we see pretty planets. Example:
[sharedmedia=gallery:images:1518]

At this point I suspect it must be something that's turned on during the shield shader (e.g. alpha blending settings) and not turned off before the planet shader, but I can't seem to put my finger on it. The reason I suspect that: If I remove the following line from the shield.fx shader the queer artifacts go away:
AlphaBlendEnable = true;

I try to turn alpha blending off afterwards both with the XNA command and by putting AlphaBlendEnable = false in the planet shader, but no matter what I do the glitch still occurs.

Any ideas?

##### Share on other sites
Well, I found a way around it...

Not sure if it's an XNA glitch or what, but if I turn on alpha blending in the shader as opposed to in XNA I get this glitch no matter what I try to do to turn off alpha blending afterward. However, if I set alpha blending outside the shader with XNA like so all is well.

Common.Game.GraphicsDevice.BlendState = BlendState.AlphaBlend;

Anyway, still feel free to comment or ask questions and/or give suggestions about procedural planets.

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

• 11
• 15
• 21
• 26
• 11