Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: shadow and normal problem

  1. #1
    Join Date
    Dec 2004
    Location
    Moscow, Russia
    Posts
    347

    Default shadow and normal problem

    Why if I try to change state->normal I always get shadow(raytrace shadow) problem?

    [img]http://www.puppet.cgtalk.ru/shadow_and_normal.jpg[/img]

    1.On left image just normal lambert shader.
    2.On center image I try to null state->normal before call mi_sample_light() and restore normal inside mi_sample_light()
    It always happend if try to change original normal (for example for bump too).
    3.On right image red faces away from light. if(mi_vector_dot(&state->normal_geom, &dir) < 0)
    White line it's terminator.

    I understand that it's just shadow but why it's not happend if I don't change normal?
    For example maya's shaders avoid this problem but how?
    How can I fix it?
    Pavel Ledin

  2. #2
    Join Date
    Dec 2004
    Location
    Marina Del Rey, California
    Posts
    2,916

    Default

    Why are you nulling state->normal?
    Won't that have the mi_sample_light return 0 before even executing in some cases? Thus leading to the blackish triangles at the edges.

    If you tesselate the geometry further, do the blackish triangles reduce in size?

    What kind of light is it?
    Barton Gawboy
    Training and Special Projects, NVIDIA ARC
    LAmrUG Forum Originator

  3. #3
    Join Date
    Dec 2004
    Location
    Moscow, Russia
    Posts
    347

    Default

    Why are you nulling state->normal?
    Null normal it's just example. Really I need make bump.
    It's happend when I try to change normal.
    It's always happend when you tru to use mr bump (mib_passthrough_bump_map)

    If you tesselate the geometry further, do the blackish triangles reduce in size?
    Yes, it's black faces.

    What kind of light is it?
    Any lights, for example mib_spot_light
    Pavel Ledin

  4. #4
    Join Date
    Dec 2004
    Location
    Moscow, Russia
    Posts
    347

    Default

    for example I try code like this:

    Code:
    	miVector random_vector;
    	random_vector&#46;x = 0&#46;2 * mi_random&#40;&#41;;
    	random_vector&#46;y = 0&#46;2 * mi_random&#40;&#41;;
    	random_vector&#46;z = 0&#46;2 * mi_random&#40;&#41;;
    	mi_vector_add&#40;&state->normal, &state->normal, &random_vector&#41;;
    	mi_vector_normalize&#40;&state->normal&#41;;
    
    	if &#40;m == 1&#41;
    		mi_inclusive_lightlist&#40;&n_l, &light, state&#41;;
    	else if &#40;m == 2&#41;
    		mi_exclusive_lightlist&#40;&n_l, &light, state&#41;;
    
    	for &#40;n=0; n < n_l; n++, light++&#41;
    	&#123;
    		sum&#46;r = sum&#46;g = sum&#46;b = 0;
    		samples = 0;
    		while &#40;mi_sample_light&#40;&color, &dir, &dot_nl, state, *light, &samples&#41;&#41;
    		&#123;
    			sum&#46;r += color&#46;r;
    			sum&#46;g += color&#46;g;
    			sum&#46;b += color&#46;b;
    		&#125;
    		if &#40;samples&#41;
    		&#123;
    			result->r += sum&#46;r / samples;
    			result->g += sum&#46;g / samples;
    			result->b += sum&#46;b / samples;
    		&#125;
    	&#125;
    	return&#40;miTRUE&#41;;
    &#125;
    Pavel Ledin

  5. #5
    Join Date
    Sep 2005
    Location
    France
    Posts
    498

    Default

    Hi,

    I don't know if this can be helpful but I had strange results with lights using :
    if (m == 1)
    mi_inclusive_lightlist(&n_l, &light, state);
    else if (m == 2)
    mi_exclusive_lightlist(&n_l, &light, state);
    My shader could not use more than one light correctly. As soon as 2 lights were present, the inclusive or exclusive list didn't worked.
    So I am wondering if this code is still right for Mental Ray 3.4 ?

    I did some modifications to the state normal which worked fine. Even with state->point.
    But you should always restore them after the process is finished.
    Regards,
    David Lanier
    R&D, plugins & shaders development company
    http://www.dl3d.com

  6. #6
    Join Date
    Dec 2004
    Location
    Moscow, Russia
    Posts
    347

    Default

    I have no problems with mode with mr 3.3(as I remember) and 3.4 too.

    Try to change normals to more value.
    For example try my code. It's just shake normals a little bit to random value from 0 to 0.2

    Looks like I did solve my problem but it's not pretty solution.

    Now I should:

    apply bump
    compute some variables
    restore original normal before enter to light loop.
    apply bump inside every mi_sample_light() call
    and restore original normal before exit from every mi_sample_light() call
    apply bump again after light loop

    It's strange...
    mr bump is still buggy (mib_passthrough_bump_map) and I suppose no way to solve it.
    Pavel Ledin

  7. #7
    Join Date
    Dec 2004
    Location
    Marina Del Rey, California
    Posts
    2,916

    Default

    If you change the normal enough in some cases, isn't it considering the light to be entering from the back side? Do you need to null state->pri?
    Barton Gawboy
    Training and Special Projects, NVIDIA ARC
    LAmrUG Forum Originator

  8. #8
    Join Date
    Dec 2004
    Location
    Marina Del Rey, California
    Posts
    2,916

    Default

    Also maybe you could track what mi_sample_light returns to see if that is it?
    Barton Gawboy
    Training and Special Projects, NVIDIA ARC
    LAmrUG Forum Originator

  9. #9
    Join Date
    Dec 2004
    Location
    Moscow, Russia
    Posts
    347

    Default

    I have tried null state->pri
    [img]http&#58;//www&#46;puppet&#46;cgtalk&#46;ru/change_normal&#46;jpg[/img]
    My code looks like:
    Code:
    	miVector *bump_normal;
    	if&#40;sp->use_normal&#41;													//Change normal&#40;bump&#41;
    	&#123;
    		bump_normal = mi_eval_vector&#40;&paras->input_normal&#41;;
    		mi_vector_normalize&#40;bump_normal&#41;;
    		state->dot_nd = mi_vector_dot&#40;bump_normal, &state->dir&#41;;
    		state->normal = *bump_normal;
    	&#125;
    	void* pri = state->pri;
    	state->pri = NULL;
    	if &#40;m == 1&#41;
    		mi_inclusive_lightlist&#40;&n_l, &light, state&#41;;
    	else if &#40;m == 2&#41;
    		mi_exclusive_lightlist&#40;&n_l, &light, state&#41;;
    
    	for &#40;n=0; n < n_l; n++, light++&#41;
    	&#123;
    		sum&#46;r = sum&#46;g = sum&#46;b = 0;
    		samples = 0;
    
    		while &#40;mi_sample_light&#40;&light_col&#46;l_color_shd, &dir, &dot_nl, state, *light, &samples&#41;&#41;
    		&#123;
    			&#46;&#46;&#46;
    		&#125;
    		if &#40;samples&#41;
    		&#123;
    			&#46;&#46;&#46;
    		&#125;
    		state->pri = pri;
    	&#125;
    As I understand nulling state->pri disable mr optimization that don't call light if face away from light.
    But result is strange (see right image)

    Now I use another code that I talking before
    Code:
    	miVector orig_normal;
    	miVector *bump_normal;
    	if&#40;sp->use_normal&#41;													//Change normal&#40;bump&#41;
    	&#123;
    		orig_normal = state->normal;
    		bump_normal = mi_eval_vector&#40;&paras->input_normal&#41;;
    		mi_vector_normalize&#40;bump_normal&#41;;
    		state->dot_nd = mi_vector_dot&#40;bump_normal, &state->dir&#41;;
    		state->normal = *bump_normal;
    	&#125;
    	state->normal = orig_normal;
    	if &#40;m == 1&#41;
    		mi_inclusive_lightlist&#40;&n_l, &light, state&#41;;
    	else if &#40;m == 2&#41;
    		mi_exclusive_lightlist&#40;&n_l, &light, state&#41;;
    
    	for &#40;n=0; n < n_l; n++, light++&#41;
    	&#123;
    		sum&#46;r = sum&#46;g = sum&#46;b = 0;
    		samples = 0;
    
    		while &#40;mi_sample_light&#40;&light_col&#46;l_color_shd, &dir, &dot_nl, state, *light, &samples&#41;&#41;
    		&#123;
    			state->normal = *bump_normal;
    			&#46;&#46;&#46;
    			state->normal = orig_normal;
    		&#125;
    		if &#40;samples&#41;
    		&#123;
    			&#46;&#46;&#46;
    		&#125;
    	&#125;
    	state->normal = *bump_normal;
    And it works fine except one case, if occlusion shader used as light shader.

    As I understand mi_sample_light always return 0 before switch to next light source. I don't know how to track it and what should I get from it.

    Ofcourse it return 0 on back side of sphere (if I don't null state->pri).

    Anyway thanks for your help.
    Pavel Ledin

  10. #10
    Join Date
    Dec 2004
    Location
    Marina Del Rey, California
    Posts
    2,916

    Default

    How is the bump normal created or calculated?

    It appears as if normal interpolation is not happening?
    Otherwise that image on the right might be what is expected if there are random normals being passed in. Are the texture coordinates being interpolated?

    Are you restoring normal and dot_nd as well as pri?
    Barton Gawboy
    Training and Special Projects, NVIDIA ARC
    LAmrUG Forum Originator

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •