Changeset View
Standalone View
source/blender/render/intern/source/shadeoutput.c
| Context not available. | |||||
| shr->combined[3]= shr->alpha; | shr->combined[3]= shr->alpha; | ||||
| } | } | ||||
| /* used for shader node */ | |||||
| inline static float lamp_get_info_internal(ShadeInput *shi, GroupObject *go, float lv[3], float *dist, float shadow[4]) | |||||
brecht: Inline is not a valid keyword in C. I wouldn't really use that here either, optimizing… | |||||
irieAuthorUnsubmitted Not Done Inline ActionsAh sorry, I forgot to remove this "inline" keyword. Anyway, this function is too large to be inline. irie: Ah sorry, I forgot to remove this "inline" keyword. Anyway, this function is too large to be… | |||||
| { | |||||
| LampRen *lar = go->lampren; | |||||
| float visifac, inp; | |||||
| if (!lar || lar->type == LA_YF_PHOTON | |||||
| || ((lar->mode & LA_LAYER) && (lar->lay & shi->obi->lay) == 0) | |||||
| || (lar->lay & shi->lay) == 0) | |||||
| return 0.0f; | |||||
| visifac = lamp_get_visibility(lar, shi->co, lv, dist); | |||||
| if (visifac == 0.0f | |||||
| || lar->type == LA_HEMI | |||||
| || (lar->type != LA_SPOT && !(lar->mode & LA_SHAD_RAY)) | |||||
| || (R.r.scemode & R_BUTS_PREVIEW)) | |||||
| return visifac; | |||||
| inp = dot_v3v3(shi->vn, lv); | |||||
| if (inp <= 0.0f) | |||||
| return visifac; | |||||
| lamp_get_shadow(lar, shi, inp, shadow, shi->depth); | |||||
| shadow[0] *= shadow[3]; | |||||
| shadow[1] *= shadow[3]; | |||||
| shadow[2] *= shadow[3]; | |||||
| shadow[3] = 1.0f - rgb_to_grayscale(shadow); | |||||
brechtUnsubmitted Not Done Inline ActionsThe shade 4 value vector is a bit strange, you probably do not want to expose like this, as if the 4th channel is alpha. I can't quite remember what it is but I think you could multiply the 4th channel into the other channels or something like this, and leave the alpha component to 1.0 always. The results that you want is probably that color * shadow * visibility_factor * dot(N, light_vector) gives you the same exact shading results as a simple diffuse shader with a regular blender material? brecht: The shade 4 value vector is a bit strange, you probably do not want to expose like this, as if… | |||||
irieAuthorUnsubmitted Not Done Inline ActionsThe calculations in this part are exactly same as "Shadows Only" materials. lamp_get_shadow() returns the shadow color as RGB channels and the light absorption as alpha channel. The RGB channels were already multiplied by the 4th channel here, so the alpha channel simply can be set 1.0. irie: The calculations in this part are exactly same as "Shadows Only" materials. lamp_get_shadow()… | |||||
brechtUnsubmitted Not Done Inline ActionsOk then. In case you haven't it's probably a good idea still to verify that multiplying all those things together gives you the same result as a perfect white diffuse shader, to verify if it's all correct. brecht: Ok then. In case you haven't it's probably a good idea still to verify that multiplying all… | |||||
irieAuthorUnsubmitted Not Done Inline ActionsI confirmed the result is exactly same as Lambert shader when the diffuse color is 100% white and the ray bias is disabled. irie: I confirmed the result is exactly same as Lambert shader when the diffuse color is 100% white… | |||||
| if (shadow[3] < 0.0f) | |||||
| shadow[3] = 0.0f; | |||||
| return visifac; | |||||
| } | |||||
| float lamp_get_info(ShadeInput *shi, Object *lamp_obj, float col[4], float lv[3], float *dist, float shadow[4]) | |||||
brechtUnsubmitted Not Done Inline ActionsI think this function should have a RE_ prefix. There's a few others that don't but they should actually have it as well, just to avoid naming conflicts and make it clear which module this function is in. brecht: I think this function should have a RE_ prefix. There's a few others that don't but they should… | |||||
irieAuthorUnsubmitted Not Done Inline ActionsI see, will add the RE_ prefix. irie: I see, will add the RE_ prefix. | |||||
| { | |||||
| if (lamp_obj->type == OB_LAMP) { | |||||
brechtUnsubmitted Not Done Inline ActionsIf this is not true there will be uninitialized values. It's a rare case as you already check for the right object type when assigning the object to the node, but with objects linked from other files the types can change so this check is needed, just need to ensure the values are zeroed then. brecht: If this is not true there will be uninitialized values. It's a rare case as you already check… | |||||
irieAuthorUnsubmitted Not Done Inline ActionsWill change it to set values anyway, though the uninitialized values shouldn't cause serious problems. irie: Will change it to set values anyway, though the uninitialized values shouldn't cause serious… | |||||
| GroupObject *go; | |||||
| Lamp *lamp = (Lamp *)lamp_obj->data; | |||||
| col[0] = lamp->r * lamp->energy; | |||||
| col[1] = lamp->g * lamp->energy; | |||||
| col[2] = lamp->b * lamp->energy; | |||||
| col[3] = 1.0f; | |||||
| shadow[0] = shadow[1] = shadow[2] = 1.0f; | |||||
| shadow[3] = 0.0f; | |||||
brechtUnsubmitted Not Done Inline ActionsDon't forget to set this one to 1 as well. brecht: Don't forget to set this one to 1 as well. | |||||
| if (R.r.scemode & R_BUTS_PREVIEW) { | |||||
| for (go = R.lights.first; go; go = go->next) { | |||||
| if (strcmp(go->ob->id.name + 2, "Lamp.002") == 0) | |||||
brechtUnsubmitted Not Done Inline ActionsThis seems like some kind of debug code left in? Not sure why there is a hardcoded name here. brecht: This seems like some kind of debug code left in? Not sure why there is a hardcoded name here. | |||||
irieAuthorUnsubmitted Not Done Inline ActionsChecking lamp name is same as preview_prepare_scene() in render_preview.c:365. "Lamp.002" is used for searching main key light of the material preview. Is there better way to do that? irie: Checking lamp name is same as preview_prepare_scene() in render_preview.c:365. "Lamp.002" is… | |||||
brechtUnsubmitted Not Done Inline ActionsAh ok. Maybe add a comment to indicate that that's what this does. brecht: Ah ok. Maybe add a comment to indicate that that's what this does. | |||||
| return lamp_get_info_internal(shi, go, lv, dist, shadow); | |||||
| } | |||||
| return 0.0f; | |||||
| } | |||||
| if (shi->light_override) { | |||||
| for (go = shi->light_override->gobject.first; go; go = go->next) { | |||||
| if (go->ob == lamp_obj) | |||||
| return lamp_get_info_internal(shi, go, lv, dist, shadow); | |||||
| } | |||||
| } | |||||
| if (shi->mat && shi->mat->group) { | |||||
| for (go = shi->mat->group->gobject.first; go; go = go->next) { | |||||
| if (go->ob == lamp_obj) | |||||
| return lamp_get_info_internal(shi, go, lv, dist, shadow); | |||||
| } | |||||
| } | |||||
| for (go = R.lights.first; go; go = go->next) { | |||||
| if (go->ob == lamp_obj) | |||||
| return lamp_get_info_internal(shi, go, lv, dist, shadow); | |||||
| } | |||||
| } | |||||
| return 0.0f; | |||||
| } | |||||
| Context not available. | |||||
Inline is not a valid keyword in C. I wouldn't really use that here either, optimizing compilers should be smart enough to decide this kind of thing.