Image based lighting texture

calendar_today

04.05.2022

label

VEX, Texturing

mouse

Houdini 18.0

1 Introduction

This example samples a HDR image from a sky sphere based on the surface orientation of a mesh.

2 Code

// INPUT
vector pos_tex = set(X, Y, 0.0);
vector pos_mesh = uvsample(geo_mesh, 'P', 'uv', pos_tex);
vector nml_mesh = uvsample(geo_mesh, 'N', 'uv', pos_tex);

float a = radians(angle);

// IMAGE BASED DIRECT LIGHTING

vector clr_sum = 0.0;
for(int i = 0; i < samples; i++){
    vector2 u = rand(pos_tex * i);
    vector dir = sample_direction_cone(nml_mesh, a, u);
    vector pos_ray = pos_mesh + nml_mesh * 1e-3;
    vector dir_ray = dir * range;
    vector pos_hit;
    vector uvw_hit;
    int prim_hit = intersect(geo_sky, pos_ray, dir_ray, pos_hit, uvw_hit);
    vector clr_hit = primuv(geo_sky, 'Cd', prim_hit, uvw_hit);
    clr_sum += clr_hit;   
}
vector clr = clr_sum / float(samples);

// OUTPUT
vector color = vector(clr);
assign(R, G, B, color);

3 Resulting map

download

Downloads