Jump to content

How to render Ambient occlusion on top of a normal map displaced objec


Recommended Posts

I have a cylinder with a normal map on top of it... nw I would like to render out the ambient occlusion on top of this... whats the way can anybody tell me..

here is what i have tried...

using the shaders...

1. Normal map displace..

>>>>>>>>>>>>>>>>>>>>

displacement normalmap_displace(

float Km = 1.0;

float Km_pos = 0.0;

float Km_neg = 0.0;

string displace_map = "";

string normal_map = "";

string normal_map_space = "current")

{

float magnitude = 0;

float level = 0;

float pos_level = 0;

float neg_level = 0;

color color_level = color(0,0,0);

color Ncolor = color(0,0,0);

point Nvector = point(0,0,0);

point Nref = point(0,0,0);

point Nside = point(0,0,0);

point Ntransformed = point(0,0,0);

float testSide = 0;

point dPds, dPdt;

dPds = Deriv(P,s);

dPdt = Deriv(P,t);

if( displace_map != "")

{

color_level = color

texture(

displace_map,

s,

(1-t),

"swidth", 0.0001,

"twidth", 0.0001,

"samples", 1);

if ((Km_pos == 0) && (Km_neg == 0))

{

level = comp(color_level,0);

magnitude = ((level * 2) - 1) * Km;

}

else

{

pos_level = comp(color_level,0);

neg_level = comp(color_level,1);

magnitude = (( pos_level * Km_pos ) - ( neg_level * Km_neg )) * Km;

}

}

else

{

magnitude = 0.0;

}

P += normalize(N) * magnitude;

if( normal_map != "")

{

Ncolor = color

texture(

normal_map,

s,

(1-t));

Nvector = (vector(Ncolor)*2) - vector(1.0, 1.0, 1.0);

if ((normal_map_space == "point") || (normal_map_space == "pointU") || (normal_map_space == "pointV")

|| (normal_map_space == "facet") || (normal_map_space == "facetU") || (normal_map_space == "facetV"))

{

if ((normal_map_space == "point") || (normal_map_space == "pointU") || (normal_map_space == "pointV"))

Nref = N;

else

Nref = Ng;

Nside = dPds ^ dPdt;

testSide = Nside.Nref;

if ((normal_map_space == "pointU") || (normal_map_space == "facetU"))

{

dPdt = dPds ^ Nref;

}

if ((normal_map_space == "pointV") || (normal_map_space == "facetV"))

{

dPds = Nref ^ dPdt;

}

dPds = normalize (dPds);

dPdt = normalize (dPdt);

Nref = normalize (Nref);

Ntransformed = vector(comp(Nvector,0) * comp(dPds,0) + comp(Nvector,1) * comp(dPdt,0) + comp(Nvector,2) * comp(Nref,0),

comp(Nvector,0) * comp(dPds,1) + comp(Nvector,1) * comp(dPdt,1) + comp(Nvector,2) * comp(Nref,1),

comp(Nvector,0) * comp(dPds,2) + comp(Nvector,1) * comp(dPdt,2) + comp(Nvector,2) * comp(Nref,2));

}

else

Ntransformed = ntransform (normal_map_space, "current", Nvector);

N = normalize(Ntransformed);

}

else

{

N = calculatenormal( P);

}

}

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

this is the occlusion shader that ive used..

surface occlude2(float samples = 32,

maxdist = 100000)

{

normal n = normalize(N),

nf = faceforward(n, I);

float occ = occlusion(P, nf, samples, "maxdist", maxdist);

Oi = Os;

Ci = (1 - occ) * Cs * Oi;

}

>>>>>>>>>>>>>>>>>>>>>>>>>>

follows the rib>>

#MayaMan 1.0.14

##RenderMan RIB

version 3.03

Option "searchpath" "shader" ["&:./shaders"]

FrameBegin 1

Format 300 400 1

ShadingInterpolation "smooth"

Attribute "render" "integer tracedisplacements" [1]

Display "flexArm.exr" "file" "rgba" "quantize" [0 0 0 0] "uniform string compression" ["none"]

