rt backface culling
This commit is contained in:
@@ -0,0 +1,34 @@
|
|||||||
|
import RayTracingData;
|
||||||
|
import Scene;
|
||||||
|
import VertexData;
|
||||||
|
import MaterialParameter;
|
||||||
|
import StaticMeshVertexData;
|
||||||
|
|
||||||
|
[shader("anyhit")]
|
||||||
|
void anyhit(inout RayPayload hitvalue, in BuiltInTriangleIntersectionAttributes attr)
|
||||||
|
{
|
||||||
|
const float3 barycentricCoords = float3(1.0f - attr.barycentrics.x - attr.barycentrics.y, attr.barycentrics.x, attr.barycentrics.y);
|
||||||
|
|
||||||
|
InstanceData inst = pScene.instances[InstanceID()];
|
||||||
|
MeshData m = pScene.meshData[InstanceID()];
|
||||||
|
|
||||||
|
// offset into the index buffer
|
||||||
|
uint indexOffset = m.firstIndex;
|
||||||
|
// added to indices to reference correct part of global mesh pool
|
||||||
|
uint vertexOffset = pScene.meshletInfos[m.meshletOffset].indicesOffset;
|
||||||
|
|
||||||
|
uint vertexIndex0 = vertexOffset + pRayTracingParams.indexBuffer[indexOffset + 3 * PrimitiveIndex() + 0];
|
||||||
|
uint vertexIndex1 = vertexOffset + pRayTracingParams.indexBuffer[indexOffset + 3 * PrimitiveIndex() + 1];
|
||||||
|
uint vertexIndex2 = vertexOffset + pRayTracingParams.indexBuffer[indexOffset + 3 * PrimitiveIndex() + 2];
|
||||||
|
|
||||||
|
VertexAttributes attr0 = pVertexData.getAttributes(vertexIndex0);
|
||||||
|
VertexAttributes attr1 = pVertexData.getAttributes(vertexIndex1);
|
||||||
|
VertexAttributes attr2 = pVertexData.getAttributes(vertexIndex2);
|
||||||
|
|
||||||
|
FragmentParameter f0 = attr0.getParameter(inst.transformMatrix, inst.inverseTransformMatrix);
|
||||||
|
FragmentParameter f1 = attr1.getParameter(inst.transformMatrix, inst.inverseTransformMatrix);
|
||||||
|
FragmentParameter f2 = attr2.getParameter(inst.transformMatrix, inst.inverseTransformMatrix);
|
||||||
|
|
||||||
|
FragmentParameter params = FragmentParameter.interpolate(f0, f1, f2, barycentricCoords);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -71,7 +71,11 @@ import MATERIAL_FILE_NAME;
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static const float eps = 1e-5;
|
const static float ka = 0;
|
||||||
|
const static float ks = 0;
|
||||||
|
const static float3 fogEmm = float3(0, 0.01, 0.01);
|
||||||
|
|
||||||
|
const static float eps = 1e-5;
|
||||||
[shader("closesthit")]
|
[shader("closesthit")]
|
||||||
void closestHit(inout RayPayload hitValue, in BuiltInTriangleIntersectionAttributes attr)
|
void closestHit(inout RayPayload hitValue, in BuiltInTriangleIntersectionAttributes attr)
|
||||||
{
|
{
|
||||||
@@ -116,15 +120,15 @@ void closestHit(inout RayPayload hitValue, in BuiltInTriangleIntersectionAttribu
|
|||||||
float3 rnd = rand01(hitValue.rndSeed);
|
float3 rnd = rand01(hitValue.rndSeed);
|
||||||
//float kt = ka + ks;
|
//float kt = ka + ks;
|
||||||
//float s = -log(rnd.z) / kt;
|
//float s = -log(rnd.z) / kt;
|
||||||
//float3 xs = r.o + s * r.d;
|
//if (s < RayTCurrent()) {
|
||||||
//if (s < t) {
|
// float3 xs = WorldRayOrigin() + s * WorldRayDirection();
|
||||||
// float p = kt * rnd.z;
|
// float p = kt * rnd.z;
|
||||||
// if (depth > 5) {
|
// if (hitValue.depth > 5) {
|
||||||
// if (rnd.z >= p) break;
|
// if (rnd.z >= p) return;
|
||||||
// else accmat /= p;
|
// else brdf.baseColor /= p;
|
||||||
// }
|
// }
|
||||||
// float3 ldirect = nextEventEstimation(accmat, r.d, xs, -r.d, kt, true, rnd);
|
// float3 ldirect = nextEventEstimation(brdf.baseColor, WorldRayDirection(), xs, -WorldRayDirection(), kt, true, rnd);
|
||||||
// accrad += (fogEmm + ks * ldirect) / kt;
|
// hitValue.light += (fogEmm + ks * ldirect) / kt;
|
||||||
// accmat *= ks / kt;
|
// accmat *= ks / kt;
|
||||||
// rayDesc.Origin = xs;
|
// rayDesc.Origin = xs;
|
||||||
// rayDesc.Direction = float3(
|
// rayDesc.Direction = float3(
|
||||||
@@ -132,14 +136,13 @@ void closestHit(inout RayPayload hitValue, in BuiltInTriangleIntersectionAttribu
|
|||||||
// sin(2*PI*rnd.x)*sqrt(1-rnd.y*rnd.y),
|
// sin(2*PI*rnd.x)*sqrt(1-rnd.y*rnd.y),
|
||||||
// rnd.y
|
// rnd.y
|
||||||
// );
|
// );
|
||||||
// continue;
|
// TraceRay(scene, 0, 0xff, 0, 0, rayDesc);
|
||||||
//}
|
//}
|
||||||
|
|
||||||
//float p = max(max(brdf.baseColor.x, brdf.baseColor.y), brdf.baseColor.z);
|
float p = max(max(brdf.baseColor.x, brdf.baseColor.y), brdf.baseColor.z);
|
||||||
//if(hitValue.depth > 5) {
|
if(hitValue.depth > 5) {
|
||||||
// if (rnd.z >= p) return;
|
if (rnd.z >= p) return;
|
||||||
// else hitValue.accmat /= p;
|
}
|
||||||
//}
|
|
||||||
|
|
||||||
hitValue.light += brdf.emissive * hitValue.emissive + brdf.evaluateAmbient();
|
hitValue.light += brdf.emissive * hitValue.emissive + brdf.evaluateAmbient();
|
||||||
//-- Ideal DIFFUSE reflection
|
//-- Ideal DIFFUSE reflection
|
||||||
@@ -160,12 +163,12 @@ void closestHit(inout RayPayload hitValue, in BuiltInTriangleIntersectionAttribu
|
|||||||
payload.anyHit = true;
|
payload.anyHit = true;
|
||||||
payload.hit = false;
|
payload.hit = false;
|
||||||
payload.rndSeed = hitValue.rndSeed;
|
payload.rndSeed = hitValue.rndSeed;
|
||||||
TraceRay(pRayTracingParams.scene, 0, 0xff, 0, 0, 0, rayDesc, payload);
|
TraceRay(pRayTracingParams.scene, RAY_FLAG_CULL_BACK_FACING_TRIANGLES, 0xff, 0, 0, 0, rayDesc, payload);
|
||||||
|
|
||||||
// we have missed all geometry, so directional light is affecting us
|
// we have missed all geometry, so directional light is affecting us
|
||||||
//if(!payload.hit) {
|
if(!payload.hit) {
|
||||||
//hitValue.light += pLightEnv.directionalLights[i].illuminate(lightingParams, brdf);
|
hitValue.light += pLightEnv.directionalLights[i].illuminate(lightingParams, brdf);
|
||||||
//}
|
}
|
||||||
}
|
}
|
||||||
for(uint i = 0; i < pLightEnv.numPointLights; ++i) {
|
for(uint i = 0; i < pLightEnv.numPointLights; ++i) {
|
||||||
RayPayload payload;
|
RayPayload payload;
|
||||||
@@ -180,7 +183,7 @@ void closestHit(inout RayPayload hitValue, in BuiltInTriangleIntersectionAttribu
|
|||||||
rayDesc.TMin = eps;
|
rayDesc.TMin = eps;
|
||||||
rayDesc.Origin = x;
|
rayDesc.Origin = x;
|
||||||
rayDesc.Direction = l;
|
rayDesc.Direction = l;
|
||||||
TraceRay(pRayTracingParams.scene, 0, 0xff, 0, 0, 0, rayDesc, payload);
|
TraceRay(pRayTracingParams.scene, RAY_FLAG_CULL_BACK_FACING_TRIANGLES, 0xff, 0, 0, 0, rayDesc, payload);
|
||||||
|
|
||||||
// hitting only after the light
|
// hitting only after the light
|
||||||
if(!payload.hit) {
|
if(!payload.hit) {
|
||||||
@@ -206,8 +209,9 @@ void closestHit(inout RayPayload hitValue, in BuiltInTriangleIntersectionAttribu
|
|||||||
payload.depth = hitValue.depth;
|
payload.depth = hitValue.depth;
|
||||||
payload.anyHit = false;
|
payload.anyHit = false;
|
||||||
payload.rndSeed = hitValue.rndSeed + 1;
|
payload.rndSeed = hitValue.rndSeed + 1;
|
||||||
TraceRay(pRayTracingParams.scene, 0, 0xff, 0, 0, 0, rayDesc, payload);
|
TraceRay(pRayTracingParams.scene, RAY_FLAG_CULL_BACK_FACING_TRIANGLES, 0xff, 0, 0, 0, rayDesc, payload);
|
||||||
float bias = dot(normalLight_WS, rayDesc.Direction);
|
float bias = dot(normalLight_WS, rayDesc.Direction);
|
||||||
hitValue.light += brdf.evaluate(params.getTangentToWorld(), -WorldRayDirection(), rayDesc.Direction, payload.light / bias);
|
hitValue.light += brdf.evaluate(params.getTangentToWorld(), -WorldRayDirection(), rayDesc.Direction, payload.light / bias);
|
||||||
}
|
}
|
||||||
|
hitValue.light /= p;
|
||||||
}
|
}
|
||||||
@@ -11,9 +11,6 @@ struct Ray
|
|||||||
const static float S_O = 6.9;
|
const static float S_O = 6.9;
|
||||||
const static float f = 0.035;
|
const static float f = 0.035;
|
||||||
const static float A = 0.0;
|
const static float A = 0.0;
|
||||||
const static float ka = 0;
|
|
||||||
const static float ks = 0;
|
|
||||||
const static float3 fogEmm = float3(0, 0.01, 0.01);
|
|
||||||
|
|
||||||
struct SampleParams
|
struct SampleParams
|
||||||
{
|
{
|
||||||
@@ -110,7 +107,7 @@ void raygen()
|
|||||||
payload.depth = 1;
|
payload.depth = 1;
|
||||||
payload.rndSeed = rndSeed + 1;
|
payload.rndSeed = rndSeed + 1;
|
||||||
payload.anyHit = false;
|
payload.anyHit = false;
|
||||||
TraceRay(pRayTracingParams.scene, 0, 0xff, 0, 0, 0, rayDesc, payload);
|
TraceRay(pRayTracingParams.scene, RAY_FLAG_CULL_BACK_FACING_TRIANGLES, 0xff, 0, 0, 0, rayDesc, payload);
|
||||||
|
|
||||||
if(pSamps.pass == 0) pRayTracingParams.radianceAccumulator[pix] = float4(0);
|
if(pSamps.pass == 0) pRayTracingParams.radianceAccumulator[pix] = float4(0);
|
||||||
float3 accumulatedRadiance = payload.light / pSamps.samplesPerPixel;
|
float3 accumulatedRadiance = payload.light / pSamps.samplesPerPixel;
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ int main(int argc, char** argv) {
|
|||||||
graphics->init(initializer);
|
graphics->init(initializer);
|
||||||
StaticMeshVertexData* vd = StaticMeshVertexData::getInstance();
|
StaticMeshVertexData* vd = StaticMeshVertexData::getInstance();
|
||||||
vd->init(graphics);
|
vd->init(graphics);
|
||||||
|
getGlobals().useRayTracing = true;
|
||||||
|
|
||||||
OWindowManager windowManager = new WindowManager();
|
OWindowManager windowManager = new WindowManager();
|
||||||
AssetRegistry::init("Assets", graphics);
|
AssetRegistry::init("Assets", graphics);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#include "PlayView.h"
|
#include "PlayView.h"
|
||||||
#include "Window/Window.h"
|
|
||||||
#include "Component/Mesh.h"
|
#include "Component/Mesh.h"
|
||||||
|
#include "Window/Window.h"
|
||||||
|
|
||||||
using namespace Seele;
|
using namespace Seele;
|
||||||
using namespace Seele::Editor;
|
using namespace Seele::Editor;
|
||||||
@@ -49,4 +49,6 @@ void PlayView::keyCallback(KeyCode code, InputAction action, KeyModifier modifie
|
|||||||
if (code == KeyCode::KEY_R && action == InputAction::RELEASE) {
|
if (code == KeyCode::KEY_R && action == InputAction::RELEASE) {
|
||||||
getGlobals().useRayTracing = !getGlobals().useRayTracing;
|
getGlobals().useRayTracing = !getGlobals().useRayTracing;
|
||||||
}
|
}
|
||||||
|
//if (code == KeyCode::KEY_B && action == InputAction::RELEASE && modifier & KeyModifier::MOD_CONTROL) {
|
||||||
|
//}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#include "GameInterface.h"
|
#include "GameInterface.h"
|
||||||
|
#include "Windows.h"
|
||||||
|
|
||||||
using namespace Seele;
|
using namespace Seele;
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "Game.h"
|
#include "Game.h"
|
||||||
|
#define NOIME
|
||||||
#include "Windows.h"
|
#include "Windows.h"
|
||||||
|
|
||||||
namespace Seele {
|
namespace Seele {
|
||||||
|
|||||||
Reference in New Issue
Block a user