Skip to content
This repository has been archived by the owner on Jul 28, 2020. It is now read-only.

Commit

Permalink
Update Sceneform to Filament 1.7.0 and include source files. (#1088)
Browse files Browse the repository at this point in the history
* Update to Filament 1.7.0 and include material sources

* Remove dependency on view renderable sfb, add source exr for lighting.
  • Loading branch information
tpsiaki authored Jun 9, 2020
1 parent ad78676 commit 1548ff3
Show file tree
Hide file tree
Showing 25 changed files with 435 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,13 @@
import com.google.ar.core.HitResult;
import com.google.ar.core.Plane;
import com.google.ar.sceneform.AnchorNode;
import com.google.ar.sceneform.Node;
import com.google.ar.sceneform.math.Vector3;
import com.google.ar.sceneform.rendering.Color;
import com.google.ar.sceneform.rendering.Material;
import com.google.ar.sceneform.rendering.ModelRenderable;
import com.google.ar.sceneform.rendering.Renderable;
import com.google.ar.sceneform.rendering.ViewRenderable;
import com.google.ar.sceneform.ux.ArFragment;
import com.google.ar.sceneform.ux.TransformableNode;
import java.lang.ref.WeakReference;
Expand Down Expand Up @@ -152,6 +155,24 @@ protected void onCreate(Bundle savedInstanceState) {
Material material = renderable.getMaterial(i);
material.setFloat4("baseColorFactor", color);
}

Node tigerTitleNode = new Node();
tigerTitleNode.setParent(model);
tigerTitleNode.setEnabled(false);
tigerTitleNode.setLocalPosition(new Vector3(0.0f, 1.0f, 0.0f));
ViewRenderable.builder()
.setView(this, R.layout.tiger_card_view)
.build()
.thenAccept(
(renderable) -> {
tigerTitleNode.setRenderable(renderable);
tigerTitleNode.setEnabled(true);
})
.exceptionally(
(throwable) -> {
throw new AssertionError("Could not load card view.", throwable);
}
);
});

arFragment
Expand Down
21 changes: 21 additions & 0 deletions samples/gltf/app/src/main/res/drawable/rounded_bg.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2018 Google LLC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#E61976d2"/>
<corners android:radius="5dp"/>
</shape>

10 changes: 10 additions & 0 deletions samples/gltf/app/src/main/res/layout/tiger_card_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/rounded_bg"
android:gravity="center"
android:orientation="vertical"
android:padding="6dp"
android:text="Tiger"
android:textAlignment="center" />
4 changes: 2 additions & 2 deletions sceneformsrc/sceneform/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ android {
}

dependencies {
api 'com.google.android.filament:filament-android:1.4.5'
api 'com.google.android.filament:gltfio-android:1.4.5'
api 'com.google.android.filament:filament-android:1.7.0'
api 'com.google.android.filament:gltfio-android:1.7.0'
implementation files("../libs/libsceneform_runtime_schemas.jar")

api "com.google.ar:core:1.16.0"
Expand Down
25 changes: 25 additions & 0 deletions sceneformsrc/sceneform/sampleData/sceneform_camera_material.mat
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
material {
"name" : "Camera",

"parameters" : [
{
"type" : "samplerExternal",
"name" : "cameraTexture"
}
],
"requires" : [
"uv0"
],
"vertexDomain" : "device",
"depthWrite" : false,
"shadingModel" : "unlit",
"doubleSided" : true
}
fragment {
void material(inout MaterialInputs material) {
prepareMaterial(material);

vec4 color = texture(materialParams_cameraTexture, getUV0());
material.baseColor.rgb = inverseTonemapSRGB(color.rgb);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
material {
"name" : "Opaque Colored",

"parameters" : [
{
"type" : "float3",
"name" : "color"
},
{
"type" : "float",
"name" : "metallic"
},
{
"type" : "float",
"name" : "roughness"
},
{
"type" : "float",
"name" : "reflectance"
}
],
"requires" : [
"position",
"uv0"
],
"shadingModel" : "lit",
"blending" : "opaque"
}
fragment {
void material(inout MaterialInputs material) {
prepareMaterial(material);
material.baseColor.rgb = materialParams.color;
material.metallic = materialParams.metallic;
material.roughness = materialParams.roughness;
material.reflectance = materialParams.reflectance;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
material {
"name" : "Opaque Textured",

"parameters" : [
{
"type" : "sampler2d",
"name" : "texture"
},
{
"type" : "float",
"name" : "metallic"
},
{
"type" : "float",
"name" : "roughness"
},
{
"type" : "float",
"name" : "reflectance"
}
],
"requires" : [
"position",
"uv0"
],
"shadingModel" : "lit",
"blending" : "opaque"
}
fragment {
void material(inout MaterialInputs material) {
prepareMaterial(material);
material.baseColor = texture(materialParams_texture, getUV0());
material.metallic = materialParams.metallic;
material.roughness = materialParams.roughness;
material.reflectance = materialParams.reflectance;
}
}
74 changes: 74 additions & 0 deletions sceneformsrc/sceneform/sampleData/sceneform_plane_material.mat
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
material {
name : "AR Core Plane Material",

"parameters": [
{
"type": "sampler2d",
"name": "texture"
},
{
"type": "float3",
"name": "color"
},
{
"type": "float2",
"name": "uvScale"
},
{
"type": "float3",
"name": "focusPoint"
},
{
"type": "float",
"name": "radius"
}
],
"variables" : [
"texCoordsAlpha",
"smoothWorldPosition"
],
"requires" : [
"position"
],
shadingModel : unlit,
"blending": "transparent"
}

vertex {
void materialVertex(inout MaterialVertexInputs material) {
float3 pos = getPosition().xyz;

// The Y position of the vertex represents the Alpha of the plane at this Vertex.
material.texCoordsAlpha.z = pos.y;

// Zero out the Y vertex and compute the world position.
pos.y = 0.0;
material.worldPosition = mulMat4x4Float3(getWorldFromModelMatrix(), pos);
material.smoothWorldPosition = material.worldPosition;

// Compute the texture coordinates.
// The X axis of the texture corresponds to the local X axis of the plane.
// The Y axis of the texture corresponds to the local Z axis of the plane.
// Scale the texture coordinates by the scale parameter passed into the material.
material.texCoordsAlpha.x = pos.x * materialParams.uvScale.x;
material.texCoordsAlpha.y = pos.z * materialParams.uvScale.y;
}
}

fragment {
void material(inout MaterialInputs material) {
prepareMaterial(material);

material.baseColor = texture(materialParams_texture, variable_texCoordsAlpha.xy);
material.baseColor.rgb *= materialParams.color;
float textureAlpha = material.baseColor.a;

// Create a spotlight effect around the focus point.
float distToFocus = distance(variable_smoothWorldPosition.xyz, materialParams.focusPoint);
float alpha = smoothstep(materialParams.radius, materialParams.radius * .5f, distToFocus);

// Transparent blending uses pre-multiplied alpha,
// so multiply the entire baseColor by the alpha for this fragment.
material.baseColor *= variable_texCoordsAlpha.z * alpha;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
material {
name : "AR Core Plane Shadow Material",
shadingModel : unlit,
blending : transparent,
shadowMultiplier : true
}

vertex {
void materialVertex(inout MaterialVertexInputs material) {
float3 pos = getPosition().xyz;

// Shift the verticies upwards so we don't z-fight with the plane material.
pos.y = 0.005f;
material.worldPosition = mulMat4x4Float3(getWorldFromModelMatrix(), pos);
}
}

fragment {
void material(inout MaterialInputs material) {
prepareMaterial(material);

material.baseColor = float4(0.0f, 0.0f, 0.0f, .6f);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
material {
"name" : "Transparent Colored",

"parameters" : [
{
"type" : "float4",
"name" : "color"
},
{
"type" : "float",
"name" : "metallic"
},
{
"type" : "float",
"name" : "roughness"
},
{
"type" : "float",
"name" : "reflectance"
}
],
"requires" : [
"position",
"uv0"
],
"shadingModel" : "lit",
"blending" : "transparent"
}
fragment {
void material(inout MaterialInputs material) {
prepareMaterial(material);
material.baseColor = materialParams.color;
material.metallic = materialParams.metallic;
material.roughness = materialParams.roughness;
material.reflectance = materialParams.reflectance;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
material {
"name" : "Transparent Textured",

"parameters" : [
{
"type" : "sampler2d",
"name" : "texture"
},
{
"type" : "float",
"name" : "metallic"
},
{
"type" : "float",
"name" : "roughness"
},
{
"type" : "float",
"name" : "reflectance"
}
],
"requires" : [
"position",
"uv0"
],
"shadingModel" : "lit",
"blending" : "transparent"
}
fragment {
void material(inout MaterialInputs material) {
prepareMaterial(material);
material.baseColor = texture(materialParams_texture, getUV0());
material.metallic = materialParams.metallic;
material.roughness = materialParams.roughness;
material.reflectance = materialParams.reflectance;
}
}
Loading

0 comments on commit 1548ff3

Please sign in to comment.