Skip to content

Commit

Permalink
implemented lighting for geo render
Browse files Browse the repository at this point in the history
see #1250
  • Loading branch information
t3kt committed Nov 17, 2024
1 parent e5ff1fd commit 5fade12
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 4 deletions.
Binary file modified src/operators/output/raymarchObject.tox
Binary file not shown.
2 changes: 1 addition & 1 deletion src/operators/output/raymarchObject.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
!rop
meta: !meta
opType: raytk.operators.output.raymarchObject
opVersion: '2'
opVersion: '3'
opStatus: alpha
opDef: !def
enable: true
Expand Down
35 changes: 32 additions & 3 deletions src/operators/output/raymarchObject_fragmentShaderBody.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,36 @@ Ray getViewRay(vec2 shift) {
return ray;
}

void prepareLights(vec3 p, inout MaterialContext matCtx) {
LightContext lightCtx = createLightContext(matCtx.result, matCtx.normal);
#ifdef RAYTK_GLOBAL_POS_IN_CONTEXT
lightCtx.globalPos = matCtx.globalPos;
#endif

// TODO: shadow
#if RAYTK_LIGHT_COUNT > 1
{
for (int i = 0; i < RAYTK_LIGHT_COUNT; i++) {
Light light = createLight(uTDLights[i].position.xyz, uTDLights[i].diffuse.xyz);
matCtx.allLights[i] = light;
// matCtx.allShadedLevels[i] = calcShadedLevel(p, matCtx);
// TODO: shadow
matCtx.allShadedLevels[i] = 1;
}
matCtx.light = matCtx.allLights[0];
matCtx.shadedLevel = matCtx.allShadedLevels[0];
}
#else
{
lightCtx.index = 0;
Light light = createLight(uTDLights[0].position.xyz, uTDLights[0].diffuse.xyz);
matCtx.light = light;
matCtx.lightIndex = 0;
// TODO: shadow
}
#endif
}

void main()
{
TDCheckDiscard();
Expand Down Expand Up @@ -274,15 +304,14 @@ void main()
#endif

matCtx.normal = calcNormal(p);
prepareLights(p, matCtx);

vec4 col = getColorFromMats(p, matCtx);

vec2 uv = gl_FragCoord.xy * uTDGeneral.viewport.zw;
col.rgb += (1.0/255.0)*hash1(uv);
colorOut = col;
} else {
discard;
}
// colorOut.g = res.x;
// colorOut = vec4(ray.pos, 1);
// colorOut = vec4(map(ray.pos).x, 0, 0, 1);
}
1 change: 1 addition & 0 deletions src/operators/output/raymarchObject_macros.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
parent().par.Uselimitbox 'THIS_USE_LIMIT_BOX' ''
'RAYTK_MAX_STEPS' 'THIS_Maxsteps'
'RAYTK_SURF_DIST' 'THIS_Surfdist'
'RAYTK_LIGHT_COUNT' 'TD_NUM_LIGHTS'
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/testCases/operators/output/raymarchObject_test.tox
Binary file not shown.

0 comments on commit 5fade12

Please sign in to comment.