~ubuntu-branches/ubuntu/trusty/blender/trusty

« back to all changes in this revision

Viewing changes to intern/cycles/kernel/kernel_emission.h

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha
  • Date: 2013-03-06 12:08:47 UTC
  • mfrom: (1.5.1) (14.1.8 experimental)
  • Revision ID: package-import@ubuntu.com-20130306120847-frjfaryb2zrotwcg
Tags: 2.66a-1ubuntu1
* Resynchronize with Debian (LP: #1076930, #1089256, #1052743, #999024,
  #1122888, #1147084)
* debian/control:
  - Lower build-depends on libavcodec-dev since we're not
    doing the libav9 transition in Ubuntu yet

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 
21
21
/* Direction Emission */
22
22
 
23
 
__device float3 direct_emissive_eval(KernelGlobals *kg, float rando,
24
 
        LightSample *ls, float u, float v, float3 I)
 
23
__device_noinline float3 direct_emissive_eval(KernelGlobals *kg, float rando,
 
24
        LightSample *ls, float u, float v, float3 I, float t, float time)
25
25
{
26
26
        /* setup shading at emitter */
27
27
        ShaderData sd;
32
32
                Ray ray;
33
33
                ray.D = ls->D;
34
34
                ray.P = ls->P;
 
35
                ray.t = 1.0f;
 
36
#ifdef __OBJECT_MOTION__
 
37
                ray.time = time;
 
38
#endif
35
39
                ray.dP.dx = make_float3(0.0f, 0.0f, 0.0f);
36
40
                ray.dP.dy = make_float3(0.0f, 0.0f, 0.0f);
 
41
#ifdef __CAMERA_MOTION__
 
42
                ray.time = time;
 
43
#endif
37
44
                shader_setup_from_background(kg, &sd, &ray);
38
 
                eval = shader_eval_background(kg, &sd, 0);
 
45
                eval = shader_eval_background(kg, &sd, 0, SHADER_CONTEXT_EMISSION);
39
46
        }
40
47
        else
41
48
#endif
42
49
        {
43
 
                shader_setup_from_sample(kg, &sd, ls->P, ls->Ng, I, ls->shader, ls->object, ls->prim, u, v);
 
50
#ifdef __HAIR__
 
51
                if(ls->type == LIGHT_STRAND)
 
52
                        shader_setup_from_sample(kg, &sd, ls->P, ls->Ng, I, ls->shader, ls->object, ls->prim, u, v, t, time, ls->prim);
 
53
                else
 
54
#endif
 
55
                        shader_setup_from_sample(kg, &sd, ls->P, ls->Ng, I, ls->shader, ls->object, ls->prim, u, v, t, time);
 
56
 
44
57
                ls->Ng = sd.Ng;
45
58
 
46
59
                /* no path flag, we're evaluating this for all closures. that's weak but
47
 
                   we'd have to do multiple evaluations otherwise */
48
 
                shader_eval_surface(kg, &sd, rando, 0);
 
60
                 * we'd have to do multiple evaluations otherwise */
 
61
                shader_eval_surface(kg, &sd, rando, 0, SHADER_CONTEXT_EMISSION);
49
62
 
50
63
                /* evaluate emissive closure */
51
64
                if(sd.flag & SD_EMISSION)
53
66
                else
54
67
                        eval = make_float3(0.0f, 0.0f, 0.0f);
55
68
        }
 
69
        
 
70
        eval *= ls->eval_fac;
56
71
 
57
72
        shader_release(kg, &sd);
58
73
 
59
74
        return eval;
60
75
}
61
76
 
62
 
