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

« back to all changes in this revision

Viewing changes to intern/cycles/kernel/osl/osl_services.cpp

  • Committer: Package Import Robot
  • Author(s): Matteo F. Vescovi
  • Date: 2013-08-14 10:43:49 UTC
  • mfrom: (14.2.19 sid)
  • Revision ID: package-import@ubuntu.com-20130814104349-t1d5mtwkphp12dyj
Tags: 2.68a-3
* Upload to unstable
* debian/: python3.3 Depends simplified
  - debian/control: python3.3 Depends dropped
    for blender-data package
  - 0001-blender_thumbnailer.patch refreshed
* debian/control: libavcodec b-dep versioning dropped

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
#include "kernel_projection.h"
37
37
#include "kernel_differential.h"
38
38
#include "kernel_object.h"
 
39
#include "kernel_random.h"
39
40
#include "kernel_bvh.h"
40
41
#include "kernel_triangle.h"
41
42
#include "kernel_curve.h"
42
43
#include "kernel_primitive.h"
43
44
#include "kernel_projection.h"
44
45
#include "kernel_accumulate.h"
 
46
#include "kernel_camera.h"
45
47
#include "kernel_shader.h"
46
48
 
47
49
CCL_NAMESPACE_BEGIN
75
77
ustring OSLRenderServices::u_geom_trianglevertices("geom:trianglevertices");
76
78
ustring OSLRenderServices::u_geom_polyvertices("geom:polyvertices");
77
79
ustring OSLRenderServices::u_geom_name("geom:name");
 
80
ustring OSLRenderServices::u_is_smooth("geom:is_smooth");
78
81
#ifdef __HAIR__
79
82
ustring OSLRenderServices::u_is_curve("geom:is_curve");
80
83
ustring OSLRenderServices::u_curve_thickness("geom:curve_thickness");
101
104
{
102
105
}
103
106
 
104
 
void OSLRenderServices::thread_init(KernelGlobals *kernel_globals_)
 
107
void OSLRenderServices::thread_init(KernelGlobals *kernel_globals_, OSL::TextureSystem *osl_ts_)
105
108
{
106
109
        kernel_globals = kernel_globals_;
 
110
        osl_ts = osl_ts_;
107
111
}
108
112
 
109
113
bool OSLRenderServices::get_matrix(OSL::Matrix44 &result, OSL::TransformationPtr xform, float time)
111
115
        /* this is only used for shader and object space, we don't really have
112
116
         * a concept of shader space, so we just use object space for both. */
113
117
        if (xform) {
114
 
                KernelGlobals *kg = kernel_globals;
115
118
                const ShaderData *sd = (const ShaderData *)xform;
 
119
                KernelGlobals *kg = sd->osl_globals;
116
120
                int object = sd->object;
117
121
 
118
122
                if (object != ~0) {
141
145
        /* this is only used for shader and object space, we don't really have
142
146
         * a concept of shader space, so we just use object space for both. */
143
147
        if (xform) {
144
 
                KernelGlobals *kg = kernel_globals;
145
148
                const ShaderData *sd = (const ShaderData *)xform;
 
149
                KernelGlobals *kg = sd->osl_globals;
146
150
                int object = sd->object;
147
151
 
148
152
                if (object != ~0) {
234
238
#ifdef __OBJECT_MOTION__
235
239
                        Transform tfm = sd->ob_tfm;
236
240
#else
237
 
                        KernelGlobals *kg = kernel_globals;
 
241
                        KernelGlobals *kg = sd->osl_globals;
238
242
                        Transform tfm = object_fetch_transform(kg, object, OBJECT_TRANSFORM);
239
243
#endif
240
244
                        tfm = transform_transpose(tfm);
259
263
#ifdef __OBJECT_MOTION__
260
264
                        Transform tfm = sd->ob_itfm;
261
265
#else
262
 
                        KernelGlobals *kg = kernel_globals;
 
266
                        KernelGlobals *kg = sd->osl_globals;
263
267
                        Transform tfm = object_fetch_transform(kg, object, OBJECT_INVERSE_TRANSFORM);
264
268
#endif
265
269
                        tfm = transform_transpose(tfm);
625
629
                ustring object_name = kg->osl->object_names[sd->object];
626
630
                return set_attribute_string(object_name, type, derivatives, val);
627
631
        }
628
 
        
 
632
        else if (name == u_is_smooth) {
 
633
                float f = ((sd->shader & SHADER_SMOOTH_NORMAL) != 0);
 
634
                return set_attribute_float(f, type, derivatives, val);
 
635
        }
629
636
#ifdef __HAIR__
630
637
        /* Hair Attributes */
631
638
        else if (name == u_is_curve) {
648
655
bool OSLRenderServices::get_background_attribute(KernelGlobals *kg, ShaderData *sd, ustring name,
649
656
                                                 TypeDesc type, bool derivatives, void *val)
650
657
{
651
 
        /* Ray Length */
652
658
        if (name == u_path_ray_length) {
 
659
                /* Ray Length */
653
660
                float f = sd->ray_length;
654
661
                return set_attribute_float(f, type, derivatives, val);
655
662
        }
656
 
        
 
663
        else if (name == u_ndc) {
 
664
                /* NDC coordinates with special exception for otho */
 
665
                OSLThreadData *tdata = kg->osl_tdata;
 
666
                OSL::ShaderGlobals *globals = &tdata->globals;
 
667
                float3 ndc[3];
 
668
 
 
669
                if((globals->raytype & PATH_RAY_CAMERA) && sd->object == ~0 && kernel_data.cam.type == CAMERA_ORTHOGRAPHIC) {
 
670
                        ndc[0] = camera_world_to_ndc(kg, sd, sd->ray_P);
 
671
 
 
672
                        if(derivatives) {
 
673
                                ndc[1] = camera_world_to_ndc(kg, sd, sd->ray_P + sd->ray_dP.dx) - ndc[0];
 
674
                                ndc[2] = camera_world_to_ndc(kg, sd, sd->ray_P + sd->ray_dP.dy) - ndc[0];
 
675
                        }
 
676
                }
 
677
                else {
 
678
                        ndc[0] = camera_world_to_ndc(kg, sd, sd->P);
 
679
 
 
680
                        if(derivatives) {
 
681
                                ndc[1] = camera_world_to_ndc(kg, sd, sd->P + sd->dP.dx) - ndc[0];
 
682
                                ndc[2] = camera_world_to_ndc(kg, sd, sd->P + sd->dP.dy) - ndc[0];
 
683
                        }
 
684
                }
 
685
 
 
686
                return set_attribute_float3(ndc, type, derivatives, val);
 
687
        }
657
688
        else
658
689
                return false;
659
690
}
661
692
bool OSLRenderServices::get_attribute(void *renderstate, bool derivatives, ustring object_name,
662
693
                                      TypeDesc type, ustring name, void *val)
663
694
{
664
 
        KernelGlobals *kg = kernel_globals;
665
695
        ShaderData *sd = (ShaderData *)renderstate;
 
696
        KernelGlobals *kg = sd->osl_globals;
666
697
        int object, prim, segment;
667
698
 
668
699
        /* lookup of attribute on another object */
737
768
                                float s, float t, float dsdx, float dtdx,
738
769
                                float dsdy, float dtdy, float *result)
739
770
{
740
 
        OSL::TextureSystem *ts = kernel_globals->osl->ts;
 
771
        OSL::TextureSystem *ts = osl_ts;
741
772
        bool status = ts->texture(filename, options, s, t, dsdx, dtdx, dsdy, dtdy, result);
742
773
 
743
774
        if(!status) {
759
790
                                  const OSL::Vec3 &dPdx, const OSL::Vec3 &dPdy,
760
791
                                  const OSL::Vec3 &dPdz, float *result)
761
792
{
762
 
        OSL::TextureSystem *ts = kernel_globals->osl->ts;
 
793
        OSL::TextureSystem *ts = osl_ts;
763
794
        bool status = ts->texture3d(filename, options, P, dPdx, dPdy, dPdz, result);
764
795
 
765
796
        if(!status) {
781
812
                                    OSL::ShaderGlobals *sg, const OSL::Vec3 &R,
782
813
                                    const OSL::Vec3 &dRdx, const OSL::Vec3 &dRdy, float *result)
783
814
{
784
 
        OSL::TextureSystem *ts = kernel_globals->osl->ts;
 
815
        OSL::TextureSystem *ts = osl_ts;
785
816
        bool status = ts->environment(filename, options, R, dRdx, dRdy, result);
786
817
 
787
818
        if(!status) {
802
833
                                         ustring dataname,
803
834
                                         TypeDesc datatype, void *data)
804
835
{
805
 
        OSL::TextureSystem *ts = kernel_globals->osl->ts;
 
836
        OSL::TextureSystem *ts = osl_ts;
806
837
        return ts->get_texture_info(filename, subimage, dataname, datatype, data);
807
838
}
808
839
 
860
891
        tracedata->init = true;
861
892
 
862
893
        /* raytrace */
863
 
        return scene_intersect(kernel_globals, &ray, ~0, &tracedata->isect);
 
894
#ifdef __HAIR__
 
895
        return scene_intersect(sd->osl_globals, &ray, ~0, &tracedata->isect, NULL, 0.0f, 0.0f);
 
896
#else
 
897
        return scene_intersect(sd->osl_globals, &ray, ~0, &tracedata->isect);
 
898
#endif
864
899
}
865
900
 
866
901
 
879
914
                                return set_attribute_float(f, type, derivatives, val);
880
915
                        }
881
916
                        else {
882
 
                                KernelGlobals *kg = kernel_globals;
883
917
                                ShaderData *sd = &tracedata->sd;
 
918
                                KernelGlobals *kg = sd->osl_globals;
884
919
 
885
920
                                if(!tracedata->setup) {
886
921
                                        /* lazy shader data setup */