Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose debug render mode in standard renderer #319

Closed
vorg opened this issue Oct 20, 2022 · 4 comments
Closed

Expose debug render mode in standard renderer #319

vorg opened this issue Oct 20, 2022 · 4 comments
Assignees
Milestone

Comments

@vorg
Copy link
Member

vorg commented Oct 20, 2022

My current idea is

const standardRenderer = systems.renderer.standard()
//or
const standardRenderer = renderEngine.renderers.find(
   (renderer) => renderer.type == "standard-renderer"
);

standardRenderer.debugRender = "data.normalView"
standardRenderer.debugRender = "data.indirectSpecular"
standardRenderer.debugRender = "data.vNormalView"
...

//reset to normal rendering
standardRenderer.debugRender = ""

This would inject code to overwrite output color with specified data for both opaque and transparent entities.

Q: debugRender, debugMode, renderMode?

@vorg
Copy link
Member Author

vorg commented Oct 20, 2022

Alternative approach with the downside of needing to do that per entity would be

const entity = createEntity({
   id: "cube1",
   transform: components.transform(),
   geometry: components.geometry(cube()),
   material: components.material({
      inject: {
          AFTER_FILNAL_COLOR: /*glsl*/`gl_FragData[0] = vec4(data.normalView, 1.0);`
      }
   })
})
``

@dmnsgn
Copy link
Member

dmnsgn commented Oct 20, 2022

Somewhat related issue #249

Q: debugRender, debugMode, renderMode?

Some remarks:
They sound more like boolean properties than string to be injected in shader for program.
Does "mode" suffix has potential to be slightly confusing with standard/line/unlit rendering mode?
"debug" prefix is also a bit restrictive as the property could be used to tweak the output, no necessarily only for debug purpose.

Alternative approach with the downside of needing to do that per entity would be

Sounds a bit more flexible than on the render system (although I understand probably more implementation work) and could be added in a loop if you have many entities :

world.entities.forEach(({ material }) => material?....);

@dmnsgn
Copy link
Member

dmnsgn commented May 5, 2023

Current solution, string replace:

let debugRender = options.debugRender;
if (debugRender) {
let scale = "";
let pow = 1;
let mode = debugRender.toLowerCase();
if (mode.includes("normal")) {
scale = "*0.5 + 0.5";
}
if (mode.includes("texcoord")) {
debugRender = `vec3(${debugRender}, 0.0)`;
}
if (
mode.includes("ao") ||
mode.includes("normal") ||
mode.includes("metallic") ||
mode.includes("roughness")
) {
pow = "2.2";
}
frag = frag.replace(
"gl_FragData[0] = encode(vec4(color, 1.0), uOutputEncoding);",
`gl_FragData[0] = vec4(pow(vec3(${debugRender}${scale}), vec3(${pow})), 1.0);`
);
}

@dmnsgn dmnsgn added this to the 4.0.0 milestone May 5, 2023
@vorg
Copy link
Member Author

vorg commented Sep 5, 2023

We can clean it up a bit but appending debugRender code to FRAG_END hook saving us from one extra string replace.

@dmnsgn dmnsgn self-assigned this Sep 5, 2023
@dmnsgn dmnsgn closed this as completed Sep 7, 2023
@github-project-automation github-project-automation bot moved this to Done in 4.0.0 Aug 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

No branches or pull requests

2 participants