__device bool direct_emission(KernelGlobals *kg, ShaderData *sd, int lindex,
 
77
__device_noinline bool direct_emission(KernelGlobals *kg, ShaderData *sd, int lindex,
63
78
        float randt, float rando, float randu, float randv, Ray *ray, BsdfEval *eval,
64
79
        bool *is_lamp)
65
80
{
66
81
        LightSample ls;
67
82
 
68
 
        float pdf = -1.0f;
69
 
 
70
 
#ifdef __MULTI_LIGHT__
 
83
#ifdef __NON_PROGRESSIVE__
71
84
        if(lindex != -1) {
72
85
                /* sample position on a specified light */
73
 
                light_select(kg, lindex, randu, randv, sd->P, &ls, &pdf);
 
86
                light_select(kg, lindex, randu, randv, sd->P, &ls);
74
87
        }
75
88
        else
76
89
#endif
77
90
        {
78
91
                /* sample a light and position on int */
79
 
                light_sample(kg, randt, randu, randv, sd->P, &ls, &pdf);
 
92
                light_sample(kg, randt, randu, randv, sd->time, sd->P, &ls);
80
93
        }
81
94
 
82
 
        /* compute pdf */
83
 
        if(pdf < 0.0f)
84
 
                pdf = light_sample_pdf(kg, &ls, -ls.D, ls.t);
85
 
 
86
 
        if(pdf == 0.0f)
 
95
        if(ls.pdf == 0.0f)
87
96
                return false;
88
97
 
89
98
        /* evaluate closure */
90
 
        float3 light_eval = direct_emissive_eval(kg, rando, &ls, randu, randv, -ls.D);
 
99
        float3 light_eval = direct_emissive_eval(kg, rando, &ls, randu, randv, -ls.D, ls.t, sd->time);
91
100
 
92
101
        if(is_zero(light_eval))
93
102
                return false;
99
108
 
100
109
        shader_bsdf_eval(kg, sd, ls.D, eval, &bsdf_pdf);
101
110
 
102
 
        if(ls.prim != ~0 || ls.type == LIGHT_BACKGROUND) {
 
111
        if(ls.shader & SHADER_USE_MIS) {
103
112
                /* multiple importance sampling */
104
 
                float mis_weight = power_heuristic(pdf, bsdf_pdf);
 
113
                float mis_weight = power_heuristic(ls.pdf, bsdf_pdf);
105
114
                light_eval *= mis_weight;
106
115
        }
107
 
        /* todo: clean up these weights */
108
 
        else if(ls.shader & SHADER_AREA_LIGHT)
109
 
                light_eval *= 0.25f; /* area lamp */
110
 
        else if(ls.t != FLT_MAX)
111
 
                light_eval *= 0.25f*M_1_PI_F; /* point lamp */
112
116
        
113
 
        bsdf_eval_mul(eval, light_eval/pdf);
 
117
        bsdf_eval_mul(eval, light_eval/ls.pdf);
114
118
 
115
119
        if(bsdf_eval_is_zero(eval))
116
120
                return false;
136
140
                ray->t = 0.0f;
137
141
        }
138
142
 
139
 
        *is_lamp = (ls.prim == ~0);
 
143
        /* return if it's a lamp for shadow pass */
 
144
        *is_lamp = (ls.prim == ~0 && ls.type != LIGHT_BACKGROUND);
140
145
 
141
146
        return true;
142
147
}
143
148
 
144
 
/* Indirect Emission */
 
149
/* Indirect Primitive Emission */
145
150
 
146
 
__device float3 indirect_emission(KernelGlobals *kg, ShaderData *sd, float t, int path_flag, float bsdf_pdf)
 
151
__device_noinline float3 indirect_primitive_emission(KernelGlobals *kg, ShaderData *sd, float t, int path_flag, float bsdf_pdf)
147
152
{
148
153
        /* evaluate emissive closure */
149
154
        float3 L = shader_emissive_eval(kg, sd);
150
155
 
 
156
#ifdef __HAIR__
 
157
        if(!(path_flag & PATH_RAY_MIS_SKIP) && (sd->flag & SD_SAMPLE_AS_LIGHT) && (sd->segment == ~0)) {
 
158
#else
151
159
        if(!(path_flag & PATH_RAY_MIS_SKIP) && (sd->flag & SD_SAMPLE_AS_LIGHT)) {
 
160
#endif
152
161
                /* multiple importance sampling, get triangle light pdf,
153
 
                   and compute weight with respect to BSDF pdf */
 
162
                 * and compute weight with respect to BSDF pdf */
154
163
                float pdf = triangle_light_pdf(kg, sd->Ng, sd->I, t);
155
164
                float mis_weight = power_heuristic(bsdf_pdf, pdf);
156
165
 
160
169
        return L;
161
170
}
162
171
 
 
172
/* Indirect Lamp Emission */
 
173
 
 
174
__device_noinline bool indirect_lamp_emission(KernelGlobals *kg, Ray *ray, int path_flag, float bsdf_pdf, float randt, float3 *emission)
 
175
{
 
176
        LightSample ls;
 
177
        int lamp = lamp_light_eval_sample(kg, randt);
 
178
 
 
179
        if(lamp == ~0)
 
180
                return false;
 
181
 
 
182
        if(!lamp_light_eval(kg, lamp, ray->P, ray->D, ray->t, &ls))
 
183
                return false;
 
184
        
 
185
        /* todo: missing texture coordinates */
 
186
        float u = 0.0f;
 
187
        float v = 0.0f;
 
188
        float3 L = direct_emissive_eval(kg, 0.0f, &ls, u, v, -ray->D, ls.t, ray->time);
 
189
 
 
190
        if(!(path_flag & PATH_RAY_MIS_SKIP)) {
 
191
                /* multiple importance sampling, get regular light pdf,
 
192
                 * and compute weight with respect to BSDF pdf */
 
193
                float mis_weight = power_heuristic(bsdf_pdf, ls.pdf);
 
194
                L *= mis_weight;
 
195
        }
 
196
 
 
197
        *emission = L;
 
198
        return true;
 
199
}
 
200
 
163
201
/* Indirect Background */
164
202
 
165
 
__device float3 indirect_background(KernelGlobals *kg, Ray *ray, int path_flag, float bsdf_pdf)
 
203
__device_noinline float3 indirect_background(KernelGlobals *kg, Ray *ray, int path_flag, float bsdf_pdf)
166
204
{
167
205
#ifdef __BACKGROUND__
168
206
        /* evaluate background closure */
169
207
        ShaderData sd;
170
208
        shader_setup_from_background(kg, &sd, ray);
171
 
        float3 L = shader_eval_background(kg, &sd, path_flag);
 
209
        float3 L = shader_eval_background(kg, &sd, path_flag, SHADER_CONTEXT_EMISSION);
172
210
        shader_release(kg, &sd);
173
211
 
174
212
#ifdef __BACKGROUND_MIS__
177
215
 
178
216
        if(!(path_flag & PATH_RAY_MIS_SKIP) && res) {
179
217
                /* multiple importance sampling, get background light pdf for ray
180
 
                   direction, and compute weight with respect to BSDF pdf */
 
218
                 * direction, and compute weight with respect to BSDF pdf */
181
219
                float pdf = background_light_pdf(kg, ray->D);
182
220
                float mis_weight = power_heuristic(bsdf_pdf, pdf);
183
221