~ | Fixing emissive texture

This commit is contained in:
TheRedShip
2025-02-02 15:16:47 +01:00
parent 328737ac4b
commit f03d48e62d
11 changed files with 73 additions and 32 deletions

View File

@ -202,8 +202,8 @@ vec3 pathtrace(Ray ray, inout uint rng_state)
GPUMaterial mat = materials[hit.mat_index];
calculateLightColor(mat, hit, color, light, rng_state);
if (mat.emission > 0.0)
break;
// if (mat.emission > 0.0 && mat.emission_texture_index == -1)
// break;
ray = newRay(hit, ray, rng_state);
ray.inv_direction = 1.0 / ray.direction;

View File

@ -2,7 +2,7 @@ hitInfo traceRay(Ray ray);
vec3 GetEnvironmentLight(Ray ray)
{
return vec3(0.);
// return vec3(0.);
vec3 sun_pos = vec3(-0.5, 0.5, 0.5);
float SunFocus = 1.5;
float SunIntensity = 1.;
@ -101,8 +101,8 @@ vec2 getSphereUV(vec3 surfacePoint)
return vec2(u, v);
}
uniform sampler2D textures[32];
uniform sampler2D emission_textures[32];
uniform sampler2D textures[64];
uniform sampler2D emissive_textures[64];
vec2 getTextureColor(hitInfo hit)
{
@ -130,11 +130,14 @@ void calculateLightColor(GPUMaterial mat, hitInfo hit, inout vec3 color, inou
if (mat.emission_texture_index != -1)
{
vec2 uv = getTextureColor(hit);
light += mat.emission * texture(emission_textures[mat.emission_texture_index], uv).rgb;
vec3 emission = mat.emission * texture(emissive_textures[mat.emission_texture_index], uv).rgb;
light += mat.emission * emission;
}
else
{
light += mat.emission * mat.color;
color *= mat.color;
color *= mat.color;
}
// light += sampleLights(hit.position, rng_state);
}

View File

@ -141,22 +141,21 @@ hitInfo traverseBVHs(Ray ray)
hitInfo temp_hit = traceBVH(transformedRay, BvhData[i]);
float transformed_t = temp_hit.t / bvh_data.scale;
if (transformed_t < hit.t)
{
GPUTriangle triangle = triangles[temp_hit.obj_index];
GPUTriangle triangle = triangles[temp_hit.obj_index];
hit.u = temp_hit.u;
hit.v = temp_hit.v;
hit.t = transformed_t;
hit.obj_index = temp_hit.obj_index;
hit.mat_index = triangle.mat_index;
vec3 position = transformedRay.origin + transformedRay.direction * temp_hit.t;
hit.position = inverseTransformMatrix * position + bvh_data.offset;
vec3 based_normal = triangle.normal; // * sign(-dot(transformedRay.direction, triangle.normal));
vec3 based_normal = triangle.normal * sign(-dot(transformedRay.direction, triangle.normal));
hit.normal = normalize(inverseTransformMatrix * based_normal);
}
}