Thanks

**nullsquared,** at really I only need the Camera-ToPixel normalized vector.

At the end, I'm want to do this:

1) Pass to the vertex program 3 corners of far-plane(TOP-LEFT, TOP-RIGHT, BOTTOM-LEFT) and calculate the current position of the pixel with this code:

Code: Select all

```
void main_vp_compositor(
// IN
float4 iPosition : POSITION,
// OUT
out float4 oPosition : POSITION,
out float3 oPosition_ : TEXCOORD0,
out float2 oUV : TEXCOORD1,
// UNIFORM
uniform float3 uCorner0, // Top-left
uniform float3 uCorner1, // Tio-right
uniform float3 uCorner2, // Bottom-left
uniform float4x4 uWorldViewProj)
{
oPosition = mul(uWorldViewProj, iPosition);
iPosition.xy = sign(iPosition.xy);
oUV = (float2(iPosition.x, -iPosition.y) + 1.0f) * 0.5f;
// Calculate segments
float3 x01 = uCorner1-uCorner0;
float3 x02 = uCorner2-uCorner0;
// Multiply segments by the current pixel position[0,1] range
x01 *= oUV.x;
x02 *= oUV.y;
// Final position = Origin + segment1 + segment2
oPosition_ = uCorner0+x01+x02;
}
```

(I've tried with uCorner0+x01+x02;uCorner0+x01-x02;uCorner0-x01+x02;uCorner0-x01-x02;...)

and finally, in the vertex pixel calculate the view vector with:

Code: Select all

```
void main_fp_compositor(
// IN
float3 iPosition : TEXCOORD0,
float2 iUV : TEXCOORD1,
// OUT
out float4 oColor : COLOR,
// UNIFORM
uniform float3 uLightDirection,
uniform float uIntensity,
uniform float3 uHGg,
uniform float3 uCameraPos,
uniform sampler2D uDepthMap : register(s0))
{
float3 view_vector = normalize(uCameraPos-iPosition);
float4 shafts = tex2D(uDepthMap, iUV);
float phase =compute_phase( view_vector, uHGg, -uLightDirection);
oColor = float4((0.15 + uIntensity*shafts.xyz)*phase,1);
}
```

But it seems not to work

, my c++ code to upload corners is: (updated each frame)

Code: Select all

```
// FAR_LEFT_TOP
static_cast<Ogre::MaterialPtr>(Ogre::MaterialManager::getSingleton().getByName("CompositorGodRays"))->
getTechnique(0)->getPass(0)->getVertexProgramParameters()->
setNamedConstant( "uCorner0", mCamera->getWorldSpaceCorners()[5] );
// FAR_RIGHT_TOP
static_cast<Ogre::MaterialPtr>(Ogre::MaterialManager::getSingleton().getByName("CompositorGodRays"))->
getTechnique(0)->getPass(0)->getVertexProgramParameters()->
setNamedConstant( "uCorner1", mCamera->getWorldSpaceCorners()[4] );
// FAR_LEFT_BOTTOM
static_cast<Ogre::MaterialPtr>(Ogre::MaterialManager::getSingleton().getByName("CompositorGodRays"))->
getTechnique(0)->getPass(0)->getVertexProgramParameters()->
setNamedConstant( "uCorner2", mCamera->getWorldSpaceCorners()[6] );
```

But it doesn't work, in all camera positions or orientations the result is the same for all pixels..., debug screenshot with

** oColor.xyz = (view_vector+1)/2;**
I don't know what the problem is...

! But it's driving me really crazy!!

Thanks!