   O'neil' scattering shader - problem
  Hi i have problem with shader from this page: http://www.gamedev.net/community/forums/topic.asp?topic_id=461747 I did all from this page (create effect, set variables etc.) but when I launch program skydome is all white O,o what's can be wrong? (I set all variables like in Formski's posts)Edit: I have tried to set this shader in Nvidia FX Composer (with pre-calculated variables) for sphere but sphere is still white! Did somebody do it in Nvidia FX Composer?[Edited by - arwi234 on May 10, 2010 3:46:35 PM]
  refresh   ;  I have no experience with O'Neil scattering so I can't help you directly. But I recommend that you change some of the parameters and see whether anything changes. Maybe you gain enough information that way to ask a more detailed question with higher chances of getting answered.Also, have you made sure that the setup "around" the shader works? E.g does the sky turn red if you only output float(1.f, 0.f, 0.f) from the shader...   ;  Yes, when i return float4(1, 0, 0, 0) sphere is red. It's a code of this shader:float4x4 WorldViewProj : WorldViewProjection;float3 v3LightDir=float3(0,0,0);// Light directionfloat3 v3CameraPos=float3(0,0,0);// Camera's current positionfloat3 v3InvWavelength=float3(5.6,9.47,19.6);// 1 / pow(wavelength, 4) for RGB channelsfloat fCameraHeight=3;float fCameraHeight2=9;float fInnerRadius = 1.0;float fInnerRadius2 = 1.0*1.0;float fOuterRadius = 1.025;float fOuterRadius2 = 1.025*1.025;// Scattering parametersfloat KrESun = 0.1;// Kr * ESunfloat KmESun = 0.6;// Km * ESunfloat Kr4PI = 0.03;// Kr * 4 * PIfloat Km4PI = 0.02;// Km * 4 * PI// Phase functionfloat g = -0.991;float g2 = 0.991*0.991;float fScale = 50;// 1 / (outerRadius - innerRadius) = 4 herefloat fScaleDepth = 0.25;// Where the average atmosphere density is foundfloat fScaleOverScaleDepth = 160;// scale / scaleDepthfloat fSkydomeRadius = 50;// Skydome radius (allows us to normalize skydome distances etc)float fExposure = 2.0;// Exposure parameter for pixel shaderint numSamples = 4;int samples = 4;// Application to vertex structurestruct a2v{float4 Position : POSITION0;};// Vertex to pixel shader structurestruct v2p{float4 Position: POSITION0;float3 Direction: TEXCOORD0;float4 RayleighColor    : TEXCOORD1;float4 MieColor: TEXCOORD2;};float scale(float cos){float x = 1.0 - cos;return fScaleDepth * exp(-0.00287 + x*(0.459 + x*(3.83 + x*(-6.80 + x*5.25))));}void RenderSkyVS(in a2v IN, out v2p OUT){// Transform to clipspaceOUT.Position = mul(IN.Position, WorldViewProj);// Get the ray from the camera to the vertex, and it's length (far point)float3 v3Pos = IN.Position / fSkydomeRadius;//v3Pos.y += 1;v3Pos.y += fInnerRadius;float3 v3Ray = v3Pos - v3CameraPos;float fFar = length(v3Ray);v3Ray /= fFar;// Calculate the ray's starting position, then calculate its scattering offsetfloat3 v3Start = v3CameraPos;float fHeight = length(v3Start);float fDepth = exp(fScaleOverScaleDepth * (fInnerRadius - fCameraHeight));float fStartAngle = dot(v3Ray, v3Start) / fHeight;float fStartOffset = fDepth * scale(fStartAngle);// Init loop variablesfloat fSampleLength = fFar / samples;float fScaledLength = fSampleLength * fScale;float3 v3SampleRay = v3Ray * fSampleLength;float3 v3SamplePoint = v3Start + v3SampleRay * 0.5f;// Loop the rayfloat3 color;for (int i = 0; i < numSamples; i++){float fHeight = length(v3SamplePoint);float fDepth = exp(fScaleOverScaleDepth * (fInnerRadius-fHeight));float fLightAngle = dot(v3LightDir, v3SamplePoint) / fHeight;float fCameraAngle = dot(v3Ray, v3SamplePoint) / fHeight;float fScatter = (fStartOffset + fDepth*(scale(fLightAngle) - scale(fCameraAngle)));float3 v3Attenuate = exp(-fScatter * (v3InvWavelength * Kr4PI + Km4PI));// Accumulate colorv3Attenuate *= (fDepth * fScaledLength);color += v3Attenuate;// Next sample pointv3SamplePoint += v3SampleRay;}// Finally, scale the Mie and Rayleigh colorsOUT.RayleighColor.xyz = color * (v3InvWavelength * KrESun);OUT.RayleighColor.w = 1.0f;OUT.MieColor.xyz = color * KmESun;OUT.MieColor.w = 1.0f;OUT.Direction = v3CameraPos - v3Pos;}float4 RenderSkyPS(in v2p IN) : COLOR0{float cos = dot(v3LightDir, IN.Direction) / length(IN.Direction);//float rayleighPhase = 0.75 * (1.0 + cos*cos);float rayleighPhase = 0.75 * (2.0 + 0.5 * cos*cos);float miePhase = 1.5f * ((1.0f - g2) / (2.0f + g2)) * (1.0f + cos*cos) / pow(1.0f + g2 - 2.0f * g * cos, 1.5f);// exposure => 1.0 - exp(-fExposure * color)return 1 - exp(-fExposure * (rayleighPhase * IN.RayleighColor + miePhase * IN.MieColor));}technique Sky{pass p0{VertexShader = compile vs_2_0 RenderSkyVS();PixelShader = compile ps_2_0 RenderSkyPS();ZWriteEnable = 0;}}Edit: sphere now is black. How can I get light direction in FX Composer 2.5 from Directional Light(i think that sphere is black because it's "night") but maybe sth in shader's wrong?[Edited by - arwi234 on May 12, 2010 1:17:39 PM];  nobody knows?   ;  refresh   