Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Q
Quick3d Dynamic Texture Input
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Yuya Nishihara
Quick3d Dynamic Texture Input
Commits
5f8e3276
Commit
5f8e3276
authored
3 years ago
by
Yuya Nishihara
Browse files
Options
Downloads
Patches
Plain Diff
implement weird hack to capture View3D output as texture
parent
f3828a5b
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
main.qml
+173
-36
173 additions, 36 deletions
main.qml
with
173 additions
and
36 deletions
main.qml
+
173
−
36
View file @
5f8e3276
...
@@ -13,55 +13,192 @@ Window {
...
@@ -13,55 +13,192 @@ Window {
visible
:
true
visible
:
true
title
:
qsTr
(
"
Hello World
"
)
title
:
qsTr
(
"
Hello World
"
)
View3D
{
RowLayout
{
anchors.fill
:
parent
anchors.fill
:
parent
OrthographicCamera
{
View3D
{
position
:
Qt
.
vector3d
(
0
,
0
,
100
)
id
:
mainView
}
Layout.fillWidth
:
true
Layout.fillHeight
:
true
DirectionalLight
{
OrthographicCamera
{
position
:
Qt
.
vector3d
(
0
,
0
,
100
)
position
:
Qt
.
vector3d
(
0
,
0
,
100
)
brightness
:
100
}
}
Model
{
Model
{
position
:
Qt
.
vector3d
(
0
,
0
,
0
)
position
:
Qt
.
vector3d
(
vxSpinBox
.
value
,
vySpinBox
.
value
,
-
1
)
source
:
"
#Rectangle
"
scale
:
Qt
.
vector3d
(
5
,
5
,
1
)
materials
:
myTextureMaterial
source
:
"
#Rectangle
"
materials
:
DefaultMaterial
{
diffuseColor
:
"
gray
"
lighting
:
DefaultMaterial
.
NoLighting
}
}
Model
{
position
:
Qt
.
vector3d
(
vxSpinBox
.
value
,
vySpinBox
.
value
,
0
)
scale
:
Qt
.
vector3d
(
5
,
5
,
1
)
source
:
"
#Rectangle
"
materials
:
CustomMaterial
{
readonly
property
TextureInput
myTexture
:
TextureInput
{
texture
:
Texture
{
// As of Qt 5.15.2, TextureInput doesn't upload texture
// unless source URL is set. So this TextureInput does
// effectively nothing in redering path. Instead, we do
// capture the intermediate output by Buffer and feed
// it via BufferInput.
//
// However, we still need this TextureInput to describe
// dependency on the textureView item. ShaderEffectSource
// is a workaround for QTBUG-93097.
//
// See also QSSGMaterialSystem::doApplyInstanceValue().
sourceItem
:
ShaderEffectSource
{
width
:
textureView
.
width
height
:
textureView
.
height
sourceItem
:
textureView
}
}
}
hasTransparency
:
true
shaderInfo
:
ShaderInfo
{
version
:
"
330
"
type
:
"
GLSL
"
}
passes
:
[
Pass
{
commands
:
[
// See the comment above for why.
BufferInput
{
buffer
:
textureBuffer
;
param
:
"
myTexture
"
}
]
shaders
:
[
myFragShader
]
}
]
Shader
{
id
:
myFragShader
stage
:
Shader
.
Fragment
shader
:
"
out vec4 fragColor;
uniform float objectOpacity;
void main() {
fragColor = texture2D(myTexture, varTexCoord0.xy) * objectOpacity;
}
"
}
}
}
}
}
}
CustomMaterial
{
Pane
{
id
:
myTextureMaterial
Layout.fillHeight
:
true
palette.window
:
"
#eee
"
GridLayout
{
columns
:
2
Label
{
text
:
"
vx
"
}
SpinBox
{
id
:
vxSpinBox
from
:
-
1000
to
:
1000
stepSize
:
10
editable
:
true
}
Label
{
text
:
"
vy
"
}
SpinBox
{
id
:
vySpinBox
from
:
-
1000
to
:
1000
stepSize
:
10
editable
:
true
}
Label
{
text
:
"
tx
"
}
SpinBox
{
id
:
txSpinBox
from
:
-
150
to
:
150
stepSize
:
10
editable
:
true
}
readonly
property
TextureInput
myTexture
:
TextureInput
{
Label
{
text
:
"
ty
"
}
texture
:
Texture
{
SpinBox
{
source
:
"
assets/quick-fox-grayscale.png
"
id
:
tySpinBox
from
:
-
150
to
:
150
stepSize
:
10
editable
:
true
}
}
}
}
}
}
Label
{
text
:
"
Red rectangle is rendered separately in hidden View3D.
"
}
View3D
{
id
:
textureView
// Size of this view must be identical to the main view. Otherwise
// the shared Buffer {} wouldn't work.
width
:
mainView
.
width
height
:
mainView
.
height
visible
:
false
shaderInfo
:
ShaderInfo
{
OrthographicCamera
{
version
:
"
330
"
position
:
Qt
.
vector3d
(
0
,
0
,
0.5
)
type
:
"
GLSL
"
scale
:
Qt
.
vector3d
(
200
/
textureView
.
width
,
200
/
textureView
.
height
,
1
)
clipNear
:
0
clipFar
:
1
}
}
passes
:
[
Model
{
Pass
{
position
:
Qt
.
vector3d
(
txSpinBox
.
value
,
tySpinBox
.
value
,
0
)
shaders
:
[
myFragShader
]
source
:
"
#Rectangle
"
}
materials
:
CustomMaterial
{
]
shaderInfo
:
ShaderInfo
{
version
:
"
330
"
Shader
{
type
:
"
GLSL
"
id
:
myFragShader
}
stage
:
Shader
.
Fragment
shader
:
"
passes
:
[
out vec4 fragColor;
Pass
{
uniform float objectOpacity;
shaders
:
[
fillColorFragShader
]
void main() {
output
:
textureBuffer
fragColor = texture2D(myTexture, varTexCoord0.xy) * objectOpacity;
}
]
// Captures the output so that it can be fed to a Material
// in the main scene.
Buffer
{
id
:
textureBuffer
name
:
"
textureBuffer
"
format
:
Buffer
.
Unknown
textureCoordOperation
:
Buffer
.
ClampToEdge
textureFilterOperation
:
Buffer
.
Linear
// Since this buffer is referred by the main view, we can't
// control the lifetime. Let it be alive forever.
bufferFlags
:
Buffer
.
SceneLifetime
}
}
"
Shader
{
id
:
fillColorFragShader
stage
:
Shader
.
Fragment
shader
:
"
out vec4 fragColor;
uniform float objectOpacity;
void main() {
fragColor = vec4(1, 0, 0, 1) * objectOpacity;
}
"
}
}
}
}
}
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment