Skip to content

Commit

Permalink
use struct for inputs to custom main functions
Browse files Browse the repository at this point in the history
see #1220
  • Loading branch information
t3kt committed Jun 9, 2024
1 parent 21ff084 commit a742054
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 3 deletions.
Binary file modified src/operators/output/customRender.tox
Binary file not shown.
7 changes: 6 additions & 1 deletion src/operators/output/customRender.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
!rop
meta: !meta
opType: raytk.operators.output.customRender
opVersion: '18'
opVersion: '19'
opStatus: alpha
paramPages:
- !page
Expand Down Expand Up @@ -192,6 +192,11 @@ opDef: !def
callbacks: !text
file: src/operators/output/customRender.py
name: customRender
macroTable: !table
file: src/operators/output/customRender_macros.txt
name: macro_exprs
evaluate: true
evalOpts: !evalOpts {}
displayCategory: Render
inputs:
- !input
Expand Down
17 changes: 16 additions & 1 deletion src/operators/output/customRender_body.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,21 @@ void main() {
#endif
initOutputs();

CustomRenderInputs inputs;
inputs.uvPos = vec3(vUV.st, 0.);
inputs.resolution = vec3(uTDOutputInfo.res.zw, 1.);
#if defined(RAYTK_OUTPUT_TEXTURE_2D)
#elif defined(RAYTK_OUTPUT_TEXTURE_3D)
inputs.uvPos.z = uTDOutputInfo.depth.z; // depth offset
inputs.resolution.z = int(uTDOutputInfo.depth.y); // depth
#elif defined(RAYTK_OUTPUT_TEXTURE_2D_ARRAY)
inputs.resolution.z = int(uTDOutputInfo.depth.y);
if (inputs.resolution.z > 1) {
inputs.uvPos.z = uTDOutputInfo.depth.z / (inputs.resolution.z - 1.0);
}
#endif
inputs.pixelPos = ivec3(inputs.uvPos * inputs.resolution);

vec2 resolution = uTDOutputInfo.res.zw;
vec2 fragCoord = vUV.st;//*resolution;
fragCoord.x *= uTDOutputInfo.res.z/uTDOutputInfo.res.w;
Expand All @@ -13,5 +28,5 @@ void main() {

Context ctx = createDefaultContext();

customMain(fragCoord, p, ctx);
customMain(inputs, ctx);
}
3 changes: 2 additions & 1 deletion src/operators/output/customRender_defaultMainCode.glsl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
void customMain(vec2 fragCoord, vec2 p, Context ctx) {
void customMain(CustomRenderInputs inputs, Context ctx) {
vec2 p = inputs.uvPos.xy * vec2(2.) - vec2(1.);
vec4 res1 = fillToVec4(inputOp1(p, ctx));
#ifdef OUTPUT_COLOR
colorOut = TDOutputSwizzle(res1);
Expand Down
3 changes: 3 additions & 0 deletions src/operators/output/customRender_macros.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
int(parent().par.Type == 'texture2d') 'RAYTK_OUTPUT_TEXTURE_2D' ''
int(parent().par.Type == 'texture3d') 'RAYTK_OUTPUT_TEXTURE_3D' ''
int(parent().par.Type == 'texture2darray') 'RAYTK_OUTPUT_TEXTURE_2D_ARRAY' ''
5 changes: 5 additions & 0 deletions src/operators/output/customRender_predeclarations.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
struct CustomRenderInputs {
ivec3 pixelPos;
vec3 uvPos;
vec3 resolution;
};
Binary file modified tests/testCases/operators/output/customRender_test.tox
Binary file not shown.

0 comments on commit a742054

Please sign in to comment.