• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Hyunkel

Sean O'Neils atmospheric scattering

14 posts in this topic

I'm trying to implement Sean O'Neils atmospheric scattering as explained here:
[url="http://http.developer.nvidia.com/GPUGems2/gpugems2_chapter16.html"]http://http.develope..._chapter16.html[/url]

My final goal is to combine his scattering shaders into a single shader that operates in screen space, without the need of additional geometry (such as a sphere for the atmosphere).
I think this shouldn't be too hard to do in a deferred renderer, where I can easily calculate the surface position of the atmosphere sphere.

Anyways, before I can tackle this task, I first need a working implementation of Sean O'Neils shaders.
I downloaded the shaders he provided with the GPU Gems article and decided to start with the "SkyFromSpace" shader.
Translating the shader into hlsl (or rather a dx effect) was rather straightforward:

[CODE]
// The number of sample points taken along the ray
static const int nSamples = 2;
static const float fSamples = (float)nSamples;
// Gravity
static const float g = -0.98f;
static const float g2 = 0.9604f;
// Shader Constants
float4x4 WorldViewProjection;
float3 v3CameraPos; // The camera's current position
float3 v3LightPos; // The direction vector to the light source
float3 v3InvWavelength; // 1 / pow(wavelength, 4) for the red, green, and blue channels
float fCameraHeight; // The camera's current height
float fCameraHeight2; // fCameraHeight^2
float fOuterRadius; // The outer (atmosphere) radius
float fOuterRadius2; // fOuterRadius^2
float fInnerRadius; // The inner (planetary) radius
float fInnerRadius2; // fInnerRadius^2
float fKrESun; // Kr * ESun
float fKmESun; // Km * ESun
float fKr4PI; // Kr * 4 * PI
float fKm4PI; // Km * 4 * PI
float fScaleDepth; // The scale depth (the altitude at which the average atmospheric density is found)
float fInvScaleDepth; // 1 / fScaleDepth
float fScale; // 1 / (fOuterRadius - fInnerRadius)
float fScaleOverScaleDepth; // fScale / fScaleDepth
// The scale equation calculated by Vernier's Graphical Analysis
float scale(float fCos)
{
float x = 1.0 - fCos;
return fScaleDepth * exp(-0.00287 + x*(0.459 + x*(3.83 + x*(-6.80 + x*5.25))));
}
// Calculates the Mie phase function
float getMiePhase(float fCos, float fCos2, float g, float g2)
{
return 1.5 * ((1.0 - g2) / (2.0 + g2)) * (1.0 + fCos2) / pow(abs(1.0 + g2 - 2.0*g*fCos), 1.5);
}
// Calculates the Rayleigh phase function
float getRayleighPhase(float fCos2)
{
//return 1.0;
return 0.75 + 0.75*fCos2;
}
// Returns the near intersection point of a line and a sphere
float getNearIntersection(float3 v3Pos, float3 v3Ray, float fDistance2, float fRadius2)
{
float B = 2.0 * dot(v3Pos, v3Ray);
float C = fDistance2 - fRadius2;
float fDet = max(0.0, B*B - 4.0 * C);
return 0.5 * (-B - sqrt(fDet));
}
// Returns the far intersection point of a line and a sphere
float getFarIntersection(float3 v3Pos, float3 v3Ray, float fDistance2, float fRadius2)
{
float B = 2.0 * dot(v3Pos, v3Ray);
float C = fDistance2 - fRadius2;
float fDet = max(0.0, B*B - 4.0 * C);
return 0.5 * (-B + sqrt(fDet));
}
struct VS_IN
{
float3 Position : POSITION0;
};
struct PS_IN
{
float4 Position : SV_POSITION;
float3 PositionWS : TEXCOORD0;
};
PS_IN VS( VS_IN input )
{
PS_IN output = (PS_IN)0;
output.PositionWS = input.Position;
output.Position = mul(float4(input.Position, 1), WorldViewProjection);
return output;
}
float4 PS( PS_IN input ) : SV_Target
{
//return float4(0, 1, 0, 1);
// Get the ray from the camera to the vertex and its length (which is the far point of the ray passing through the atmosphere)
float3 v3Pos = input.PositionWS;
float3 v3Ray = v3Pos - v3CameraPos;
float fFar = length(v3Ray);
v3Ray /= fFar;
// Calculate the closest intersection of the ray with the outer atmosphere (which is the near point of the ray passing through the atmosphere)
float fNear = getNearIntersection(v3CameraPos, v3Ray, fCameraHeight2, fOuterRadius2);
// Calculate the ray's start and end positions in the atmosphere, then calculate its scattering offset
float3 v3Start = v3CameraPos + v3Ray * fNear;
fFar -= fNear;
float fStartAngle = dot(v3Ray, v3Start) / fOuterRadius;
float fStartDepth = exp(-fInvScaleDepth);
float fStartOffset = fStartDepth*scale(fStartAngle);
// Initialize the scattering loop variables
float fSampleLength = fFar / fSamples;
float fScaledLength = fSampleLength * fScale;
float3 v3SampleRay = v3Ray * fSampleLength;
float3 v3SamplePoint = v3Start + v3SampleRay * 0.5;
// Now loop through the sample rays
float3 v3FrontColor = float3(0.0, 0.0, 0.0);
for(int i=0; i<nSamples; i++)
{
float fHeight = length(v3SamplePoint);
float fDepth = exp(fScaleOverScaleDepth * (fInnerRadius - fHeight));
float fLightAngle = dot(v3LightPos, v3SamplePoint) / fHeight;
float fCameraAngle = dot(v3Ray, v3SamplePoint) / fHeight;
float fScatter = (fStartOffset + fDepth*(scale(fLightAngle) - scale(fCameraAngle)));
float3 v3Attenuate = exp(-fScatter * (v3InvWavelength * fKr4PI + fKm4PI));
v3FrontColor += v3Attenuate * (fDepth * fScaledLength);
v3SamplePoint += v3SampleRay;
}
// Finally, scale the Mie and Rayleigh colors and set up the varying variables for the pixel shader
float3 c0 = v3FrontColor * (v3InvWavelength * fKrESun);
float3 c1 = v3FrontColor * fKmESun;
float3 v3Direction = v3CameraPos - v3Pos;
float fCos = dot(v3LightPos, v3Direction) / length(v3Direction);
float fCos2 = fCos*fCos;
float3 color = getRayleighPhase(fCos2) * c0 + getMiePhase(fCos, fCos2, g, g2) * c1;
float4 AtmoColor = float4(color, color.b);
float4 PlanetColor = float4(1, 0, 0, 1);
return PlanetColor + AtmoColor;
}
technique10 Default
{
pass P0
{
SetVertexShader( CompileShader( vs_4_0, VS() ) );
SetGeometryShader( 0 );
SetPixelShader( CompileShader( ps_4_0, PS() ) );
}
}
[/CODE]

This is pretty much a direct copy of O'Neils shader, except I'm doing everything in the pixel shader, and I color the sphere red to better visualize where the effect is applied.

Here are the shader constants I'm using:
[CODE]
float Km = 0.0025f;
float Kr = 0.0015f;
float ESun = 10.0f;
Vec3f v3InvWavelength = Vec3f(
1.0f / pow(0.650f, 4),
1.0f / pow(0.570f, 4),
1.0f / pow(0.475f, 4));
float fOuterRadius = 1.025f;
float fOuterRadius2 = fOuterRadius * fOuterRadius;
float fInnerRadius = 1.0f;
float fInnerRadius2 = fInnerRadius * fInnerRadius;
float fKrESun = Kr * ESun;
float fKmESun = Km * ESun;
float fKr4PI = Kr * 4.0f * Pi;
float fKm4PI = Km * 4.0f * Pi;
float fScaleDepth = 0.25f;
float fInvScaleDepth = 1.0f / fScaleDepth;
float fScale = 1.0f / (fOuterRadius - fInnerRadius);
float fScaleOverScaleDepth = fScale / fScaleDepth;
Vec3f v3LightPos = Vec3f(0.5f, 0.5f, -0.5f);
v3LightPos.normalize();
Vec3f v3CameraPos = Engine->Scene->Camera->GetPosition();
float fCameraHeight = v3CameraPos.length();
float fCameraHeight2 = v3CameraPos.length_squared();
[/CODE]

I'm running this shader on a sphere with radius 1.025f

And this is what I'm getting:
[img]http://i.imgur.com/wVMZo.png[/img]

Keep in mind, I added the red color to highlight the sphere surface.
As you can see, I'm not doing so well.
I noticed that the effect isn't incorporating the whole sphere, which makes me think there's a problem with the scaling parameters here:
[CODE]
float fScaleDepth = 0.25f;
float fInvScaleDepth = 1.0f / fScaleDepth;
float fScale = 1.0f / (fOuterRadius - fInnerRadius);
float fScaleOverScaleDepth = fScale / fScaleDepth;
[/CODE]

This doesn't really surprise me too much because I have trouble understanding what exactly the fScaleDepth parameter is supposed to be.
I'm using 0.25f because it's what was used in the GPU Gems example.
I've played with the parameters quite a bit but I can't seem to get it right.

I'd be grateful for any suggestions.

Cheers,
Hyu
0

Share this post


Link to post
Share on other sites
I had an in-depth look at the example code provided with the GPU gems article and decided to match all my settings 1:1 to what was used in the example in the hopes to get it working.
Unfortunately most problems prevailed.

My rasterizer state was messed up, explaining some of the things going on the pic I posted earlier.
Even with that fixed, my Skyfromspace shader implementation is nowhere near working.

I then decided to switch to the Groundfromspace shader because I was stuck, and it seems to work rather well:

[img]http://i.imgur.com/gLLR3.png[/img]

This is the GroundFromSpace shader applied to a sphere mesh with radius 10.00 (planet) with a diffuse color of (0.25, 0.25, 0.25)

Now, if I add the SkyFromSpace shader applied to another sphere mesh with radius 10.25 (atmosphere)
on top of it I get this:

[img]http://i.imgur.com/bhaDF.png[/img]



Both share the exact same shader constants.
Since the GroundFromSpace shader seems to be working rather nicely, I'm no longer convinced that the problem is related to the scaling parameters, especially since I copied the ones from Sean O'Neil exactly.
Using the new scaling factors also didn't change anything, so I'm pretty sure I had them set up right the first time around.


I tried to debug the shader as best as I could and found out that the v3FrontColor variable is definitely getting calculated incorrectly.
Unfortunately the calculations are rather complicated and I have trouble finding the issue.

Here's what I have for now:

Shader:
[CODE]
// The number of sample points taken along the ray
static const int nSamples = 4;
static const float fSamples = 4.0f;
// Mie phase assymetry factor
static const float g = -0.98f;
static const float g2 = 0.9604f;
// Shader Constants
float4x4 WorldViewProjection;
float3 v3CameraPos; // The camera's current position
float3 v3LightPos; // The direction vector to the light source
float3 v3InvWavelength; // 1 / pow(wavelength, 4) for the red, green, and blue channels
float fCameraHeight; // The camera's current height
float fCameraHeight2; // fCameraHeight^2
float fOuterRadius; // The outer (atmosphere) radius
float fOuterRadius2; // fOuterRadius^2
float fInnerRadius; // The inner (planetary) radius
float fInnerRadius2; // fInnerRadius^2
float fKrESun; // Kr * ESun
float fKmESun; // Km * ESun
float fKr4PI; // Kr * 4 * PI
float fKm4PI; // Km * 4 * PI
float fScaleDepth; // The scale depth (the altitude at which the average atmospheric density is found)
float fInvScaleDepth; // 1 / fScaleDepth
float fScale; // 1 / (fOuterRadius - fInnerRadius)
float fScaleOverScaleDepth; // fScale / fScaleDepth
// The scale equation calculated by Vernier's Graphical Analysis
float scale(float fCos)
{
float x = 1.0 - fCos;
return fScaleDepth * exp(-0.00287 + x*(0.459 + x*(3.83 + x*(-6.80 + x*5.25))));
}
// Calculates the Mie phase function
float getMiePhase(float fCos, float fCos2, float g, float g2)
{
return 1.5 * ((1.0 - g2) / (2.0 + g2)) * (1.0 + fCos2) / pow(abs(1.0 + g2 - 2.0*g*fCos), 1.5);
}
// Calculates the Rayleigh phase function
float getRayleighPhase(float fCos2)
{
//return 1.0;
return 0.75 + 0.75*fCos2;
}
// Returns the near intersection point of a line and a sphere
float getNearIntersection(float3 v3Pos, float3 v3Ray, float fDistance2, float fRadius2)
{
float B = 2.0 * dot(v3Pos, v3Ray);
float C = fDistance2 - fRadius2;
float fDet = max(0.0, B*B - 4.0 * C);
return 0.5 * (-B - sqrt(fDet));
}
// Returns the far intersection point of a line and a sphere
float getFarIntersection(float3 v3Pos, float3 v3Ray, float fDistance2, float fRadius2)
{
float B = 2.0 * dot(v3Pos, v3Ray);
float C = fDistance2 - fRadius2;
float fDet = max(0.0, B*B - 4.0 * C);
return 0.5 * (-B + sqrt(fDet));
}
struct VS_IN
{
float3 Position : POSITION0;
};
struct PS_IN
{
float4 Position : SV_POSITION;
float3 PositionWS : TEXCOORD0;
};
PS_IN VS( VS_IN input )
{
PS_IN output = (PS_IN)0;
output.PositionWS = input.Position;
output.Position = mul(float4(input.Position, 1), WorldViewProjection);
return output;
}
float4 PS_GroundFromSpace( PS_IN input ) : SV_Target
{
// Get the ray from the camera to the vertex and its length (which is the far point of the ray passing through the atmosphere)
float3 v3Pos = input.PositionWS;
float3 v3Ray = v3Pos - v3CameraPos;
v3Pos = normalize(v3Pos);
float fFar = length(v3Ray);
v3Ray /= fFar;
// Calculate the closest intersection of the ray with the outer atmosphere (which is the near point of the ray passing through the atmosphere)
float fNear = getNearIntersection(v3CameraPos, v3Ray, fCameraHeight2, fOuterRadius2);
// Calculate the ray's starting position, then calculate its scattering offset
float3 v3Start = v3CameraPos + v3Ray * fNear;
fFar -= fNear;
float fDepth = exp((fInnerRadius - fOuterRadius) * fInvScaleDepth);
float fCameraAngle = dot(-v3Ray, v3Pos);
float fLightAngle = dot(v3LightPos, v3Pos);
float fCameraScale = scale(fCameraAngle);
float fLightScale = scale(fLightAngle);
float fCameraOffset = fDepth*fCameraScale;
float fTemp = (fLightScale + fCameraScale);
// Initialize the scattering loop variables
//gl_FrontColor = vec4(0.0, 0.0, 0.0, 0.0);
float fSampleLength = fFar / fSamples;
float fScaledLength = fSampleLength * fScale;
float3 v3SampleRay = v3Ray * fSampleLength;
float3 v3SamplePoint = v3Start + v3SampleRay * 0.5;
// Now loop through the sample rays
float3 v3FrontColor = float3(0.0, 0.0, 0.0);
float3 v3Attenuate;
for(int i=0; i<nSamples; i++)
{
float fHeight = length(v3SamplePoint);
float fDepth = exp(fScaleOverScaleDepth * (fInnerRadius - fHeight));
float fScatter = fDepth*fTemp - fCameraOffset;
v3Attenuate = exp(-fScatter * (v3InvWavelength * fKr4PI + fKm4PI));
v3FrontColor += v3Attenuate * (fDepth * fScaledLength);
v3SamplePoint += v3SampleRay;
}
float3 c0 = v3FrontColor * (v3InvWavelength * fKrESun + fKmESun);
float3 c1 = v3Attenuate;
float3 PlanetColor = float3(0.25, 0.25, 0.25);
return float4(c0 + PlanetColor * c1, 1);
}
float4 PS_SkyFromSpace( PS_IN input ) : SV_Target
{
//return float4(0, 1, 0, 1);
// Get the ray from the camera to the vertex and its length (which is the far point of the ray passing through the atmosphere)
float3 v3Pos = input.PositionWS;
float3 v3Ray = v3Pos - v3CameraPos;
float fFar = length(v3Ray);
v3Ray /= fFar;
// Calculate the closest intersection of the ray with the outer atmosphere (which is the near point of the ray passing through the atmosphere)
float fNear = getNearIntersection(v3CameraPos, v3Ray, fCameraHeight2, fOuterRadius2);
// Calculate the ray's start and end positions in the atmosphere, then calculate its scattering offset
float3 v3Start = v3CameraPos + v3Ray * fNear;
fFar -= fNear;
float fStartAngle = dot(v3Ray, v3Start) / fOuterRadius;
float fStartDepth = exp(-fInvScaleDepth);
float fStartOffset = fStartDepth*scale(fStartAngle);
// Initialize the scattering loop variables
float fSampleLength = fFar / fSamples;
float fScaledLength = fSampleLength * fScale;
float3 v3SampleRay = v3Ray * fSampleLength;
float3 v3SamplePoint = v3Start + v3SampleRay * 0.5;
// Now loop through the sample rays
float3 v3FrontColor = float3(0.0, 0.0, 0.0);
for(int i=0; i<nSamples; i++)
{
float fHeight = length(v3SamplePoint);
float fDepth = exp(fScaleOverScaleDepth * (fInnerRadius - fHeight));
float fLightAngle = dot(v3LightPos, v3SamplePoint) / fHeight;
float fCameraAngle = dot(v3Ray, v3SamplePoint) / fHeight;
float fScatter = (fStartOffset + fDepth*(scale(fLightAngle) - scale(fCameraAngle)));
float3 v3Attenuate = exp(-fScatter * (v3InvWavelength * fKr4PI + fKm4PI));
v3FrontColor += v3Attenuate * (fDepth * fScaledLength);
v3SamplePoint += v3SampleRay;
}
// Finally, scale the Mie and Rayleigh colors and set up the varying variables for the pixel shader
float3 c0 = v3FrontColor * (v3InvWavelength * fKrESun);
float3 c1 = v3FrontColor * fKmESun;
float3 v3Direction = v3CameraPos - v3Pos;
float fCos = dot(v3LightPos, v3Direction) / length(v3Direction);
float fCos2 = fCos*fCos;
float3 color = getRayleighPhase(fCos2) * c0 + getMiePhase(fCos, fCos2, g, g2) * c1;
float4 AtmoColor = float4(color, color.b);
return AtmoColor;
}
technique10 SkyFromSpace
{
pass P0
{
SetVertexShader( CompileShader( vs_4_0, VS() ) );
SetGeometryShader( 0 );
SetPixelShader( CompileShader( ps_4_0, PS_SkyFromSpace() ) );
}
}
technique10 GroundFromSpace
{
pass P0
{
SetVertexShader( CompileShader( vs_4_0, VS() ) );
SetGeometryShader( 0 );
SetPixelShader( CompileShader( ps_4_0, PS_GroundFromSpace() ) );
}
}
[/CODE]

And this is how I render both spheres:
[CODE]
AtmosphereSphere = CMeshFactory::CreateSphere(this, 10.25f, 128, 128);
PlanetSphere = CMeshFactory::CreateSphere(this, 10.00f, 128, 128);
[/CODE]

[CODE]
void CGraphicsManagerDX11::TestAtmosphere()
{
float Km = 0.0025f;
float Kr = 0.0015f;
float ESun = 10.0f;
Vec3f v3InvWavelength = Vec3f(
1.0f / pow(0.650f, 4),
1.0f / pow(0.570f, 4),
1.0f / pow(0.475f, 4));
float fOuterRadius = 10.25f;
float fOuterRadius2 = fOuterRadius * fOuterRadius;
float fInnerRadius = 10.00f;
float fInnerRadius2 = fInnerRadius * fInnerRadius;
float fKrESun = Kr * ESun;
float fKmESun = Km * ESun;
float fKr4PI = Kr * 4.0f * Pi;
float fKm4PI = Km * 4.0f * Pi;
float fScaleDepth = 0.25f;
float fInvScaleDepth = 1.0f / fScaleDepth;
float fScale = 1.0f / (fOuterRadius - fInnerRadius);
float fScaleOverScaleDepth = fScale / fScaleDepth;
Vec3f v3LightPos = Vec3f(0.5f, 0.5f, -0.5f);
v3LightPos.normalize();
Vec3f v3CameraPos = Engine->Scene->Camera->GetPosition();
float fCameraHeight = v3CameraPos.length();
float fCameraHeight2 = fCameraHeight * fCameraHeight;
Context->OMSetRenderTargets(1, &BackBufferView, DepthBufferView);
Context->OMSetDepthStencilState(DepthStencilStates->Default, 0);
Context->RSSetState(RasterizerStates->CullBack);
Context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
CEffect* Effect = EffectManager->Get(L"Scatter");
Effect->SetShaderConstant("WorldViewProjection", Engine->Scene->Camera->GetViewProjection());
Effect->SetShaderConstant("v3CameraPos", v3CameraPos);
Effect->SetShaderConstant("v3LightPos", v3LightPos);
Effect->SetShaderConstant("fCameraHeight", fCameraHeight);
Effect->SetShaderConstant("fCameraHeight2", fCameraHeight2);
Effect->SetShaderConstant("v3InvWavelength", v3InvWavelength);
Effect->SetShaderConstant("fOuterRadius", fOuterRadius);
Effect->SetShaderConstant("fOuterRadius2", fOuterRadius2);
Effect->SetShaderConstant("fInnerRadius", fInnerRadius);
Effect->SetShaderConstant("fInnerRadius2", fInnerRadius2);
Effect->SetShaderConstant("fKrESun", fKrESun);
Effect->SetShaderConstant("fKmESun", fKmESun);
Effect->SetShaderConstant("fKr4PI", fKr4PI);
Effect->SetShaderConstant("fKm4PI", fKm4PI);
Effect->SetShaderConstant("fScaleDepth", fScaleDepth);
Effect->SetShaderConstant("fInvScaleDepth", fInvScaleDepth);
Effect->SetShaderConstant("fScale", fScale);
Effect->SetShaderConstant("fScaleOverScaleDepth", fScaleOverScaleDepth);
PlanetSphere->UseBuffers(Context);
Effect->GetTechniquePass("GroundFromSpace")->Apply(0, Context);
Context->DrawIndexed(PlanetSphere->IndexCount, 0, 0);
AtmosphereSphere->UseBuffers(Context);
Effect->GetTechniquePass("SkyFromSpace")->Apply(0, Context);
Context->DrawIndexed(AtmosphereSphere->IndexCount, 0, 0);
}
[/CODE]


Any ideas where the issue could be?

Cheers,
Hyu
0

Share this post


Link to post
Share on other sites
I seem to have misunderstood something rather important when reading the article, which is
that the atmosphere is supposed to be rendered behind the planet, not in front of it.
In retrospect I have no idea how I came to another conclusion.

After fixing this major issue I got much better results and have begun modifying the shaders so they can be directly applied to a gbuffer.
I currently perform all of the geometry shading in a single pass, and then
add the outer atmosphere in a second pass.
Both can be done in a single pass though, but this involves rather heavy dynamic branching.

This is where I'm currently at:
[img]http://i.imgur.com/gM0cW.jpg[/img]


I had to change the
[CODE]
float fCameraAngle = dot(-v3Ray, v3Pos);
[/CODE]

variable to

[CODE]
float fCameraAngle = 1.0f;
[/CODE]

for ground shading though, because it would otherwise produce weird results when the camera is close to the inner radius.
I'm not really sure why that is though, but it works fine with 1.0f.

It still looks a bit odd, but that is mostly because I'm using a red planet, on whom an earth-like atmosphere feels out of place.
The sky is also quite a bit too dark. I'll have to tweak some values to get that right, but that shouldn't be too difficult.
Once I get that sorted, add some hdr, and get some work on my noise functions for the terrain generation done, it should look rather pretty.

Cheers,
Hyu
2

Share this post


Link to post
Share on other sites
That looks pretty good. I too adapted Sean O'Neil's shaders to work in a single pass in a deferred renderer, [url="http://swiftcoder.wordpress.com/starfall"]for StarFall[/url] (albeit using GLSL).

It works rather well, though I'd really like to integrate [url="http://evasion.inrialpes.fr/~Eric.Bruneton/"]Eric Bruneton's multiple-scattering[/url] at some point.
0

Share this post


Link to post
Share on other sites
StarFall is looking pretty good!

Ideally I'd like to integrate Eric Bruneton's scattering as well.
In fact I tried to implement it before I adapted Sean O'Neil's shaders, but I had major trouble
understanding how to generate the 4d lookup texture.

I plan on getting back to it in the future though.
0

Share this post


Link to post
Share on other sites
I tried to implement O'Neils shaders as well, but the most I ever got was a handful of brightly colored triangles somewhere.
After I saw your post I figured I'd give the GroundFromSpace shader a try, and got it to work as well (for the most part. if the light is closer than 1 atmosphere radius, the lightScale value becomes an issue).
Hoewver I do not get the orange-ish color around the night/day terminator.

The SkyFromSpace shader however, I can't seem to get to work at all. How do you draw the atmosphere behind the planet?
Disable depth buffer writes, draw the atmosphere, then render the planet?
Doesn't the opaque planet skip any and all alpha blending with the transparent atmosphere if it is in front of it though?

Even rewriting my SkyFromSpace shader after your code, all I get is this: (GroundFromSpace in the background):
[img]http://dl.dropbox.com/u/21007284/triangle.png[/img]


The underlying geometry is a geosphere, so that is likely just a single vertex's color lerping to the sourrounding 6 triangles.
0

Share this post


Link to post
Share on other sites
[quote]
[left]Hoewver I do not get the orange-ish color around the night/day terminator.[/left]
[/quote]
The shaders are very sensitive to the scaling parameters.
Things go horribly wrong if one of them is off even by a small amount.
You also have to follow some rules, such as the planet center being at 0, 0, 0.
If you post the shader constants you're currently using I can check if something obvious is wrong.

[quote]
[left][color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3]How do you draw the atmosphere behind the planet?[/quote][/size][/font][/color][/left]


[left][color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3]Draw your planet using the GroundFromSpace shader first[/size][/font][/color][/left]
[left][color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3]Then change your rasterizer state so it culls front faces instead of back faces.[/size][/font][/color][/left]
[left][color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3]Then draw the atmosphere sphere using the AtmosphereFromSpace shader.
Since your culling is inverted, only the back half of the sphere will be drawn.
Pixels behind the planet will not be drawn because they will fail the depth test.[/size][/font][/color][/left]
0

Share this post


Link to post
Share on other sites
I pass the object position to the shader and use vertex, camera and light position relative to that.

These are my shader constants:
[CODE]
constBuffer.samples = 3;
float Kr = 0.0025f;
float Km = 0.0010f;
float ESun = 20.0f;
float pi = 3.14159265358979323846f;
constBuffer.Kr4PI = Kr * 4 * pi;
constBuffer.Km4PI = Km * 4 * pi;
constBuffer.KrESun = Kr * ESun;
constBuffer.KmESun = Km * ESun;
constBuffer.pRadius = 1.0f;
constBuffer.aRadius = 1.025f;

constBuffer.rScaleDepth = 0.25f;
constBuffer.mScaleDepth = 0.1f;

constBuffer.CamPosW = XMFLOAT4(sin(t) * 5, 5, cos(t) * 5, 0.0f);
constBuffer.LightPos = XMFLOAT4(1000, 1000, 1000, 0.0f);
constBuffer.g = -0.99f;
constBuffer.WaveLength = XMFLOAT4(0.65f, 0.57f, 0.475f, 0.0f);
[/CODE]

A few others I calculate in the shader:
[CODE]
float3 CamPos = CamPosW - objPos;
float3 LightPos = LightPosW - objPos;
float3 InvWaveLength = 1.0 / pow(WaveLength.xyz, 4);
float fscale = 1.0 / (aRadius - pRadius);
float scaleOverScaleDepth = fscale / rScaleDepth;
float altitude = length(CamPos);

float3 pos = mul(input.Pos, World).xyz - objPos.xyz;
[/CODE]
0

Share this post


Link to post
Share on other sites
v3LightPos is actually the light direction, not the light position, even though the name suggests otherwise.
It needs to be normalized.

mScaleDepth, which I am assuming is fInvScaleDepth needs to be 1 / ScaleDepth.

for "g" I would stick to -0.98f.
It doesn't really influence anything too much besides the fake sun when rendering the sky from atmosphere though, which you aren't doing.

Apart from that I can't find any problems.
0

Share this post


Link to post
Share on other sites
[quote name='Hyunkel' timestamp='1330911352' post='4919321']
v3LightPos is actually the light direction, not the light position, even though the name suggests otherwise.
It needs to be normalized.

mScaleDepth, which I am assuming is fInvScaleDepth needs to be 1 / ScaleDepth.

for "g" I would stick to -0.98f.
It doesn't really influence anything too much besides the fake sun when rendering the sky from atmosphere though, which you aren't doing.

Apart from that I can't find any problems.
[/quote]

Normalizing LighgtDir/Pos gives me more colored specks, they flicker extremely fast and are hard to capture:
[img]http://dl.dropbox.com/u/21007284/specks.png[/img]

In O'Neils C++ soruce code there are both rayleighScaleDepth and mieScaleDepth, though all the shaders only use the rayleigh one.
InvScaleDepth is only used in this one line, so I opted for
[CODE]
float startDepth = exp(-1 / rScaleDepth);
[/CODE]

instead.

Is the orange day/night transition in your renders a result of O'Neils shader, or something that you are doing?

