Add a camera near/far setting in gltf_viewer
This commit is contained in:
committed by
Mathias Agopian
parent
d9266ba61c
commit
94f121f37d
@@ -166,6 +166,8 @@ Java_com_google_android_filament_utils_AutomationEngine_nGetViewerOptions(JNIEnv
|
||||
const jfieldID cameraAperture = env->GetFieldID(klass, "cameraAperture", "F");
|
||||
const jfieldID cameraSpeed = env->GetFieldID(klass, "cameraSpeed", "F");
|
||||
const jfieldID cameraISO = env->GetFieldID(klass, "cameraISO", "F");
|
||||
const jfieldID cameraNear = env->GetFieldID(klass, "cameraNear", "F");
|
||||
const jfieldID cameraFar = env->GetFieldID(klass, "cameraFar", "F");
|
||||
const jfieldID groundShadowStrength = env->GetFieldID(klass, "groundShadowStrength", "F");
|
||||
const jfieldID groundPlaneEnabled = env->GetFieldID(klass, "groundPlaneEnabled", "Z");
|
||||
const jfieldID skyboxEnabled = env->GetFieldID(klass, "skyboxEnabled", "Z");
|
||||
@@ -177,6 +179,8 @@ Java_com_google_android_filament_utils_AutomationEngine_nGetViewerOptions(JNIEnv
|
||||
env->SetFloatField(result, cameraAperture, options.cameraAperture);
|
||||
env->SetFloatField(result, cameraSpeed, options.cameraSpeed);
|
||||
env->SetFloatField(result, cameraISO, options.cameraISO);
|
||||
env->SetFloatField(result, cameraNear, options.cameraNear);
|
||||
env->SetFloatField(result, cameraFar, options.cameraFar);
|
||||
env->SetFloatField(result, groundShadowStrength, options.groundShadowStrength);
|
||||
env->SetBooleanField(result, groundPlaneEnabled, options.groundPlaneEnabled);
|
||||
env->SetBooleanField(result, skyboxEnabled, options.skyboxEnabled);
|
||||
|
||||
+2
@@ -97,6 +97,8 @@ public class AutomationEngine {
|
||||
public float cameraAperture = 16.0f;
|
||||
public float cameraSpeed = 125.0f;
|
||||
public float cameraISO = 100.0f;
|
||||
public float cameraNear = 0.1f;
|
||||
public float cameraFar = 100.0f;
|
||||
public float groundShadowStrength = 0.75f;
|
||||
public boolean groundPlaneEnabled = false;
|
||||
public boolean skyboxEnabled = true;
|
||||
|
||||
+16
-3
@@ -27,8 +27,8 @@ import com.google.android.filament.gltfio.*
|
||||
import kotlinx.coroutines.*
|
||||
import java.nio.Buffer
|
||||
|
||||
private const val kNearPlane = 0.05 // 5 cm
|
||||
private const val kFarPlane = 1000.0 // 1 km
|
||||
private const val kNearPlane = 0.05f // 5 cm
|
||||
private const val kFarPlane = 1000.0f // 1 km
|
||||
private const val kAperture = 16f
|
||||
private const val kShutterSpeed = 1f / 125f
|
||||
private const val kSensitivity = 100f
|
||||
@@ -80,6 +80,18 @@ class ModelViewer(
|
||||
updateCameraProjection()
|
||||
}
|
||||
|
||||
var cameraNear = kNearPlane
|
||||
set(value) {
|
||||
field = value
|
||||
updateCameraProjection()
|
||||
}
|
||||
|
||||
var cameraFar = kFarPlane
|
||||
set(value) {
|
||||
field = value
|
||||
updateCameraProjection()
|
||||
}
|
||||
|
||||
val scene: Scene
|
||||
val view: View
|
||||
val camera: Camera
|
||||
@@ -368,7 +380,8 @@ class ModelViewer(
|
||||
val width = view.viewport.width
|
||||
val height = view.viewport.height
|
||||
val aspect = width.toDouble() / height.toDouble()
|
||||
camera.setLensProjection(cameraFocalLength.toDouble(), aspect, kNearPlane, kFarPlane)
|
||||
camera.setLensProjection(cameraFocalLength.toDouble(), aspect,
|
||||
cameraNear.toDouble(), cameraFar.toDouble())
|
||||
}
|
||||
|
||||
inner class SurfaceCallback : UiHelper.RendererCallback {
|
||||
|
||||
+2
@@ -356,6 +356,8 @@ class MainActivity : Activity() {
|
||||
automation.applySettings(modelViewer.engine, json, viewerContent)
|
||||
modelViewer.view.colorGrading = automation.getColorGrading(modelViewer.engine)
|
||||
modelViewer.cameraFocalLength = automation.viewerOptions.cameraFocalLength
|
||||
modelViewer.cameraNear = automation.viewerOptions.cameraNear
|
||||
modelViewer.cameraFar = automation.viewerOptions.cameraFar
|
||||
updateRootTransform()
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because one or more lines are too long
Binary file not shown.
@@ -88,7 +88,8 @@ public:
|
||||
|
||||
void setSidebarWidth(int width) { mSidebarWidth = width; }
|
||||
void setWindowTitle(const char* title) { mWindowTitle = title; }
|
||||
float& getCameraFocalLength() { return mCameraFocalLength; }
|
||||
void setCameraFocalLength(float focalLength) { mCameraFocalLength = focalLength; }
|
||||
void setCameraNearFar(float near, float far) { mCameraNear = near; mCameraFar = far; }
|
||||
|
||||
void addOffscreenView(filament::View* view) { mOffscreenViews.push_back(view); }
|
||||
|
||||
@@ -241,6 +242,8 @@ private:
|
||||
std::string mWindowTitle;
|
||||
std::vector<filament::View*> mOffscreenViews;
|
||||
float mCameraFocalLength = 28.0f;
|
||||
float mCameraNear = 0.1f;
|
||||
float mCameraFar = 100.0f;
|
||||
};
|
||||
|
||||
#endif // TNT_FILAMENT_SAMPLE_FILAMENTAPP_H
|
||||
|
||||
@@ -191,6 +191,8 @@ void FilamentApp::run(const Config& config, SetupCallback setupCallback,
|
||||
|
||||
int sidebarWidth = mSidebarWidth;
|
||||
float cameraFocalLength = mCameraFocalLength;
|
||||
float cameraNear = mCameraNear;
|
||||
float cameraFar = mCameraFar;
|
||||
|
||||
SDL_EventState(SDL_DROPFILE, SDL_ENABLE);
|
||||
SDL_Window* sdlWindow = window->getSDLWindow();
|
||||
@@ -200,10 +202,15 @@ void FilamentApp::run(const Config& config, SetupCallback setupCallback,
|
||||
SDL_SetWindowTitle(sdlWindow, mWindowTitle.c_str());
|
||||
}
|
||||
|
||||
if (mSidebarWidth != sidebarWidth || mCameraFocalLength != cameraFocalLength) {
|
||||
if (mSidebarWidth != sidebarWidth ||
|
||||
mCameraFocalLength != cameraFocalLength ||
|
||||
mCameraNear != cameraNear ||
|
||||
mCameraFar != cameraFar) {
|
||||
window->configureCamerasForWindow();
|
||||
sidebarWidth = mSidebarWidth;
|
||||
cameraFocalLength = mCameraFocalLength;
|
||||
cameraNear = mCameraNear;
|
||||
cameraFar = mCameraFar;
|
||||
}
|
||||
|
||||
if (!UTILS_HAS_THREADING) {
|
||||
@@ -791,8 +798,8 @@ void FilamentApp::Window::configureCamerasForWindow() {
|
||||
// the sidebar. To prevent this we simply clamp the width of the main viewport.
|
||||
const uint32_t mainWidth = splitview ? width : std::max(1, (int) width - sidebar);
|
||||
|
||||
double near = 0.1;
|
||||
double far = 100;
|
||||
double near = mFilamentApp->mCameraNear;
|
||||
double far = mFilamentApp->mCameraFar;
|
||||
mMainCamera->setLensProjection(mFilamentApp->mCameraFocalLength, double(mainWidth) / height, near, far);
|
||||
mDebugCamera->setProjection(45.0, double(width) / height, 0.0625, 4096, Camera::Fov::VERTICAL);
|
||||
|
||||
|
||||
@@ -214,6 +214,8 @@ struct ViewerOptions {
|
||||
float cameraAperture = 16.0f;
|
||||
float cameraSpeed = 125.0f;
|
||||
float cameraISO = 100.0f;
|
||||
float cameraNear = 0.1f;
|
||||
float cameraFar = 100.0f;
|
||||
float groundShadowStrength = 0.75f;
|
||||
bool groundPlaneEnabled = false;
|
||||
bool skyboxEnabled = true;
|
||||
|
||||
@@ -444,6 +444,10 @@ static int parse(jsmntok_t const* tokens, int i, const char* jsonChunk, ViewerOp
|
||||
i = parse(tokens, i + 1, jsonChunk, &out->cameraSpeed);
|
||||
} else if (compare(tok, jsonChunk, "cameraISO") == 0) {
|
||||
i = parse(tokens, i + 1, jsonChunk, &out->cameraISO);
|
||||
} else if (compare(tok, jsonChunk, "cameraNear") == 0) {
|
||||
i = parse(tokens, i + 1, jsonChunk, &out->cameraNear);
|
||||
} else if (compare(tok, jsonChunk, "cameraFar") == 0) {
|
||||
i = parse(tokens, i + 1, jsonChunk, &out->cameraFar);
|
||||
} else if (compare(tok, jsonChunk, "groundShadowStrength") == 0) {
|
||||
i = parse(tokens, i + 1, jsonChunk, &out->groundShadowStrength);
|
||||
} else if (compare(tok, jsonChunk, "groundPlaneEnabled") == 0) {
|
||||
@@ -773,6 +777,8 @@ static std::ostream& operator<<(std::ostream& out, const ViewerOptions& in) {
|
||||
<< "\"cameraAperture\": " << (in.cameraAperture) << ",\n"
|
||||
<< "\"cameraSpeed\": " << (in.cameraSpeed) << ",\n"
|
||||
<< "\"cameraISO\": " << (in.cameraISO) << ",\n"
|
||||
<< "\"cameraNear\": " << (in.cameraNear) << ",\n"
|
||||
<< "\"cameraFar\": " << (in.cameraFar) << ",\n"
|
||||
<< "\"groundShadowStrength\": " << (in.groundShadowStrength) << ",\n"
|
||||
<< "\"groundPlaneEnabled\": " << to_string(in.groundPlaneEnabled) << ",\n"
|
||||
<< "\"skyboxEnabled\": " << to_string(in.skyboxEnabled) << ",\n"
|
||||
|
||||
@@ -939,34 +939,35 @@ void ViewerGui::updateUserInterface() {
|
||||
if (ImGui::CollapsingHeader("Camera")) {
|
||||
ImGui::Indent();
|
||||
|
||||
ImGui::SliderFloat("Focal length (mm)", &mSettings.viewer.cameraFocalLength,
|
||||
16.0f, 90.0f);
|
||||
|
||||
bool dofMedian = mSettings.view.dof.filter == View::DepthOfFieldOptions::Filter::MEDIAN;
|
||||
int dofRingCount = mSettings.view.dof.fastGatherRingCount;
|
||||
int dofMaxCoC = mSettings.view.dof.maxForegroundCOC;
|
||||
if (!dofRingCount) dofRingCount = 5;
|
||||
if (!dofMaxCoC) dofMaxCoC = 32;
|
||||
|
||||
ImGui::SliderFloat("Focal length (mm)", &mSettings.viewer.cameraFocalLength, 16.0f, 90.0f);
|
||||
ImGui::SliderFloat("Aperture", &mSettings.viewer.cameraAperture, 1.0f, 32.0f);
|
||||
ImGui::SliderFloat("Speed (1/s)", &mSettings.viewer.cameraSpeed, 1000.0f, 1.0f);
|
||||
ImGui::SliderFloat("ISO", &mSettings.viewer.cameraISO, 25.0f, 6400.0f);
|
||||
ImGui::Checkbox("DoF", &mSettings.view.dof.enabled);
|
||||
ImGui::SliderFloat("Focus distance", &mSettings.viewer.cameraFocusDistance, 0.0f, 30.0f);
|
||||
ImGui::SliderFloat("Blur scale", &mSettings.view.dof.cocScale, 0.1f, 10.0f);
|
||||
ImGui::SliderInt("Ring count", &dofRingCount, 1, 17);
|
||||
ImGui::SliderInt("Max CoC", &dofMaxCoC, 1, 32);
|
||||
ImGui::Checkbox("Native Resolution", &mSettings.view.dof.nativeResolution);
|
||||
ImGui::Checkbox("Median Filter", &dofMedian);
|
||||
ImGui::SliderFloat("Near", &mSettings.viewer.cameraNear, 0.001f, 1.0f);
|
||||
ImGui::SliderFloat("Far", &mSettings.viewer.cameraFar, 1.0f, 10000.0f);
|
||||
|
||||
mSettings.view.dof.filter = dofMedian ?
|
||||
View::DepthOfFieldOptions::Filter::MEDIAN :
|
||||
View::DepthOfFieldOptions::Filter::NONE;
|
||||
mSettings.view.dof.backgroundRingCount = dofRingCount;
|
||||
mSettings.view.dof.foregroundRingCount = dofRingCount;
|
||||
mSettings.view.dof.fastGatherRingCount = dofRingCount;
|
||||
mSettings.view.dof.maxForegroundCOC = dofMaxCoC;
|
||||
mSettings.view.dof.maxBackgroundCOC = dofMaxCoC;
|
||||
if (ImGui::CollapsingHeader("DoF")) {
|
||||
bool dofMedian = mSettings.view.dof.filter == View::DepthOfFieldOptions::Filter::MEDIAN;
|
||||
int dofRingCount = mSettings.view.dof.fastGatherRingCount;
|
||||
int dofMaxCoC = mSettings.view.dof.maxForegroundCOC;
|
||||
if (!dofRingCount) dofRingCount = 5;
|
||||
if (!dofMaxCoC) dofMaxCoC = 32;
|
||||
ImGui::Checkbox("Enabled##dofEnabled", &mSettings.view.dof.enabled);
|
||||
ImGui::SliderFloat("Focus distance", &mSettings.viewer.cameraFocusDistance, 0.0f, 30.0f);
|
||||
ImGui::SliderFloat("Blur scale", &mSettings.view.dof.cocScale, 0.1f, 10.0f);
|
||||
ImGui::SliderInt("Ring count", &dofRingCount, 1, 17);
|
||||
ImGui::SliderInt("Max CoC", &dofMaxCoC, 1, 32);
|
||||
ImGui::Checkbox("Native Resolution", &mSettings.view.dof.nativeResolution);
|
||||
ImGui::Checkbox("Median Filter", &dofMedian);
|
||||
mSettings.view.dof.filter = dofMedian ?
|
||||
View::DepthOfFieldOptions::Filter::MEDIAN :
|
||||
View::DepthOfFieldOptions::Filter::NONE;
|
||||
mSettings.view.dof.backgroundRingCount = dofRingCount;
|
||||
mSettings.view.dof.foregroundRingCount = dofRingCount;
|
||||
mSettings.view.dof.fastGatherRingCount = dofRingCount;
|
||||
mSettings.view.dof.maxForegroundCOC = dofMaxCoC;
|
||||
mSettings.view.dof.maxBackgroundCOC = dofMaxCoC;
|
||||
}
|
||||
|
||||
if (ImGui::CollapsingHeader("Vignette")) {
|
||||
ImGui::Checkbox("Enabled##vignetteEnabled", &mSettings.view.vignette.enabled);
|
||||
|
||||
@@ -854,7 +854,6 @@ int main(int argc, char** argv) {
|
||||
auto& rcm = engine->getRenderableManager();
|
||||
auto instance = rcm.getInstance(app.scene.groundPlane);
|
||||
const auto viewerOptions = app.automationEngine->getViewerOptions();
|
||||
const auto& dofOptions = app.viewer->getSettings().view.dof;
|
||||
rcm.setLayerMask(instance,
|
||||
0xff, viewerOptions.groundPlaneEnabled ? 0xff : 0x00);
|
||||
|
||||
@@ -862,7 +861,8 @@ int main(int argc, char** argv) {
|
||||
|
||||
// Note that this focal length might be different from the slider value because the
|
||||
// automation engine applies Camera::computeEffectiveFocalLength when DoF is enabled.
|
||||
FilamentApp::get().getCameraFocalLength() = viewerOptions.cameraFocalLength;
|
||||
FilamentApp::get().setCameraFocalLength(viewerOptions.cameraFocalLength);
|
||||
FilamentApp::get().setCameraNearFar(viewerOptions.cameraNear, viewerOptions.cameraFar);
|
||||
|
||||
const size_t cameraCount = app.asset->getCameraEntityCount();
|
||||
view->setCamera(app.mainCamera);
|
||||
|
||||
@@ -596,11 +596,16 @@ static void gui(filament::Engine* engine, filament::View*) {
|
||||
|
||||
if (ImGui::CollapsingHeader("Camera")) {
|
||||
ImGui::Indent();
|
||||
ImGui::SliderFloat("Focal length", &FilamentApp::get().getCameraFocalLength(), 16.0f, 90.0f);
|
||||
ImGui::SliderFloat("Focal length", ¶ms.cameraFocalLength, 16.0f, 90.0f);
|
||||
ImGui::SliderFloat("Aperture", ¶ms.cameraAperture, 1.0f, 32.0f);
|
||||
ImGui::SliderFloat("Speed", ¶ms.cameraSpeed, 800.0f, 1.0f);
|
||||
ImGui::SliderFloat("ISO", ¶ms.cameraISO, 25.0f, 6400.0f);
|
||||
ImGui::SliderFloat("Near", ¶ms.cameraNear, 0.01f, 1.0f);
|
||||
ImGui::SliderFloat("Far", ¶ms.cameraFar, 1.0f, 10000.0f);
|
||||
ImGui::Unindent();
|
||||
|
||||
FilamentApp::get().setCameraFocalLength(params.cameraFocalLength);
|
||||
FilamentApp::get().setCameraNearFar(params.cameraNear, params.cameraFar);
|
||||
}
|
||||
|
||||
if (ImGui::CollapsingHeader("Indirect Light")) {
|
||||
|
||||
@@ -184,6 +184,9 @@ struct SandboxParameters {
|
||||
float cameraAperture = 16.0f;
|
||||
float cameraSpeed = 125.0f;
|
||||
float cameraISO = 100.0f;
|
||||
float cameraFocalLength = 28.0f;
|
||||
float cameraNear = 0.1f;
|
||||
float cameraFar = 100.0f;
|
||||
bool colorGrading = true;
|
||||
ColorGradingOptions colorGradingOptions;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user