Display "+normal.exr" "file" "N" "quantize" [0 0 0 0]

#"uniform string compression" ["none"]

Projection "perspective" "fov" [54.4322]

ScreenWindow -1 1 -1.33333 1.33333

Clipping 0.1 1000

Scale -1 1 1

Rotate 0 0 0 1

Rotate -11.7053 1 0 0

Rotate 55.4 0 1 0

Translate -35.5166 -13.1841 24.6357

WorldBegin

Attribute "visibility" "integer camera" [1]

Attribute "visibility" "integer reflection" [1]

Attribute "visibility" "integer shadow" [1]

Attribute "render" "string casts_shadows" ["Os"]

LightSource "distantlight" 1 "intensity" [1.8]"lightcolor" [1 0.965922 0.871]"from" [0 0 0]"to" [-0.633036 -0.497084 -0.593442]

LightSource "distantlight" 2 "intensity" [1.2]"lightcolor" [0.765 0.832523 1]"from" [0 0 0]"to" [-0.503996 -0.497084 0.706326]

Illuminate 1 1

Illuminate 2 1

# BEGIN MODEL: nurbsCylinder-nurbsCylinderShape

AttributeBegin

ConcatTransform [1 0 0 0 0 2.22045e-016 1 0 0 -2 4.44089e-016 0 0 0 0 1]

Attribute "visibility" "integer shadow" [0]

Attribute "visibility" "integer reflection" [0]

AttributeBegin

Attribute "identifier" "name" ["nurbsCylinder-nurbsCylinderShape"]

Surface "occlude2"

#Color [0.5 0.5 0.5]

Attribute "displacementbound" "sphere" [1]

"coordinatesystem" ["object"]

Attribute "render" "integer tracedisplacements" [1]

#Declare "displace_map" "string"

Declare "normal_map" "string"

Declare "normal_map_space" "string"

Declare "Km_pos" "float"

Declare "Km_neg" "float"

Displacement "normalmap_displace"

"Km_pos" [6.5]

"Km_neg" [6.5]

#"displace_map" ["mrArmDisplace.tif"]

"normal_map" ["flexingArmPointNormals.tif"]

"normal_map_space" ["pointV"]

Sides 2

ReverseOrientation

TextureCoordinates 0 0 0 1 1 0 1 1

Declare "__no_shadows" "constant float"

NuPatch 19 4 [-0.125 -0.125 -0.0625 0 0.0625 0.125 0.1875 0.25 0.3125 0.375 0.4375

0.5 0.5625 0.625 0.6875 0.75 0.8125 0.875 0.9375 1 1.0625 1.125 1.125] 0 1 19 4 [0 0 0 0 0.0625 0.125 0.1875 0.25 0.3125 0.375 0.4375

0.5 0.5625 0.625 0.6875 0.75 0.8125 0.875 0.9375 1 1 1 1] 0 1

"__no_shadows" [1]