SkyFromSpace.fx:
[CODE]
cbuffer perObject
{
float4x4 Scale;
float4x4 Rotation;
float4x4 Position;
float4 objColor;
float4 objPos;
int wire;
int textured;
};
cbuffer perFrame
{
float4x4 view;
float4x4 projection;

float4 CamPosW;
float4 LightPosW;
float4 WaveLength;
float samples;
float pRadius;
float aRadius;
float KrESun;
float KmESun;
float Kr4PI;
float Km4PI;
float g;
float rScaleDepth;
float mScaleDepth;
};
struct appdata
{
float4 Pos : POSITION;
float3 Normal : NORMAL;
float3 UVW : TEXCOORD;
};
struct v2p
{
float4 Pos : SV_POSITION;
float4 Color0 : COLOR0;
float4 Color1 : COLOR1;
float3 Direction : TEXCOORD;
};

float scale(float f)
{
float x = 1.0 - f;
return rScaleDepth * exp(-0.00287 + x*(0.459 + x*(3.83 + x*(-6.80 + x*5.25))));
}
// Calculates the Mie phase function
float getMiePhase(float fCos, float fCos2, float g, float g2)
{
return 1.5 * ((1.0 - g2) / (2.0 + g2)) * (1.0 + fCos2) / pow(abs(1.0 + g2 - 2.0*g*fCos), 1.5);
}
// Calculates the Rayleigh phase function
float getRayleighPhase(float fCos2)
{
//return 1.0;
return 0.75 + 0.75*fCos2;
}
// Returns the near intersection point of a line and a sphere
float getNearIntersection(float3 v3Pos, float3 v3Ray, float fDistance2, float fRadius2)
{
float B = 2.0 * dot(v3Pos, v3Ray);
float C = fDistance2 - fRadius2;
float fDet = max(0.0, B*B - 4.0 * C);
return 0.5 * (-B - sqrt(fDet));
}
v2p VS(appdata input)
{
//calculate prerequisites
float4x4 WVP = transpose(mul(mul(mul(mul(projection, view), Position), Rotation), Scale));
float4x4 World = transpose(mul(mul(Position,Rotation),Scale));

float3 CamPos = CamPosW - objPos;
float3 LightPos = LightPosW - objPos;
LightPos /= length(LightPos);

float3 InvWaveLength = 1.0 / pow(WaveLength.xyz, 4);
float fscale = 1.0 / (aRadius - pRadius);
float scaleOverScaleDepth = fscale / rScaleDepth;
float altitude = length(CamPos);

float3 pos = mul(input.Pos, World).xyz - objPos.xyz;
float3 ray = pos - CamPos;
pos /= length(pos);
float far = length(ray);
ray /= far;
float near = getNearIntersection(CamPos, ray, altitude*altitude, aRadius*aRadius);
//initial values
float3 start = CamPos + ray * near;
far -= near;
float startAngle = dot(ray, start) / aRadius;
float startDepth = exp(-1 / rScaleDepth);
float startOffset = startDepth * scale(startAngle);
float sampleLength = far / samples;
float scaledLength = sampleLength * fscale;
float3 sampleRay = ray * sampleLength;
float3 samplePoint = start + sampleRay * 0.5;
//loop through samples
float3 frontColor = float3(0,0,0);
for (int i=0; i<(int)samples; i++)
{
float height = length(samplePoint.xyz);
float depth = exp(scaleOverScaleDepth * (pRadius - height));
float lightAngle = dot(LightPos, samplePoint) / height;
float camAngle = dot(ray, samplePoint) / height;
float scatter = (startOffset + depth * (scale(lightAngle) - scale(camAngle)));
float3 attenuate = exp(-scatter * (InvWaveLength * Kr4PI + Km4PI));
frontColor += attenuate * (depth * scaledLength);
samplePoint += sampleRay;
}

float3 c0 = frontColor * (InvWaveLength.xyz * KrESun);
float3 c1 = frontColor * KmESun;
float3 direction = CamPos - pos;
float Cos = dot(LightPos, direction) / length(direction);

v2p output;
output.Pos = mul(input.Pos, WVP);
output.Color0 = float4(c0, Cos);
output.Color1 = float4(c1, 1);
output.Direction = float4(direction, 1);
return output;
}

float4 PS(v2p input) : SV_TARGET
{
float Cos = input.Color0.w;
float3 color = getRayleighPhase(Cos*Cos) * input.Color0 + getMiePhase(Cos, Cos*Cos, g, g*g) * input.Color1;
return float4(color, color.z);
}
[/CODE]


And the GroundFromSpace.fx as well:
[CODE]
cbuffer perObject
{
float4x4 Scale;
float4x4 Rotation;
float4x4 Position;
float4 objColor;
float4 objPos;
int wire;
int textured;
};
cbuffer perFrame
{
float4x4 view;
float4x4 projection;

float4 CamPosW;
float4 LightPosW;
float4 WaveLength;
float samples;
float pRadius;
float aRadius;
float KrESun;
float KmESun;
float Kr4PI;
float Km4PI;
float g;
float rScaleDepth;
float mScaleDepth;
};
Texture2D objTexture;
SamplerState texSampler;

struct appdata
{
float4 Pos : POSITION;
float3 Normal : NORMAL;
float3 UVW : TEXCOORD;
};
struct v2p
{
float4 Pos : SV_POSITION;
float4 Color0 : COLOR0;
float4 Color1 : COLOR1;
float3 TexCoord : TEXCOORD;
};

float scale(float fCos)
{
float x = 1.0 - fCos;
return rScaleDepth * exp(-0.00287 + x*(0.459 + x*(3.83 + x*(-6.80 + x*5.25))));
}
// Returns the near intersection point of a line and a sphere
float getNearIntersection(float3 v3Pos, float3 v3Ray, float fDistance2, float fRadius2)
{
float B = 2.0 * dot(v3Pos, v3Ray);
float C = fDistance2 - fRadius2;
float fDet = max(0.0, B*B - 4.0 * C);
return 0.5 * (-B - sqrt(fDet));
}

