Skip to content

Commit

Permalink
完成预计算部分
Browse files Browse the repository at this point in the history
  • Loading branch information
MuseumMage committed Jun 21, 2024
1 parent a63c813 commit 55be978
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
10 changes: 5 additions & 5 deletions Assignment4/lut-gen/Eavg_MC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ samplePoints squareToCosineHemisphere(int sample_count){
double sampley = (p + rng(gen)) / sample_side;

double theta = 0.5f * acos(1 - 2*samplex);
double phi = 2 * M_PI * sampley;
double phi = 2 * PI * sampley;
Vec3f wi = Vec3f(sin(theta) * cos(phi), sin(theta) * sin(phi), cos(theta));
float pdf = wi.z / PI;

Expand Down Expand Up @@ -79,10 +79,10 @@ Vec3f IntegrateEmu(Vec3f V, float roughness, float NdotV, Vec3f Ei) {
float NoV = std::max(dot(N, V), 0.0f);

// TODO: To calculate Eavg here

}

return Eavg / sample_count;
// return Eavg / sample_count;
return Ei * NdotV * 2.0f;
}


Expand All @@ -98,9 +98,9 @@ int main() {
std::cout << resolution << " " << resolution << " " << channel << std::endl;
// | -----> mu(j)
// |
// | rough(i)
// | rough£¨i£©
// flip it if you want to write the data on picture
uint8_t data[resolution * resolution * 3];
uint8_t* data = new uint8_t[resolution * resolution * 3];
float step = 1.0 / resolution;
Vec3f Eavg = Vec3f(0.0);
for (int i = 0; i < resolution; i++)
Expand Down
23 changes: 17 additions & 6 deletions Assignment4/lut-gen/Emu_MC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ typedef struct samplePoints {
}samplePoints;

samplePoints squareToCosineHemisphere(int sample_count){
samplePoints samlpeList;
samplePoints sampleList;
const int sample_side = static_cast<int>(floor(sqrt(sample_count)));

std::random_device rd;
Expand All @@ -31,15 +31,15 @@ samplePoints squareToCosineHemisphere(int sample_count){
double sampley = (p + rng(gen)) / sample_side;

double theta = 0.5f * acos(1 - 2*samplex);
double phi = 2 * M_PI * sampley;
double phi = 2 * PI * sampley;
Vec3f wi = Vec3f(sin(theta) * cos(phi), sin(theta) * sin(phi), cos(theta));
float pdf = wi.z / PI;

samlpeList.directions.push_back(wi);
samlpeList.PDFs.push_back(pdf);
sampleList.directions.push_back(wi);
sampleList.PDFs.push_back(pdf);
}
}
return samlpeList;
return sampleList;
}

float DistributionGGX(Vec3f N, Vec3f H, float roughness)
Expand Down Expand Up @@ -83,7 +83,18 @@ Vec3f IntegrateBRDF(Vec3f V, float roughness, float NdotV) {
samplePoints sampleList = squareToCosineHemisphere(sample_count);
for (int i = 0; i < sample_count; i++) {
// TODO: To calculate (fr * ni) / p_o here

Vec3f L = normalize(sampleList.directions[i]);
Vec3f H = normalize(V + L);
float pdf = sampleList.PDFs[i];
float NdotL = std::max(dot(N, L), 0.0f);

float D = DistributionGGX(N, H, roughness);
float G = GeometrySmith(roughness, NdotV, NdotL);
float F = 1.0f;

auto fr = (D * G * F) / (4.0 * NdotV * NdotL);
auto res = fr * NdotL / pdf;
A = B = C += (float)res;
}

return {A / sample_count, B / sample_count, C / sample_count};
Expand Down

0 comments on commit 55be978

Please sign in to comment.