0027900: Coding rules - drop redundant Name parameter from V3d_Viewer constructor
[occt.git] / src / Shaders / RaytraceRender.fs
CommitLineData
fc73a202 1out vec4 OutColor;
2
189f85a3 3// Seed for random number generator
4uniform int uFrameRndSeed;
5
6// Weight of current frame related to accumulated frames.
7uniform float uSampleWeight;
8
9//! Input accumulated image.
10uniform sampler2D uAccumTexture;
11
8c820969 12//! Enabled/disbales using of single RNG seed for image 16x16 blocks.
13//! Increases performance up to 4 times, but noise becomes structured.
14uniform int uBlockedRngEnabled;
15
16#define MAX_RADIANCE vec3 (10.f)
17
fc73a202 18// =======================================================================
19// function : main
20// purpose :
21// =======================================================================
22void main (void)
23{
189f85a3 24#ifndef PATH_TRACING
fc73a202 25 SRay aRay = GenerateRay (vPixel);
189f85a3 26#else
27 ivec2 aWinSize = textureSize (uAccumTexture, 0);
28
f2474958 29 SeedRand (uFrameRndSeed, aWinSize.x, uBlockedRngEnabled == 0 ? 1 : 8);
189f85a3 30
31 SRay aRay = GenerateRay (vPixel +
32 vec2 (RandFloat() + 1.f, RandFloat() + 1.f) / vec2 (aWinSize));
33#endif
34
fc73a202 35 vec3 aInvDirect = 1.f / max (abs (aRay.Direct), SMALL);
189f85a3 36
fc73a202 37 aInvDirect = vec3 (aRay.Direct.x < 0.f ? -aInvDirect.x : aInvDirect.x,
38 aRay.Direct.y < 0.f ? -aInvDirect.y : aInvDirect.y,
39 aRay.Direct.z < 0.f ? -aInvDirect.z : aInvDirect.z);
40
189f85a3 41#ifdef PATH_TRACING
189f85a3 42 vec4 aColor = PathTrace (aRay, aInvDirect);
43
44 if (any (isnan (aColor.xyz)))
45 {
8c820969 46 aColor.rgb = ZERO;
189f85a3 47 }
48
8c820969 49 aColor.rgb = min (aColor.rgb, MAX_RADIANCE);
189f85a3 50
8c820969 51 OutColor = mix (texture2D (uAccumTexture, vPixel), aColor, uSampleWeight);
189f85a3 52#else
fc73a202 53 OutColor = clamp (Radiance (aRay, aInvDirect), 0.f, 1.f);
189f85a3 54#endif
fc73a202 55}