Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Look up keyword
Like this
5Activity
0 of .
Results for:
No results containing your search query
P. 1
Normalmaps mipmaps Mathematica playground

Normalmaps mipmaps Mathematica playground

Ratings: (0)|Views: 818|Likes:

More info:

Categories:Types, Research
Published by: c0de517e.blogspot.com on Feb 03, 2012
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

08/15/2013

pdf

text

original

 
In[1]:=
Load a normalmap, convert to floats and remap it to the
1,1 range, resize to make it more manageable...
normalMap
ImageApply
 Normalize
0.5
&,Image
ImageResize
Import
"C:\\Users\\angelo.pesce\\Desktop\\4.jpg"
, 128
, "Real"
Out[1]=
 
In[2]:=
We'll need a mean to operate on sub
 blocks of an image,let's write a small helper function that does these operations in parallell
 blockImageMap
img_, fn_, size_
:
Parallelize
 Map
fn, ImagePartition
img, size
,
2

Let's compute the average normal for the blocks,we could have done it wiht anotherImageResize but it's also a test of blockImageMap...
 blockSize
16;averagedNormals
blockImageMap
normalMap, Normalize
 Apply
Plus, Flatten
ImageData
, 1

&, blockSize
;Image
averagedNormals
averagedNormals
Flatten
averagedNormals, 1
;
Out[5]=
2
 
normalmapFit.nb
 
In[7]:=
We're not going to use a four
dimensional Phong BRDF,we'll cheat reduce Phong to a simple lobe around the normal,like a "powered" diffuse
Let me motivate this a bit: let's say that we have a cone
Phong which takes a cone of normals and a light direction. The light aroundthe normal reflection direction around the cone will be a cone whosesize is equal to the normal cone no matter where the light direction is,thus this cone
Phong will have a constant lobe which justrotates as the light direction changes,so we can ignore the light direction and just construct a lobearound the normal
s
instead, which we do here.
cosFn
n_, exp_, a_, b_
:
Max
n.
Cos
 b
Sin
a
, Sin
 b
Sin
a
, Cos
a

, 0.
^exp
Let's see how that looks like when we startaveraging different lobes around a bunch of normals
aggregateCosFn
Compile

nlist, _Real, 2
, exp, a, b
, Mean
 Map
n
 Max
n.
Cos
 b
Sin
a
, Sin
 b
Sin
a
, Cos
a

, 0.
^exp, nlist

;someTestNormals

0., 0., 1.
,
0., 1., 0.
,
0., 0.7071067811865475, 0.7071067811865475

;someTestData
Flatten
Table

a, b, aggregateCosFn
someTestNormals, 5., a, b

,
a, 0., Pi, 0.01
,
 b,
Pi
2, Pi
2, 0.01

, 1
;

AbsoluteTimingtestPlot
SphericalPlot3D
aggregateCosFn
someTestNormals, 5., a, b
,
a,
Pi
2., Pi
2.
,
 b, 0., Pi
, PlotRange
Full
Out[10]=
0.6400640, Null
CompiledFunction::cfsa:Argument a atposition 3 shouldbea machine
sizerealnumber.
normalmapFit.nb
3

Activity (5)

You've already reviewed this. Edit your review.
1 hundred reads
1 thousand reads
Mluettecke liked this
gamecom liked this
sbelahbib liked this

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->