Skip to content

CAD DTM Rendering #186

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

Open
wants to merge 62 commits into
base: master
Choose a base branch
from
Open

CAD DTM Rendering #186

wants to merge 62 commits into from

Conversation

Erfan-Ahmadi
Copy link
Contributor

@Erfan-Ahmadi Erfan-Ahmadi commented Mar 25, 2025

CAD DTM Rendering Example
Devsh-Graphics-Programming/Nabla#858

};

// Set 0 - Scene Data and Globals, buffer bindings don't change the buffers only get updated
[[vk::binding(0, 0)]] ConstantBuffer<Globals> globals : register(b0);
[[vk::binding(1, 0)]] StructuredBuffer<DrawObject> drawObjects : register(t0);
[[vk::binding(2, 0)]] StructuredBuffer<MainObject> mainObjects : register(t1);
[[vk::binding(3, 0)]] StructuredBuffer<LineStyle> lineStyles : register(t2);
[[vk::binding(4, 0)]] StructuredBuffer<DTMSettings> dtmSettingsBuff : register(t3);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

small rename, just dtmSettings

{
float4 outputColor = colorBelow;
outputColor.rgb = colorAbove.rgb * colorAbove.a + outputColor.rgb * outputColor.a * (1.0f - colorAbove.a);
outputColor.a = colorAbove.a + outputColor.a * (1.0f - colorAbove.a);
Copy link
Contributor Author

@Erfan-Ahmadi Erfan-Ahmadi Apr 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • I think first ever blendColorOnTop, should override outputColor (dtmColor) and not blend at all. you're wrongly blending with color black (let's say your only have height shading and it's color is (1, 0, 0, 0.5)), background color can be anything. you should let the hardware do the final blend. seems like you handle that by multiplying by outputColor.a

  • looks like you're using the under blending operator, in that case it should be blendUnder?!

TL;DR I need some time to figure this out, can you help me understand why this works?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok we should do under blending, change this function's name to blendUnder and then render the other way around.
and as an optimization skip rendering the next stuff if alpha is 1.0 (the color is gonna get discarded for things behind)

the under blending operator is as follows:

dst.rgb = dst.rgb*dst.a + (1-dst.a)*src.a*src.rgb; // src and dst swapped
dst.a = (1.0f-src.a)*dst.a + src.a; // like currently implemented
``
the current implementation while it looks correct, fails when you just blend a bunch of fully transparent things on top of a semi transparent thing because `outputColor.rgb = outputColor.rgb*outputColor.a;` each time. 

Copy link
Contributor Author

@Erfan-Ahmadi Erfan-Ahmadi Apr 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Edits: after putting some thought into it and reading dual depth, we should replace dst.rgb*dst.a with just dst.rgb because the multiplication was taken into account in previous steps by src.a*src.rgb

so the whole expression becomes:

dst.rgb = dst.rgb + (1-dst.a)*src.a*src.rgb; // src and dst swapped
dst.a = (1.0f-src.a)*dst.a + src.a; // like currently implemented

// TODO: functions outside of the "dtm" namespace need to be moved to another file

// for usage in upper_bound function
struct StyleAccessor
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move these to line_style.hlsl, and include it here
these aren't related to dtms

return dot(vec, vec);
}

// TODO: Later move these functions and structs to dtmSettings.hlsl and a namespace like dtmSettings::height_shading or dtmSettings::contours, etc..
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants