MCPcopy Create free account
hub / github.com/RenderKit/embree / renderPixelStandard

Function renderPixelStandard

tutorials/point_geometry/point_geometry_device.cpp:106–162  ·  view source on GitHub ↗

task that renders a single screen tile */

Source from the content-addressed store, hash-verified

104
105/* task that renders a single screen tile */
106void renderPixelStandard(const TutorialData& data,
107 int x, int y,
108 int* pixels,
109 const unsigned int width,
110 const unsigned int height,
111 const float time,
112 const ISPCCamera& camera, RayStats& stats)
113{
114 /* initialize ray */
115 Ray ray(Vec3fa(camera.xfm.p), Vec3fa(normalize(x*camera.xfm.l.vx + y*camera.xfm.l.vy + camera.xfm.l.vz)), 0.0f, inf);
116
117 /* intersect ray with scene */
118 RTCIntersectArguments iargs;
119 rtcInitIntersectArguments(&iargs);
120 iargs.feature_mask = (RTCFeatureFlags)(FEATURE_MASK);
121
122 rtcTraversableIntersect1(data.g_traversable,RTCRayHit_(ray),&iargs);
123 RayStats_addRay(stats);
124
125 /* shade pixels */
126 Vec3fa color = Vec3fa(0.0f);
127 if (ray.geomID != RTC_INVALID_GEOMETRY_ID)
128 {
129 /* interpolate diffuse color */
130 Vec3fa diffuse = data.point_colors[ray.geomID ? ray.primID : 0];
131
132 /* calculate smooth shading normal */
133 Vec3fa Ng = normalize(ray.Ng);
134 color = color + diffuse*0.5f;
135 Vec3fa lightDir = normalize(Vec3fa(-1,-1,-1));
136
137 /* initialize shadow ray */
138 Ray shadow(ray.org + ray.tfar*ray.dir, neg(lightDir), 0.001f, inf, 0.0f);
139
140 /* trace shadow ray */
141 RTCOccludedArguments sargs;
142 rtcInitOccludedArguments(&sargs);
143 sargs.feature_mask = (RTCFeatureFlags)(FEATURE_MASK);
144
145 rtcTraversableOccluded1(data.g_traversable,RTCRay_(shadow),&sargs);
146 RayStats_addShadowRay(stats);
147
148 /* add light contribution */
149 if (shadow.tfar >= 0.0f) {
150 Vec3fa r = normalize(reflect(ray.dir,Ng));
151 float s = pow(clamp(dot(r,lightDir),0.0f,1.0f),10.0f);
152 float d = clamp(-dot(lightDir,Ng),0.0f,1.0f);
153 color = color + diffuse*d + 0.5f*Vec3fa(s);
154 }
155 }
156
157 /* write color to framebuffer */
158 unsigned int r = (unsigned int) (255.0f * clamp(color.x,0.0f,1.0f));
159 unsigned int g = (unsigned int) (255.0f * clamp(color.y,0.0f,1.0f));
160 unsigned int b = (unsigned int) (255.0f * clamp(color.z,0.0f,1.0f));
161 pixels[y*width+x] = (b << 16) + (g << 8) + r;
162}
163

Callers 2

renderTileTaskFunction · 0.70
renderFrameStandardFunction · 0.70

Calls 15

RTCRayHit_Function · 0.85
RayStats_addRayFunction · 0.85
negFunction · 0.85
rtcInitOccludedArgumentsFunction · 0.85
RTCRay_Function · 0.85
RayStats_addShadowRayFunction · 0.85
reflectFunction · 0.85
Vec3faClass · 0.50
normalizeFunction · 0.50
rtcTraversableIntersect1Function · 0.50
rtcTraversableOccluded1Function · 0.50

Tested by

no test coverage detected