Add Java / WebGL bindings for screen-space reflections (#5054)
This commit is contained in:
@@ -390,6 +390,16 @@ Java_com_google_android_filament_View_nSetTemporalAntiAliasingOptions(JNIEnv *,
|
||||
.filterWidth = filterWidth, .feedback = feedback, .enabled = (bool) enabled});
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_google_android_filament_View_nSetScreenSpaceReflectionsOptions(JNIEnv*, jclass,
|
||||
jlong nativeView, jfloat thickness, jfloat bias, jfloat maxDistance, jfloat stride, jboolean enabled) {
|
||||
View* view = (View*) nativeView;
|
||||
view->setScreenSpaceReflectionsOptions({.thickness = thickness, .bias = bias,
|
||||
.maxDistance = maxDistance, .stride = stride, .enabled = (bool) enabled
|
||||
});
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_google_android_filament_View_nIsShadowingEnabled(JNIEnv *, jclass, jlong nativeView) {
|
||||
|
||||
@@ -79,6 +79,7 @@ public class View {
|
||||
private VignetteOptions mVignetteOptions;
|
||||
private ColorGrading mColorGrading;
|
||||
private TemporalAntiAliasingOptions mTemporalAntiAliasingOptions;
|
||||
private ScreenSpaceReflectionsOptions mScreenSpaceReflectionsOptions;
|
||||
private MultiSampleAntiAliasingOptions mMultiSampleAntiAliasingOptions;
|
||||
private VsmShadowOptions mVsmShadowOptions;
|
||||
private SoftShadowOptions mSoftShadowOptions;
|
||||
@@ -335,6 +336,28 @@ public class View {
|
||||
public boolean enabled = false;
|
||||
};
|
||||
|
||||
/**
|
||||
* Options for Screen-space Reflections.
|
||||
* @see View#setScreenSpaceReflectionOptions
|
||||
*/
|
||||
public static class ScreenSpaceReflectionsOptions {
|
||||
/** ray thickness, in world units */
|
||||
public float thickness = 0.5f;
|
||||
|
||||
/** bias, in world units, to prevent self-intersections */
|
||||
public float bias = 0.01f;
|
||||
|
||||
/** maximum distance, in world units, to raycast */
|
||||
public float maxDistance = 3.0f;
|
||||
|
||||
/** stride, in texels, for samples along the ray. */
|
||||
public float stride = 1.0f;
|
||||
|
||||
/** enables or disables screen-space reflections */
|
||||
public boolean enabled = false;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Options for controlling the Bloom effect
|
||||
*
|
||||
@@ -1185,6 +1208,17 @@ public class View {
|
||||
options.feedback, options.filterWidth, options.enabled);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables or disable screen-space reflections. Disabled by default.
|
||||
*
|
||||
* @param options screen-space reflections options
|
||||
*/
|
||||
public void setScreenSpaceReflectionsOptions(@NonNull ScreenSpaceReflectionsOptions options) {
|
||||
mScreenSpaceReflectionsOptions = options;
|
||||
nSetScreenSpaceReflectionsOptions(getNativeObject(), options.thickness, options.bias,
|
||||
options.maxDistance, options.stride, options.enabled);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns temporal anti-aliasing options.
|
||||
*
|
||||
@@ -1198,6 +1232,19 @@ public class View {
|
||||
return mTemporalAntiAliasingOptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns screen-space reflections options.
|
||||
*
|
||||
* @return screen-space reflections options
|
||||
*/
|
||||
@NonNull
|
||||
public ScreenSpaceReflectionsOptions getScreenSpaceReflectionsOptions() {
|
||||
if (mScreenSpaceReflectionsOptions == null) {
|
||||
mScreenSpaceReflectionsOptions = new ScreenSpaceReflectionsOptions();
|
||||
}
|
||||
return mScreenSpaceReflectionsOptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables or disables tone-mapping in the post-processing stage. Enabled by default.
|
||||
*
|
||||
@@ -1782,6 +1829,7 @@ public class View {
|
||||
boolean nativeResolution, int foregroundRingCount, int backgroundRingCount, int fastGatherRingCount, int maxForegroundCOC, int maxBackgroundCOC);
|
||||
private static native void nSetVignetteOptions(long nativeView, float midPoint, float roundness, float feather, float r, float g, float b, float a, boolean enabled);
|
||||
private static native void nSetTemporalAntiAliasingOptions(long nativeView, float feedback, float filterWidth, boolean enabled);
|
||||
private static native void nSetScreenSpaceReflectionsOptions(long nativeView, float thickness, float bias, float maxDistance, float stride, boolean enabled);
|
||||
private static native void nSetMultiSampleAntiAliasingOptions(long nativeView, boolean enabled, int sampleCount, boolean customResolve);
|
||||
private static native boolean nIsShadowingEnabled(long nativeView);
|
||||
private static native void nSetScreenSpaceRefractionEnabled(long nativeView, boolean enabled);
|
||||
|
||||
@@ -480,6 +480,8 @@ static int parse(jsmntok_t const* tokens, int i, const char* jsonChunk,
|
||||
i = parse(tokens, i + 1, jsonChunk, &out->bias);
|
||||
} else if (compare(tok, jsonChunk, "maxDistance") == 0) {
|
||||
i = parse(tokens, i + 1, jsonChunk, &out->maxDistance);
|
||||
} else if (compare(tok, jsonChunk, "stride") == 0) {
|
||||
i = parse(tokens, i + 1, jsonChunk, &out->stride);
|
||||
} else {
|
||||
slog.w << "Invalid screen-space reflections key: '" << STR(tok, jsonChunk) << "'" << io::endl;
|
||||
i = parse(tokens, i + 1);
|
||||
@@ -1351,6 +1353,7 @@ static std::ostream& operator<<(std::ostream& out, const ScreenSpaceReflectionsO
|
||||
<< "\"thickness\": " << in.thickness << ",\n"
|
||||
<< "\"bias\": " << in.bias << ",\n"
|
||||
<< "\"maxDistance\": " << in.maxDistance << ",\n"
|
||||
<< "\"stride\": " << in.stride << "\n"
|
||||
<< "}";
|
||||
}
|
||||
|
||||
|
||||
@@ -294,6 +294,21 @@ Filament.loadClassExtensions = function() {
|
||||
this._setTemporalAntiAliasingOptions(options);
|
||||
};
|
||||
|
||||
/// setScreenSpaceReflectionsOptions ::method::
|
||||
/// overrides ::argument:: Dictionary with one or more of the following properties: \
|
||||
/// thickness, bias, maxDistance, stride, enabled.
|
||||
Filament.View.prototype.setScreenSpaceReflectionsOptions = function(overrides) {
|
||||
const options = {
|
||||
thickness: 0.5,
|
||||
bias: 0.01,
|
||||
maxDistance: 3.0,
|
||||
stride: 1.0,
|
||||
enabled: false
|
||||
};
|
||||
Object.assign(options, overrides);
|
||||
this._setScreenSpaceReflectionsOptions(options);
|
||||
};
|
||||
|
||||
/// setBloomOptions ::method::
|
||||
/// overrides ::argument:: Dictionary with one or more of the following properties: \
|
||||
/// enabled, strength, resolution, anomorphism, levels, blendMode, threshold, highlight.
|
||||
|
||||
11
web/filament-js/filament.d.ts
vendored
11
web/filament-js/filament.d.ts
vendored
@@ -123,6 +123,14 @@ export interface View$BloomOptions {
|
||||
// TODO: add support for dirt texture in BloomOptions.
|
||||
}
|
||||
|
||||
export interface View$ScreenSpaceReflectionsOptions {
|
||||
thickness?: number;
|
||||
bias?: number;
|
||||
maxDistance?: number;
|
||||
stride?: number;
|
||||
enabled?: boolean;
|
||||
}
|
||||
|
||||
export interface View$FogOptions {
|
||||
distance?: number;
|
||||
maximumOpacity?: number;
|
||||
@@ -521,6 +529,7 @@ export class View {
|
||||
public setAmbientOcclusionOptions(options: View$AmbientOcclusionOptions): void;
|
||||
public setDepthOfFieldOptions(options: View$DepthOfFieldOptions): void;
|
||||
public setBloomOptions(options: View$BloomOptions): void;
|
||||
public setScreenSpaceReflectionsOptions(options: View$ScreenSpaceReflectionsOptions): void;
|
||||
public setFogOptions(options: View$FogOptions): void;
|
||||
public setVignetteOptions(options: View$VignetteOptions): void;
|
||||
public setAmbientOcclusion(ambientOcclusion: View$AmbientOcclusion): void;
|
||||
@@ -589,7 +598,7 @@ export class Engine {
|
||||
public getSupportedFormatSuffix(suffix: string): void;
|
||||
public getTransformManager(): TransformManager;
|
||||
public init(assets: string[], onready: () => void): void;
|
||||
public loadFilamesh(urlOrBuffer: BufferReference, definstance: MaterialInstance, matinstances: object): Filamesh;
|
||||
public loadFilamesh(urlOrBuffer: BufferReference, definstance?: MaterialInstance, matinstances?: object): Filamesh;
|
||||
}
|
||||
|
||||
export class gltfio$AssetLoader {
|
||||
|
||||
@@ -395,6 +395,13 @@ value_object<filament::View::TemporalAntiAliasingOptions>("View$TemporalAntiAlia
|
||||
.field("filterWidth", &filament::View::TemporalAntiAliasingOptions::filterWidth)
|
||||
.field("feedback", &filament::View::TemporalAntiAliasingOptions::feedback);
|
||||
|
||||
value_object<filament::View::ScreenSpaceReflectionsOptions>("View$ScreenSpaceReflectionsOptions")
|
||||
.field("thickness", &filament::View::ScreenSpaceReflectionsOptions::thickness)
|
||||
.field("bias", &filament::View::ScreenSpaceReflectionsOptions::bias)
|
||||
.field("maxDistance", &filament::View::ScreenSpaceReflectionsOptions::maxDistance)
|
||||
.field("stride", &filament::View::ScreenSpaceReflectionsOptions::stride)
|
||||
.field("enabled", &filament::View::ScreenSpaceReflectionsOptions::enabled);
|
||||
|
||||
value_object<filament::View::BloomOptions>("View$BloomOptions")
|
||||
.field("dirtStrength", &filament::View::BloomOptions::dirtStrength)
|
||||
.field("strength", &filament::View::BloomOptions::strength)
|
||||
@@ -693,6 +700,7 @@ class_<View>("View")
|
||||
.function("_setDepthOfFieldOptions", &View::setDepthOfFieldOptions)
|
||||
.function("_setMultiSampleAntiAliasingOptions", &View::setMultiSampleAntiAliasingOptions)
|
||||
.function("_setTemporalAntiAliasingOptions", &View::setTemporalAntiAliasingOptions)
|
||||
.function("_setScreenSpaceReflectionsOptions", &View::setScreenSpaceReflectionsOptions)
|
||||
.function("_setBloomOptions", &View::setBloomOptions)
|
||||
.function("_setFogOptions", &View::setFogOptions)
|
||||
.function("_setVignetteOptions", &View::setVignetteOptions)
|
||||
|
||||
@@ -253,7 +253,8 @@ Filament._createIblFromKtx = function(ktxdata, engine, options) {
|
||||
const iblktx = options['ktx'] = new Filament.KtxBundle(ktxdata);
|
||||
|
||||
const format = iblktx.info().glInternalFormat;
|
||||
if (format != this.ctx.R11F_G11F_B10F && format != this.ctx.RGB16F && format != this.ctx.RGB32F) {
|
||||
//if (format != this.ctx.R11F_G11F_B10F && format != this.ctx.RGB16F && format != this.ctx.RGB32F) {
|
||||
if (format != 35898 && format != 33327 && format != 34837) {
|
||||
console.warn('IBL texture format is 0x' + format.toString(16) +
|
||||
' which is not an expected floating-point format. Please use cmgen to generate IBL.');
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ Filament.init = (assets, onready) => {
|
||||
// resolves to a module. Here we replace the function with the module. Note that our
|
||||
// TypeScript bindings assume that Filament is a namespace, not a function.
|
||||
Filament().then(module => {
|
||||
Filament = Object.assign(module, Filament);
|
||||
Filament = Object.assign(Filament, module);
|
||||
|
||||
// At this point, emscripten has finished compiling and instancing the WebAssembly module.
|
||||
// The JS classes that correspond to core Filament classes (e.g., Engine) are not guaranteed
|
||||
|
||||
Reference in New Issue
Block a user