protected void WarpSlice( int _ThetaHIndex, int _ThetaDIndex, double _Warp, ref Vector3 _Result ) { double ThetaH = Math.PI * _ThetaHIndex / 180.0; double ThetaD = Math.PI * _ThetaDIndex / 180.0; double PhiD = Math.PI * _Warp / 180.0; if ( PhiD > 0.5 * Math.PI ) PhiD = Math.PI - PhiD; double Scale = ComputeScaleFactor( ThetaH, ThetaD, PhiD ); double ScaledThetaH = ThetaH / Scale; double ScaledThetaD = ThetaD / Scale; // int ScaledThetaHIndex = (int) Math.Min( 89, 89 * Math.Sqrt( 2.0 * ScaledThetaH / Math.PI ) ); // int ScaledThetaDIndex = (int) Math.Min( 89, 180 * ScaledThetaD / Math.PI ); int ScaledThetaHIndex = (int) (89 * Math.Sqrt( 2.0 * ScaledThetaH / Math.PI )); int ScaledThetaDIndex = (int) (180 * ScaledThetaD / Math.PI); if ( ScaledThetaHIndex > 89 || ScaledThetaDIndex > 89 ) { // Out of range! _Result.Set( 0, 0, 0 ); return; } _Result = m_BRDF[ScaledThetaHIndex,ScaledThetaDIndex,90]; // int U = _ThetaHIndex * INTERSECTIONS_TABLE_SIZE / 90; // int V = _ThetaDIndex * INTERSECTIONS_TABLE_SIZE / 90; // double C = m_Intersections[U,V]; // _Result.Set( C, C, C ); }
public static void half_diff_coords_to_std_coords( double _ThetaHalf, double _PhiHalf, double _ThetaDiff, double _PhiDiff, ref Vector3 _In, ref Vector3 _Out ) { double SinTheta_half = Math.Sin( _ThetaHalf ); Half.Set( Math.Cos( _PhiHalf ) * SinTheta_half, Math.Sin( _PhiHalf ) * SinTheta_half, Math.Cos( _ThetaHalf ) ); // Build the 2 vectors representing the frame in which we can use the diff angles Vector3 OrthoX; Half.Cross( ref Normal, out OrthoX ); if ( OrthoX.LengthSq() < 1e-6 ) OrthoX.Set( 1, 0, 0 ); else OrthoX.Normalize(); Vector3 OrthoY; Half.Cross( ref OrthoX, out OrthoY ); // Rotate using diff angles to retrieve incoming direction Half.Rotate( ref OrthoX, -_ThetaDiff, out Temp ); Temp.Rotate( ref Half, _PhiDiff, out _In ); // ...or by mirroring in "Half tangent space" double MirrorX = -_In.Dot( ref OrthoX ); double MirrorY = -_In.Dot( ref OrthoY ); double z = _In.Dot( ref Half ); _Out.Set( MirrorX*OrthoX.x + MirrorY*OrthoY.x + z*Half.x, MirrorX*OrthoX.y + MirrorY*OrthoY.y + z*Half.y, MirrorX*OrthoX.z + MirrorY*OrthoY.z + z*Half.z ); // if ( _In.z < -0.5 || _Out.z < -0.5 ) // throw new Exception( "RHA MAIS MERDE!" ); }