I tried your suggestions, but I still have this strange error. camPosInDome is (0, height, 0) and should never be a null vector.
Since I have no idea what could be the reason for this error and maybe because the real problem is in a different line Im gonna post my vertex shader here:
VS_OUTPUT VS(float3 vertexPos : POSITION) { VS_OUTPUT output = (VS_OUTPUT)0; float3 vertexPosWorld = mul( float4(vertexPos, 1.0f), world); // Position des Vertex im World Space float3 ray = vertexPosWorld - camPosWorld; float distance = length(ray); ray /= distance; // Eventuell normalize(ray); // Berechnung der Optical Depth (Integralteil) von der Kamera bis zum Vertex vPos float camHeight = camPosWorld.y; float3 camPosInDome = float3(0.0f, camHeight, 0.0f); float camAngle = dot(camPosInDome, ray) / camHeight; float2 LUTTexCoords = float2(camHeight * scale, 0.5f - camAngle * 0.5f); float4 camOpticalDepth = opticalDepthLUT.Sample(opticalDepthLUT_sampler, LUTTexCoords); float3 rayleighSum = float3(0.0f, 0.0f, 0.0f); float3 mieSum = float3(0.0f, 0.0f, 0.0f); float sampleLength = distance / sampleCount; float3 sampleRay = ray * sampleLength; float3 samplePos = camPosInDome + sampleRay * 0.5f; // All the loop variables (to avoid multiple definitions - dont know if necessary) float sampleHeight; float lightAngle; float2 lightDepthTexCoords; float4 lightDepth; float rayleighDensity; float rayleighDepth; float mieDensity; float mieDepth; float sampleAngle; float2 sampleDepthTexCoords; float4 sampleDepth; float3 attenuation; float len; float3 alsoSamplePos; for(int i=0; i < sampleCount; i++) { sampleHeight = samplePos.y; lightAngle = dot(lightDir, samplePos) / length(samplePos); lightDepthTexCoords = float2(sampleHeight * scale, 0.5f - lightAngle * 0.5f); lightDepth = opticalDepthLUT.Sample(opticalDepthLUT_sampler, lightDepthTexCoords); rayleighDensity = sampleLength * lightDepth[0]; rayleighDepth = lightDepth[1]; mieDensity = sampleLength * lightDepth[2]; mieDepth = sampleLength * lightDepth[3]; ! strange error ! ->: sampleAngle = dot(ray, samplePos) / length(samplePos); sampleDepthTexCoords = float2(sampleHeight * scale, 0.5f - sampleAngle * 0.5f); sampleDepth = opticalDepthLUT.Sample(opticalDepthLUT_sampler, sampleDepthTexCoords); rayleighDepth += camOpticalDepth[1] - sampleDepth[1]; mieDepth += camOpticalDepth[3] - sampleDepth[3]; rayleighDepth *= Kr4PI; mieDepth *= Km4PI; attenuation[0] = exp( -rayleighDepth / wavelength4[0] - mieDepth); attenuation[1] = exp( -rayleighDepth / wavelength4[1] - mieDepth); attenuation[2] = exp( -rayleighDepth / wavelength4[2] - mieDepth); rayleighSum[0] += rayleighDensity * attenuation[0]; rayleighSum[1] += rayleighDensity * attenuation[1]; rayleighSum[2] += rayleighDensity * attenuation[2]; mieSum[0] += mieDensity * attenuation[0]; mieSum[1] += mieDensity * attenuation[1]; mieSum[2] += mieDensity * attenuation[2]; samplePos += sampleRay; } float angle = dot(-ray, lightDir); float2 phase; float angle2 = angle * angle; float g2 = g*g; phase[0] = 0.75f * (1.0f + angle2); // Rayleigh Phase phase[1] = 1.5f * ((1 - g2) / (2 + g2)) * (1.0f + angle2) / // Mie Phase pow(1 + g2 - 2 *g * angle2, 1.5f); phase[0] *= 0.0025f * 15.0f; phase[1] *= 0.0025f * 15.0f; float4 color = float4(0.0f, 0.0f, 0.0f, 1.0f); color[0] = rayleighSum[0] * phase[0] / wavelength4[0] + mieSum[0] * phase[1]; color[1] = rayleighSum[1] * phase[0] / wavelength4[1] + mieSum[1] * phase[1]; color[2] = rayleighSum[2] * phase[0] / wavelength4[2] + mieSum[2] * phase[1]; color[0] = min(color[0], 1.0f); color[1] = min(color[1], 1.0f); color[2] = min(color[2], 1.0f); float3 vPos2 = mul( float4(vertexPosWorld, 1.0f), view); float4 vPos3 = mul( float4(vPos2, 1.0f), proj); output.pos = vPos3; output.color = color; return output;}
Im thankful for every idea!