We are going from exr files to lat-long env tex files (via txmake) and exr to 
lat-long env exr files (via maketx) respectively. The only difference being in 
the way we encode the data in the original exr files. I am attaching the python 
script as an example.


Ryan




On Thursday, November 14, 2013 9:13 PM, Larry Gritz <[email protected]> wrote:
 
Are you aware of the differences in the spatial representation of OpenEXR 
versus the usual convention that PRMan and OIIO use with TIFF textures?

In other words, are you quite sure that this is a OIIO vs PRMan difference 
rather than a TIFF versus OpenEXR difference in the layout of the data?




On Nov 13, 2013, at 11:00 PM, ryan heniser <[email protected]> wrote:

Hi Larry,
>
>Thanks for the quick response. We have spherical harmonic coefficients stored 
>in Pixar's env maps. I am trying to swap us to use OpenExr's env maps (via 
>OpenImageIO in a RSL Plugin ). This will allow us to control the caching of 
>this LUT separate from PRMan's texture cache. When I read in the two maps, the 
>values differ by as much as 0.1. I am pretty sure I have accounted for the 
>difference in env map encoding between the two. I wrote a little python script 
>to create the unit sphere for the two encodings. Rendering with the two unit 
>sphere maps also gives me at least 0.03 in error. Increasing the resolution 
>decreases it to some extent. I am pretty sure I am point sampling the tex file 
>too. But, I am checking with the PRMan folks to make sure. 
>
>Would you expect so much
 error between the two? Any ideas on where I may be going wrong?
>
>Thanks,
>Ryan
>
>
>
>
>
>
>
>
>
>
>On Thursday, November 14, 2013 6:58 PM, Larry Gritz <[email protected]> 
>wrote:
> 
>Yeah, that looks like it should do it.  Between the zero derivatives and the 
>width==0, and the InterpClosest (to prevent true interpolation), you ought to 
>be point sampling.
>
>
>Is this not working as expected?  What happens?
>
>
>
>
>On Nov 13, 2013, at 9:53 PM, ryan heniser <[email protected]> wrote:
>
>How do I point sample a env map with an environment call? I thought it would 
>be something like
>>
>>// Initialize texture options for point sampling
>>gTexOpts.nchannels = 3;
>>gTexOpts.firstchannel = 0;
>>gTexOpts.swrap = TextureOpt::WrapPeriodic;
>>gTexOpts.twrap = TextureOpt::WrapClamp;
>>gTexOpts.samples = 1;
>>gTexOpts.mipmode = TextureOpt::MipModeNoMIP;
>>gTexOpts.interpmode = TextureOpt::InterpClosest; // Force closest texel
>>gTexOpts.conservative_filter = false;
>>gTexOpts.sblur = 0;
>>gTexOpts.tblur = 0;
>>gTexOpts.swidth = 0;
>>gTexOpts.twidth =
 0;
>>
>>
>>const Imath::V3f zero(0,0,0);
>>
>>bool ok = gTexSys->environment(filename, gTexOpts, r, zero, zero, test);
>>
>>
>>Ryan
>>_______________________________________________
>>
>>
>
>--
>Larry Gritz
>[email protected]
>
>
> 
>
>
>

--
Larry Gritz
[email protected]
#!/usr/bin/python

import OpenEXR
import array
import math
import subprocess
import os

# The size of the data window should be 2*N by N
# pixels (width by height), where N can be any
# integer greater than 0.
width = 1024
height = 512

two_pi = 6.283185307179586
pi = 3.141592653589793
pi_div_2 = 1.57079632679489655800

# --------------------------------------------------
# OpenExr
# --------------------------------------------------
# From ImfEnvmap.cpp:
# x is longitude (azimuth or phi)
# y is latitude (inclination/elevation or theta)
#
#    pi    <= longitude <= -pi
#    -pi/2 <= latitude  <= pi/2
#
# x = sin (longitude) * cos (latitude)
# y = sin (latitude)
# z = cos (longitude) * cos (latitude)
#
long = pi
long_step = -(two_pi / width)

lat = pi_div_2
lat_step = -(pi / height)

r_data = array.array('f')
g_data = array.array('f')
b_data = array.array('f')
for h in range(height):
    for w in range(width):
        cos_lat = math.cos(lat)
        i = (width*h) + w

        r_data.insert(i, math.sin(long) * cos_lat)
        g_data.insert(i, math.sin(lat))
        b_data.insert(i, math.cos(long) * cos_lat)

        long += long_step

    lat += lat_step


exr = OpenEXR.OutputFile("unit_sphere.exr", OpenEXR.Header(width,height))
exr.writePixels({'R': r_data.tostring(),
                 'G': g_data.tostring(),
                 'B': b_data.tostring()})

subprocess.call("maketx -envlatl unit_sphere.exr -o unit_sphere_lat_long_env_openexr.exr", shell=True)

os.remove("unit_sphere.exr")

# --------------------------------------------------
# Pixar tex mapping
# --------------------------------------------------
# A pixel's (x,y):
# x is longitude (azimuth or phi)
# y is latitude (inclination/elevation or theta)
#
# and the y coordinate corresponds to its latitude.
#    -pi     <= longitude <=  pi
#    -pi/2 <= latitude  <= pi/2
#
#    x = cos(longitude) * cos(latitude)
#    y = sin(longitude) * cos(latitude)
#    z = sin(latitude)
#

long = -pi
long_step = two_pi / width

lat = pi_div_2
lat_step = -(pi / height)

r_data = array.array('f')
g_data = array.array('f')
b_data = array.array('f')
for h in range(height):
    for w in range(width):
        cos_lat = math.cos(lat)
        i = (width*h) + w

        r_data.insert(i, math.cos(long) * cos_lat)
        g_data.insert(i, math.sin(long) * cos_lat)
        b_data.insert(i, math.sin(lat))

        long += long_step

    lat += lat_step


tex = OpenEXR.OutputFile("unit_sphere_lat_long_env_pixar.exr", OpenEXR.Header(width,height))
tex.writePixels({'R': r_data.tostring(),
                 'G': g_data.tostring(),
                 'B': b_data.tostring()})

subprocess.call("txmake -envlatl unit_sphere_lat_long_env_pixar.exr unit_sphere_lat_long_env_pixar.tex", shell=True)

os.remove("unit_sphere_lat_long_env_pixar.exr")


_______________________________________________
Oiio-dev mailing list
[email protected]
http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org

Reply via email to