mirror of
https://github.com/TheRedShip/RT_GPU.git
synced 2025-09-27 10:48:34 +02:00
~ | Emissive texture working
This commit is contained in:
@ -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 && mat.emission_texture_index == -1)
|
||||
// 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;
|
||||
|
@ -1,27 +1,28 @@
|
||||
bool intersectSphere(Ray ray, GPUObject obj, out hitInfo hit)
|
||||
{
|
||||
vec3 oc = ray.origin - obj.position;
|
||||
|
||||
float b = dot(oc, ray.direction);
|
||||
float c = dot(oc, oc) - obj.radius * obj.radius;
|
||||
float h = b * b - c;
|
||||
float discriminant = b * b - c;
|
||||
|
||||
float t = -b - sqrt(h);
|
||||
float last_t = -b + sqrt(h);
|
||||
float sqrtD = sqrt(max(0.0, discriminant));
|
||||
float t0 = -b - sqrtD;
|
||||
float t1 = -b + sqrtD;
|
||||
|
||||
if (t > last_t)
|
||||
{
|
||||
float temp = t;
|
||||
t = last_t;
|
||||
last_t = temp;
|
||||
}
|
||||
float temp = min(t0, t1);
|
||||
t1 = max(t0, t1);
|
||||
t0 = temp;
|
||||
|
||||
hit.t = t;
|
||||
hit.last_t = last_t;
|
||||
hit.position = ray.origin + ray.direction * t;
|
||||
bool isInside = c < 0.0;
|
||||
t0 = isInside ? t1 : t0;
|
||||
|
||||
hit.t = t0;
|
||||
hit.last_t = t1;
|
||||
hit.position = ray.origin + ray.direction * t0;
|
||||
hit.normal = normalize(hit.position - obj.position);
|
||||
hit.normal *= (isInside ? -1.0 : 1.0);
|
||||
|
||||
return (h >= 0.0 && t > 0.0);
|
||||
return (discriminant >= 0.0) && (t0 > 0.0);
|
||||
}
|
||||
|
||||
bool intersectPlane(Ray ray, GPUObject obj, out hitInfo hit)
|
||||
|
@ -90,11 +90,9 @@ vec3 sampleLights(vec3 position, inout uint rng_state)
|
||||
|
||||
vec2 getSphereUV(vec3 surfacePoint)
|
||||
{
|
||||
// Convert 3D point to spherical coordinates
|
||||
float phi = atan(surfacePoint.z, surfacePoint.x);
|
||||
float theta = acos(surfacePoint.y);
|
||||
|
||||
// Map to [0, 1] UV space
|
||||
float u = (phi + M_PI) / (2.0 * M_PI);
|
||||
float v = theta / M_PI;
|
||||
|
||||
@ -113,11 +111,9 @@ vec2 getTextureColor(hitInfo hit)
|
||||
else if (hit.obj_type == 3)
|
||||
{
|
||||
GPUTriangle tri = triangles[hit.obj_index];
|
||||
|
||||
uv = hit.u * tri.texture_vertex2 + hit.v * tri.texture_vertex3 + (1 - (hit.u + hit.v)) * tri.texture_vertex1;
|
||||
uv = vec2(uv.x, 1 - uv.y);
|
||||
}
|
||||
return (uv);
|
||||
return (vec2(uv.x, 1 - uv.y));
|
||||
}
|
||||
|
||||
void calculateLightColor(GPUMaterial mat, hitInfo hit, inout vec3 color, inout vec3 light, inout uint rng_state)
|
||||
@ -136,8 +132,8 @@ void calculateLightColor(GPUMaterial mat, hitInfo hit, inout vec3 color, inou
|
||||
}
|
||||
else
|
||||
{
|
||||
light += mat.emission * mat.color;
|
||||
color *= mat.color;
|
||||
light += mat.emission * mat.color;
|
||||
}
|
||||
// light += sampleLights(hit.position, rng_state);
|
||||
}
|
BIN
skymap.hdr
Normal file
BIN
skymap.hdr
Normal file
Binary file not shown.
@ -333,11 +333,13 @@ void ObjParser::parseMtl(std::stringstream &input_line, Scene &scene)
|
||||
throw std::runtime_error("OBJ: syntax error while getting material texture");
|
||||
|
||||
mat->emission_texture_index = scene.getEmissionTextures().size();
|
||||
std::cout << "path " << mat->emission_texture_index << " : " << getFilePath(_filename) + path << std::endl;
|
||||
scene.addEmissionTexture(getFilePath(_filename) + path);
|
||||
|
||||
if (mat->emission == 0)
|
||||
mat->emission = 1;
|
||||
}
|
||||
else
|
||||
std::cerr << "unsupported material setting : " << identifier << std::endl;
|
||||
// else
|
||||
// std::cerr << "unsupported material setting : " << identifier << std::endl;
|
||||
}
|
||||
if(mat)
|
||||
{
|
||||
|
Reference in New Issue
Block a user