v2p VS(appdata input)
{
//calculate prerequisites
float4x4 WVP = transpose(mul(mul(mul(mul(projection, view), Position), Rotation), Scale));
float4x4 World = transpose(mul(mul(Position,Rotation),Scale));

float3 CamPos = CamPosW - objPos;
float3 LightPos = LightPosW - objPos;
float3 LightDir = LightPos / length(LightPos);
float4 InvWaveLength = 1.0 / float4(pow(WaveLength.x, 4), pow(WaveLength.y, 4), pow(WaveLength.z, 4), 0);
float fscale = 1.0 / (aRadius - pRadius);
float scaleOverScaleDepth = fscale / rScaleDepth;
float altitude = length(CamPos);

float3 pos = mul(input.Pos, World).xyz - objPos.xyz;
float3 ray = pos - CamPos;
pos /= length(pos);
float far = length(ray);
ray /= far;
float near = getNearIntersection(CamPos, ray, altitude*altitude, aRadius*aRadius);
//initial values
float3 start = CamPos + ray * near;
far -= near;
float depth = exp((pRadius - aRadius) / rScaleDepth);
float camAngle = dot(-ray, pos);
float lightAngle = dot(LightDir, pos);
float camScale = scale(camAngle);
float lightScale = scale(lightAngle);
float camOffset = depth*camScale;
float temp = lightScale + camScale;
float sampleLength = far / samples;
float scaledLength = sampleLength * fscale;
float3 sampleRay = ray * sampleLength;
float3 samplePoint = start + sampleRay * 0.5;
//loop through samples
float3 frontColor = float3(0,0,0);
float3 attenuate;
for (int i=0; i<(int)samples; i++)
{
float height = length(samplePoint.xyz);
depth = exp(scaleOverScaleDepth * (pRadius - height));
float scatter = (depth*temp) - camOffset;
attenuate = exp(-scatter * (InvWaveLength * Kr4PI + Km4PI));
frontColor += attenuate * (depth * scaledLength);
samplePoint += sampleRay;
}
v2p output;
output.Pos = mul(input.Pos, WVP);
output.Color0 = float4(frontColor * (InvWaveLength.xyz * KrESun + KmESun), lightAngle);
output.Color1 = float4(attenuate, 1);
output.TexCoord = input.UVW;
return output;
}
float4 PS(v2p input) : SV_TARGET
{
float4 planetColor;
if (textured) planetColor = objTexture.Sample(texSampler, input.TexCoord.xyz);
else planetColor = objColor;
float lightAngle = input.Color0.w;
float4 color = input.Color0 + (planetColor * input.Color1);
color *= lightAngle;
color.w = 1.0;
return color;
}
[/CODE]
0

Share this post


Link to post
Share on other sites
You might want to think about working from the [url="http://sponeil.net/"]most current version of his shaders (poke around in 'downloads')[/url], rather than the dated, and somewhat badly-commented version in GPU Gems...
1

Share this post


Link to post
Share on other sites
[quote name='melak47' timestamp='1330912482' post='4919323']
Is the orange day/night transition in your renders a result of O'Neils shader, or something that you are doing?
[/quote]

It is a result of O'Neil's shaders.

I can't find any obvious mistakes in your code except for:

[color=#000000]float4 [/color][color=#660066]Color0[/color][color=#000000] [/color][color=#666600]:[/color][color=#000000] COLOR0[/color][color=#666600];[/color]
[color=#000000]float4 [/color][color=#660066]Color1[/color][color=#000000] [/color][color=#666600]:[/color][color=#000000] COLOR1[/color][color=#666600];[/color]

You should pass these values as TEXCOORD's, because directx clamps COLOR to the [0, 1] range.
This should only cause minor artifacts though.

[quote name='swiftcoder' timestamp='1330920064' post='4919360']
You might want to think about working from the [url="http://sponeil.net/"]most current version of his shaders (poke around in 'downloads')[/url], rather than the dated, and somewhat badly-commented version in GPU Gems...
[/quote]

Thank you for pointing this out! I had no idea.
0

Share this post


Link to post
Share on other sites
[quote name='swiftcoder' timestamp='1330920064' post='4919360']
You might want to think about working from the [url="http://sponeil.net/"]most current version of his shaders (poke around in 'downloads')[/url], rather than the dated, and somewhat badly-commented version in GPU Gems...
[/quote]
The thing is, I am!
I have started the SkyFromSpace shader from scratch about 6 times now, once from the GPU Gems article, once from the current version, once from the article in nvidia FX Composer, trying to debug it, again from the current version in fx composer, once from someone else's source code on here, and once from Hyunkel's code here.

I figured out why I didn't get the orange transition. Before I got the lightScale value right, the whole sphere was lit up so I multiplied the resulting diffuse by the lightAngle to make the far side of the planet dark. Now that the lightScale works correctly though, it was fading the diffuse out before the transition.
Now that it's got the right value, the far side of the planet turns dark on it's own.

I'm kind of clueless about the SkyFromSpace shader though...I guess I will take another stab at it sometime.
0

Share this post


Link to post
Share on other sites
hello,
I come here baring a cry for help. I needed an atmosphere shader for the little project I am working on. so I convert the SkyFormSpace shader in the book GPU gems 2- Chapter 16, Accurate Atmospheric Scattering written by Sean O'Neil to SkyFormSpace.fx. I want to see the atmosphere effect in the software FX Composer . but the result is incorrect?


the effect in FxComposer:
[img]http://fmn.xnpic.com/fmn057/20121206/2130/original_T9ix_6f2800000af1118e.jpg[/img]

and the effect in my project:
[img]http://fmn.rrimg.com/fmn063/20121206/2130/original_VJuS_5da900000ae1118f.jpg[/img]

Here is the shader code i'm using:
[CODE]
// SkyFromSpace - Author: Sean O'Neil - Copyright (c) 2004 Sean O'Neil
//The output of this vertex shader
struct vertout
{
float4 pos : POSITION; // Transformed vertex position
float4 c0 : COLOR0; // The Rayleigh color
float4 c1 : COLOR1; // The Mie color
float3 t0 : TEXCOORD0;
};
//The number of sample points taken along the ray
const int nSamples = 2;
const float fSamples =2.0;
//The scale depth (the altitude at which the average atmospheric density is found)
const float fScaleDepth = 0.25;
const float fInvScaleDepth = 4.0;
//The scale equation calculated by Vernier's Graphical Analysis
float scale(float fCos)
{
float x = 1.0 - fCos;
return fScaleDepth * exp(-0.00287 + x*(0.459 + x*(3.83 + x*(-6.80 + x*5.25))));
}
//Calculates the Mie phase function
float getMiePhase(float fCos, float fCos2, float g, float g2)
{
return 1.5 * ((1.0 - g2) / (2.0 + g2)) * (1.0 + fCos2) / pow(1.0 + g2 - 2.0*g*fCos, 1.5);
}
//Calculates the Rayleigh phase function
float getRayleighPhase(float fCos2)
{
//return 1.0;
return 0.75 + 0.75*fCos2;
}
//Returns the near intersection point of a line and a sphere
float getNearIntersection(float3 v3Pos, float3 v3Ray, float fDistance2, float fRadius2)
{
float B = 2.0 * dot(v3Pos, v3Ray);
float C = fDistance2 - fRadius2;
float fDet = max(0.0, B*B - 4.0 * C);
return 0.5 * (-B - sqrt(fDet));
}
//Returns the far intersection point of a line and a sphere
float getFarIntersection(float3 v3Pos, float3 v3Ray, float fDistance2, float fRadius2)
{
float B = 2.0 * dot(v3Pos, v3Ray);
float C = fDistance2 - fRadius2;
float fDet = max(0.0, B*B - 4.0 * C);
return 0.5 * (-B + sqrt(fDet));
}
//uniform float4x4 gl_ModelViewProjectionMatrix;
uniform float4x4 worldViewProj: WorldViewProjection;
uniform float3 v3CameraPos={0.0,0.0,25};// The camera's current position
uniform float3 v3LightPos={0.0,0.0,1}; // The direction vector to the light source
uniform float fOuterRadius=10.15f; // The outer (atmosphere) radius
uniform float fInnerRadius=10.0f; // The inner (planetary) radius
uniform float red = 0.650f; // 650 nm for red
uniform float green = 0.570f; // 570 nm for green
uniform float blue = 0.475f; // 475 nm for blue
uniform float Kr = 0.0025f;
uniform float Km = 0.0015f;
uniform float PI = 3.14159f;
uniform float ESun = 15.0f;
vertout v_SkyFormSpace(float4 gl_Vertex : POSITION)
{
float3 v3InvWavelength={1.0/pow(red, 4.0f),1.0/pow(green, 4.0f),1.0/pow(blue, 4.0f)};
float fCameraHeight=sqrt(v3CameraPos.x*v3CameraPos.x+v3CameraPos.y*v3CameraPos.y+v3CameraPos.z*v3CameraPos.z);
float fCameraHeight2=fCameraHeight*fCameraHeight;

float fOuterRadius2=fOuterRadius*fOuterRadius;
float fInnerRadius2=fInnerRadius*fInnerRadius;

float fKrESun=Kr * ESun;
float fKmESun=Km * ESun;
float fKr4PI=Kr * 4 * PI;
float fKm4PI=Km * 4 * PI;
float fScale=1.0 / (fOuterRadius - fInnerRadius);
float fScaleOverScaleDepth=fScale / fScaleDepth;

// Get the ray from the camera to the vertex and its length (which is the far point of the ray passing through the atmosphere)
float3 v3Pos = gl_Vertex.xyz;
float3 v3Ray = v3Pos - v3CameraPos;
float fFar = length(v3Ray);
v3Ray /= fFar;
// Calculate the closest intersection of the ray with the outer atmosphere (which is the near point of the ray passing through the atmosphere)
float fNear = getNearIntersection(v3CameraPos, v3Ray, fCameraHeight2, fOuterRadius2);
// Calculate the ray's start and end positions in the atmosphere, then calculate its scattering offset
float3 v3Start = v3CameraPos + v3Ray * fNear;
fFar -= fNear;
float fStartAngle = dot(v3Ray, v3Start) / fOuterRadius;
float fStartDepth = exp(-1.0 / fScaleDepth);
float fStartOffset = fStartDepth*scale(fStartAngle);
// Initialize the scattering loop variables
float fSampleLength = fFar / fSamples;
float fScaledLength = fSampleLength * fScale;
float3 v3SampleRay = v3Ray * fSampleLength;
float3 v3SamplePoint = v3Start + v3SampleRay * 0.5;
// Now loop through the sample rays
float3 v3FrontColor = float3(0.0, 0.0, 0.0);
for(int i=0; i<nSamples; i++)
{
float fHeight = length(v3SamplePoint);
float fDepth = exp(fScaleOverScaleDepth * (fInnerRadius - fHeight));
float fLightAngle = dot(v3LightPos, v3SamplePoint) / fHeight;
//float fCameraAngle = dot(v3Ray, v3SamplePoint) / fHeight;
float fCameraAngle = 1.0;
float fScatter = (fStartOffset + fDepth*(scale(fLightAngle) - scale(fCameraAngle)));
float3 v3Attenuate = exp(-fScatter * (v3InvWavelength * fKr4PI + fKm4PI));
v3FrontColor += v3Attenuate * (fDepth * fScaledLength);
v3SamplePoint += v3SampleRay;
}
// Finally, scale the Mie and Rayleigh colors and set up the varying variables for the pixel shader
vertout OUT;
OUT.pos = mul(gl_Vertex,worldViewProj);
OUT.c0.rgb = v3FrontColor * (v3InvWavelength * fKrESun);
OUT.c1.rgb = v3FrontColor * fKmESun;
OUT.t0 = v3CameraPos - v3Pos;
return OUT;
}
//uniform float3 v3LightPos;
uniform float g=-0.95;
uniform float g2=0.9025;
float4 p_SkyFormSpace(in float4 c0 : COLOR0,
in float4 c1 : COLOR1,
in float3 v3Direction : TEXCOORD0
) : COLOR
{
float fCos = dot(v3LightPos, v3Direction) / length(v3Direction);
float fCos2 = fCos*fCos;
float4 color = getRayleighPhase(fCos2) * c0 + getMiePhase(fCos, fCos2, g, g2) * c1;
color.a = color.b;
return color;
}
technique technique0 {
pass p0 {
CullMode = None;
VertexShader = compile vs_3_0 v_SkyFormSpace();
PixelShader = compile ps_3_0 p_SkyFormSpace();
}
}
[/CODE]


If anyone could help me with a fix or have some advice to help me solve the problem, it will be greatly appreciated.
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0