"Pw" [25.5942 3.01857 10.7311 1

26.0487 3.96007 10.2234 1 26.0229 5.15069 9.80322 1 25.5206 6.40916 9.53443 1

24.6182 7.54388 9.458 1 23.4532 8.38208 9.58556 1 22.203 8.79616 9.89771 1

21.0578 8.72308 10.3469 1 20.192 8.17399 10.8648 1 19.7375 7.23248 11.3726 1

19.7634 6.0419 11.7928 1 20.2658 4.78349 12.0616 1 21.1681 3.64883 12.138 1

22.3331 2.81063 12.0104 1 23.5833 2.39651 11.6982 1 24.7284 2.46952 11.249 1

25.5942 3.01857 10.7311 1 26.0487 3.96007 10.2234 1 26.0229 5.15069 9.80322 1

24.9107 2.34914 10.269 1 25.3653 3.29064 9.76133 1 25.3395 4.4813 9.34116 1

24.8372 5.73985 9.0724 1 23.9349 6.87467 8.99597 1 22.77 7.71298 9.12351 1

21.5197 8.12716 9.43562 1 20.3746 8.05416 9.8848 1 19.5088 7.50512 10.4027 1

19.0543 6.56362 10.9104 1 19.0801 5.37301 11.3306 1 19.5824 4.11453 11.5994 1

20.4847 2.97977 11.6758 1 21.6496 2.14146 11.5482 1 22.8998 1.72723 11.236 1

24.0449 1.80015 10.7868 1 24.9107 2.34914 10.269 1 25.3653 3.29064 9.76133 1

25.3395 4.4813 9.34116 1 23.5426 1.00772 9.34501 1 23.9973 1.94918 8.83758 1

23.9718 3.14001 8.41759 1 23.4697 4.39889 8.14892 1 22.5677 5.53414 8.07249 1

21.4029 6.37292 8.19994 1 20.1528 6.78753 8.5119 1 19.0077 6.71488 8.96091 1

18.1419 6.16603 9.47863 1 17.6873 5.22458 9.98621 1 17.713 4.03384 10.4063 1

18.2151 2.77509 10.675 1 19.1172 1.63991 10.7514 1 20.2818 0.80112 10.6238 1

21.5318 0.386415 10.3117 1 22.6768 0.458954 9.86264 1 23.5426 1.00772 9.34501 1

23.9973 1.94918 8.83758 1 23.9718 3.14001 8.41759 1 21.4891 -1.00758 7.95939 1

21.9442 -0.0661766 7.45252 1 21.9192 1.12506 7.03298 1 21.4177 2.38474 6.76458 1

20.5162 3.52102 6.68814 1 19.3518 4.36087 6.81536 1 18.1019 4.77644 7.12696 1

16.9569 4.70451 7.57557 1 16.0911 4.15609 8.09291 1 15.6363 3.21472 8.60017 1

15.6617 2.02371 9.02006 1 16.1633 0.764326 9.28857 1 17.0648 -0.371762 9.36482 1

18.2289 -1.21164 9.23721 1 19.4784 -1.62744 8.92526 1 20.6232 -1.55581 8.47654 1

21.4891 -1.00758 7.95939 1 21.9442 -0.0661766 7.45252 1 21.9192 1.12506 7.03298 1

19.4308 -3.03357 6.57486 1 19.8869 -2.09215 6.06932 1 19.8632 -0.900046 5.65097 1

19.3631 0.361149 5.3833 1 18.4626 1.49931 5.30699 1 17.299 2.34109 5.43379 1

16.0494 2.75837 5.74461 1 14.9043 2.68772 6.1923 1 14.0382 2.14003 6.70874 1

13.5829 1.19873 7.21522 1 13.6075 0.00713283 7.63443 1 14.1081 -1.25347 7.9024 1

15.0084 -2.3913 7.97825 1 16.1714 -3.23321 7.85052 1 17.42 -3.65099 7.53883 1

18.5646 -3.58094 7.09085 1 19.4308 -3.03357 6.57486 1 19.8869 -2.09215 6.06932 1

19.8632 -0.900046 5.65097 1 17.357 -5.09361 5.19312 1 17.8166 -4.15167 4.69202 1

17.7971 -2.95711 4.27777 1 17.301 -1.69206 4.01284 1 16.4035 -0.549371 3.93736 1

15.2414 0.296934 4.06315 1 13.9922 0.718133 4.37166 1 12.8465 0.650348 4.81647 1

11.9791 0.104142 5.33 1 11.5217 -0.837223 5.83378 1 11.5437 -2.03053 6.25058 1

12.0411 -3.29438 6.51646 1 12.938 -4.43663 6.59071 1 14.0978 -5.28351 6.46224 1

15.3445 -5.70596 6.15116 1 16.4888 -5.63937 5.70542 1 17.357 -5.09361 5.19312 1

17.8166 -4.15167 4.69202 1 17.7971 -2.95711 4.27777 1 15.3376 -7.02877 3.79734 1

15.7988 -6.07621 3.29098 1 15.7775 -4.87635 2.87044 1 15.2776 -3.61123 2.60024 1

14.3758 -2.47493 2.52336 1 13.2106 -1.63793 2.65149 1 11.9347 -1.35923 3.02472 1

10.7779 -1.45124 3.4715 1 9.90204 -1.9964 3.97271 1 9.42357 -2.96804 4.46901 1

9.42784 -4.17591 4.87188 1 9.93965 -5.39353 5.12463 1 10.8269 -6.54422 5.19175 1

11.9799 -7.39917 5.05966 1 13.1816 -7.90422 4.74553 1 14.3761 -7.75725 4.31146 1

15.3376 -7.02877 3.79734 1 15.7988 -6.07621 3.29098 1 15.7775 -4.87635 2.87044 1

13.0459 -9.47273 2.38959 1 13.6276 -8.39437 1.95917 1 13.688 -7.08276 1.57133 1

13.2274 -5.71515 1.28212 1 12.3365 -4.55494 1.20329 1 11.1679 -3.66889 1.29185 1

9.91588 -3.25503 1.60172 1 8.76605 -3.33649 2.05054 1 7.90146 -3.84562 2.54162 1

7.3102 -5.13784 3.11111 1 7.2259 -6.43011 3.45242 1 7.60025 -7.80256 3.6266 1

8.46293 -8.93674 3.64821 1 9.62538 -9.76044 3.50684 1 10.8881 -10.175 3.2122 1

12.0738 -10.0995 2.81685 1 13.0459 -9.47273 2.38959 1 13.6276 -8.39437 1.95917 1

13.688 -7.08276 1.57133 1 11.1041 -10.8573 0.708789 1 11.8091 -9.80812 0.468305 1

12.0595 -8.50123 0.344601 1 11.7922 -7.15099 0.333135 1 11.0638 -5.9442 0.44422 1

9.96271 -5.07954 0.640705 1 8.62184 -4.7107 0.860646 1 7.29223 -4.86625 1.11537 1

6.19718 -5.51016 1.38594 1 5.4921 -6.55055 1.62006 1 5.27267 -7.83612 1.77111 1

5.57499 -9.17536 1.82279 1 6.37324 -10.3626 1.7937 1 7.50399 -11.2174 1.63094 1

8.78325 -11.614 1.34614 1 10.0317 -11.4866 1.00002 1 11.1041 -10.8573 0.708789 1

11.8091 -9.80812 0.468305 1 12.0595 -8.50123 0.344601 1 9.90288 -10.3502 -1.30084 1

10.7556 -9.26035 -1.3675 1 11.1319 -7.91105 -1.3485 1 10.9786 -6.50602 -1.24239 1

10.3211 -5.25801 -1.06339 1 9.25809 -4.35708 -0.840413 1 7.94753 -3.94177 -0.611914 1

6.58436 -4.07723 -0.41755 1 5.37385 -4.74411 -0.289132 1 4.50182 -5.84066 -0.244254 1

4.10549 -7.19838 -0.284728 1 4.24981 -8.60865 -0.39943 1 4.91468 -9.85568 -0.569098 1

5.99698 -10.7499 -0.770286 1 7.32756 -11.1568 -0.977304 1 8.6997 -11.0161 -1.16309 1

9.90288 -10.3502 -1.30084 1 10.7556 -9.26035 -1.3675 1 11.1319 -7.91105 -1.3485 1

9.03929 -9.18683 -3.3138 1 9.9518 -8.07228 -3.31591 1 10.3863 -6.70236 -3.23165 1

10.278 -5.28521 -3.07242 1 9.64376 -4.03656 -2.86189 1 8.57944 -3.14694 -2.63271 1

7.24579 -2.75239 -2.42115 1 5.84467 -2.91338 -2.26073 1 4.58908 -3.60534 -2.17637 1

3.67078 -4.72245 -2.18038 1 3.23077 -6.09412 -2.27089 1 3.33714 -7.51117 -2.43287 1

3.97412 -8.75793 -2.64102 1 5.04424 -9.64498 -2.86407 1 6.38337 -10.0378 -3.06935 1

7.78642 -9.87689 -3.22704 1 9.03929 -9.18683 -3.3138 1 9.9518 -8.07228 -3.31591 1

10.3863 -6.70236 -3.23165 1 8.14162 -8.21633 -5.23633 1 9.06543 -7.09596 -5.22708 1

9.5099 -5.72373 -5.13084 1 9.40774 -4.30845 -4.96182 1 8.7746 -3.06568 -4.74557 1

7.70661 -2.18484 -4.51518 1 6.36595 -1.80026 -4.30616 1 4.9564 -1.97055 -4.15069 1

3.6925 -2.66969 -4.07261 1 2.76691 -3.791 -4.08366 1 2.32087 -5.16358 -4.18179 1

2.42261 -6.57841 -4.3517 1 3.05673 -7.8202 -4.56732 1 4.12651 -8.7001 -4.79591 1

5.46874 -9.08433 -5.00304 1 6.8787 -8.91449 -5.15761 1 8.14162 -8.21633 -5.23633 1

9.06543 -7.09596 -5.22708 1 9.5099 -5.72373 -5.13084 1 7.22294 -7.31731 -7.13688 1

8.14957 -6.19523 -7.12496 1 8.5963 -4.82275 -7.02579 1 8.49527 -3.40877 -6.85431 1

7.86186 -2.16864 -6.63654 1 6.7924 -1.29126 -6.4057 1 5.44955 -0.910314 -6.1971 1

4.03763 -1.0838 -6.04263 1 2.77158 -1.78524 -5.96587 1 1.84424 -2.90772 -5.97846 1

1.39694 -4.28028 -6.07835 1 1.49788 -5.69395 -6.2502 1 2.13171 -6.93357 -6.46775 1

3.20186 -7.81053 -6.69792 1 4.54528 -8.19141 -6.9058 1 5.95731 -8.01823 -7.05991 1

7.22294 -7.31731 -7.13688 1 8.14957 -6.19523 -7.12496 1 8.5963 -4.82275 -7.02579 1

6.29693 -6.44083 -9.03144 1 7.2245 -5.31813 -9.01868 1 7.67193 -3.94565 -8.91856 1

7.57115 -2.53234 -8.74625 1 6.93751 -1.29341 -8.52794 1 5.86742 -0.417538 -8.2969 1

4.52372 -0.038115 -8.08837 1 3.11093 -0.212908 -7.93417 1 1.84413 -0.915258 -7.8578 1

0.916226 -2.03818 -7.87086 1 0.468554 -3.41066 -7.97131 1 0.56931 -4.82377 -8.14379 1

1.20316 -6.06241 -8.36201 1 2.27357 -6.93808 -8.59275 1 3.61752 -7.31749 -8.80095 1

5.03034 -7.1429 -8.95498 1 6.29693 -6.44083 -9.03144 1 7.2245 -5.31813 -9.01868 1

7.67193 -3.94565 -8.91856 1 5.36807 -5.57274 -10.924 1 6.29603 -4.44975 -10.9109 1

6.74371 -3.07731 -10.8104 1 6.643 -1.66436 -10.6377 1 6.00921 -0.426033 -10.4192 1

4.93882 0.449102 -10.188 1 3.59473 0.827787 -9.97951 1 2.18156 0.652372 -9.82539 1

0.914434 -0.0504052 -9.74915 1 -0.0136969 -1.17352 -9.76239 1 -0.461503 -2.54595 -9.86306 1

-0.360788 -3.95877 -10.0358 1 0.273116 -5.19692 -10.2543 1 1.34368 -6.07193 -10.4853 1

2.68789 -6.45062 -10.6936 1 4.10107 -6.27534 -10.8477 1 5.36807 -5.57274 -10.924 1

6.29603 -4.44975 -10.9109 1 6.74371 -3.07731 -10.8104 1 4.43795 -4.70827 -12.8156 1

5.36609 -3.58513 -12.8024 1 5.81388 -2.21272 -12.7017 1 5.71318 -0.799973 -12.5289 1

5.07931 0.438019 -12.3102 1 4.00875 1.31275 -12.079 1 2.66447 1.69104 -11.8705 1

1.2511 1.51529 -11.7164 1 -0.0161843 0.812293 -11.6402 1 -0.944423 -0.310915 -11.6536 1

-1.39229 -1.68331 -11.7543 1 -1.29158 -3.09597 -11.9272 1 -0.657631 -4.33385 -12.1458 1

0.413028 -5.20851 -12.377 1 1.75738 -5.58681 -12.5854 1 3.17075 -5.41115 -12.7394 1

4.43795 -4.70827 -12.8156 1 5.36609 -3.58513 -12.8024 1 5.81388 -2.21272 -12.7017 1

3.50721 -3.84554 -14.7069 1 4.43544 -2.72233 -14.6936 1 4.88329 -1.34994 -14.5928 1

4.78259 0.0626853 -14.4199 1 4.14866 1.30048 -14.2012 1 3.078 2.17497 -13.97 1

1.73361 2.55303 -13.7614 1 0.320127 2.37709 -13.6074 1 -0.947238 1.67396 -13.5312 1

-1.87553 0.550699 -13.5446 1 -2.32342 -0.821678 -13.6454 1 -2.22271 -2.23424 -13.8183 1

-1.58873 -3.47195 -14.037 1 -0.518016 -4.3464 -14.2682 1 0.826422 -4.72446 -14.4767 1

2.23989 -4.54859 -14.6307 1 3.50721 -3.84554 -14.7069 1 4.43544 -2.72233 -14.6936 1

4.88329 -1.34994 -14.5928 1 2.88652 -3.27094 -15.9676 1 3.81479 -2.14769 -15.9543 1

4.26266 -0.775316 -15.8535 1 4.16195 0.637255 -15.6806 1 3.528 1.87496 -15.4618 1

2.4573 2.74935 -15.2306 1 1.11285 3.1273 -15.022 1 -0.300673 2.95128 -14.8679 1

-1.56807 2.24809 -14.7918 1 -2.49639 1.1248 -14.8052 1 -2.94429 -0.247562 -14.906 1

-2.84358 -1.66008 -15.079 1 -2.20958 -2.89772 -15.2977 1 -1.13884 -3.77207 -15.5289 1

0.205638 -4.15003 -15.7374 1 1.61916 -3.97406 -15.8915 1 2.88652 -3.27094 -15.9676 1

3.81479 -2.14769 -15.9543 1 4.26266 -0.775316 -15.8535 1 2.57613 -2.98375 -16.598 1

3.50442 -1.86049 -16.5846 1 3.9523 -0.488116 -16.4838 1 3.85159 0.924432 -16.3109 1

3.21762 2.1621 -16.0921 1 2.14691 3.03645 -15.8609 1 0.80244 3.41436 -15.6523 1

-0.611103 3.2383 -15.4982 1 -1.87852 2.53509 -15.4221 1 -2.80685 1.41179 -15.4355 1

-3.25475 0.0394334 -15.5363 1 -3.15403 -1.37307 -15.7093 1 -2.52003 -2.61067 -15.9281 1

-1.44928 -3.48499 -16.1593 1 -0.104783 -3.86291 -16.3678 1 1.30875 -3.6869 -16.5218 1

2.57613 -2.98375 -16.598 1 3.50442 -1.86049 -16.5846 1 3.9523 -0.488116 -16.4838 1]

AttributeEnd

AttributeEnd

# END MODEL: nurbsCylinder-nurbsCylinderShape

WorldEnd

FrameEnd

Im getting Occlusion where im getting ambient occlusion where normal map is not being picked up by 3delight for maya..

does anybody know whats happening with this?

Link to comment
Share on other sites

Have you tried turning on "Trace" Displacements?

In RIB I think it's Attribute "trace" "displacements" 1

edit: I didn't see you have "Attribute "render" "integer tracedisplacements" [1]" I'm not familiar with this syntax,

Edited by Alanw
Link to comment
Share on other sites

There's a thread over at the Aqsis forum discussing similar problems with both the normalmap_displace.sl shader and the mrArmDisplace map that you're using (both of which came from a tutorial by Olivier Renouard, btw, just to give credit where it's due).

I'd suggest you check with those guys since they're all trying to find out what's going on, and at least one of them is a developer... they'd be much more in touch with the details than most of us here.

Link to comment
Share on other sites

  • 2 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...