Advertisement
Guest User

Untitled

a guest
May 25th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1.  
  2. float3 GetConeTracedCubeMap(float3 ray, float mip)
  3. {
  4. float3 sum = 0;
  5.  
  6. if (mip < 0.10) {
  7. sum = texCUBElod(EnvMap, float4(ray, mip)).rgb;
  8. }
  9. else
  10. {
  11.  
  12. float alpha = mip / 8.0;
  13. float3 tangent = normalize(cross(float3(0,0,1),ray));
  14. float3 bitangent = normalize(cross(tangent, ray)); // both should be normalized, so why normalize?
  15.  
  16. float radius = alpha * 90 ;
  17. float raydist = 100; // don't think I should touch this
  18.  
  19. int nCubemapBlurConeSides = 15;
  20. float angStep = PI2 / nCubemapBlurConeSides;
  21.  
  22.  
  23.  
  24. // this creates rays that deviate from the normal reflection ray
  25.  
  26.  
  27. for(int n=0; n < nCubemapBlurConeSides; n++)
  28. {
  29. float2 wConeVertexPos = float2( cos(angStep*n) , sin(angStep*n)) * radius * 0.33; // vertex position in cone in worldspace
  30. float3 wConeVertexPosTransformed = (ray*raydist) + wConeVertexPos.x * tangent + wConeVertexPos.y * bitangent; // vertex position in cone in worldspace & transformed to cone
  31. sum = sum + texCUBElod(EnvMap, float4(wConeVertexPosTransformed, mip)).rgb;
  32. }
  33.  
  34. for(int n=0; n < nCubemapBlurConeSides; n++)
  35. {
  36. float2 wConeVertexPos = float2( cos(angStep*n) , sin(angStep*n)) * radius * 0.66; // vertex position in cone in worldspace
  37. float3 wConeVertexPosTransformed = (ray*raydist) + wConeVertexPos.x * tangent + wConeVertexPos.y * bitangent; // vertex position in cone in worldspace & transformed to cone
  38. sum = sum + texCUBElod(EnvMap, float4(wConeVertexPosTransformed, mip)).rgb;
  39. }
  40.  
  41.  
  42. for(int n=0; n < nCubemapBlurConeSides; n++)
  43. {
  44. float2 wConeVertexPos = float2( cos(angStep*n) , sin(angStep*n)) * radius; // vertex position in cone in worldspace
  45. float3 wConeVertexPosTransformed = (ray*raydist) + wConeVertexPos.x * tangent + wConeVertexPos.y * bitangent; // vertex position in cone in worldspace & transformed to cone
  46. sum = sum + texCUBElod(EnvMap, float4(wConeVertexPosTransformed, mip)).rgb;
  47. }
  48.  
  49.  
  50. sum = sum / (nCubemapBlurConeSides * 3 );
  51. }
  52.  
  53. return sum ;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement