Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- float3 GetConeTracedCubeMap(float3 ray, float mip)
- {
- float3 sum = 0;
- if (mip < 0.10) {
- sum = texCUBElod(EnvMap, float4(ray, mip)).rgb;
- }
- else
- {
- float alpha = mip / 8.0;
- float3 tangent = normalize(cross(float3(0,0,1),ray));
- float3 bitangent = normalize(cross(tangent, ray)); // both should be normalized, so why normalize?
- float radius = alpha * 90 ;
- float raydist = 100; // don't think I should touch this
- int nCubemapBlurConeSides = 15;
- float angStep = PI2 / nCubemapBlurConeSides;
- // this creates rays that deviate from the normal reflection ray
- for(int n=0; n < nCubemapBlurConeSides; n++)
- {
- float2 wConeVertexPos = float2( cos(angStep*n) , sin(angStep*n)) * radius * 0.33; // vertex position in cone in worldspace
- float3 wConeVertexPosTransformed = (ray*raydist) + wConeVertexPos.x * tangent + wConeVertexPos.y * bitangent; // vertex position in cone in worldspace & transformed to cone
- sum = sum + texCUBElod(EnvMap, float4(wConeVertexPosTransformed, mip)).rgb;
- }
- for(int n=0; n < nCubemapBlurConeSides; n++)
- {
- float2 wConeVertexPos = float2( cos(angStep*n) , sin(angStep*n)) * radius * 0.66; // vertex position in cone in worldspace
- float3 wConeVertexPosTransformed = (ray*raydist) + wConeVertexPos.x * tangent + wConeVertexPos.y * bitangent; // vertex position in cone in worldspace & transformed to cone
- sum = sum + texCUBElod(EnvMap, float4(wConeVertexPosTransformed, mip)).rgb;
- }
- for(int n=0; n < nCubemapBlurConeSides; n++)
- {
- float2 wConeVertexPos = float2( cos(angStep*n) , sin(angStep*n)) * radius; // vertex position in cone in worldspace
- float3 wConeVertexPosTransformed = (ray*raydist) + wConeVertexPos.x * tangent + wConeVertexPos.y * bitangent; // vertex position in cone in worldspace & transformed to cone
- sum = sum + texCUBElod(EnvMap, float4(wConeVertexPosTransformed, mip)).rgb;
- }
- sum = sum / (nCubemapBlurConeSides * 3 );
- }
- return sum ;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement