Skip to content

Commit

Permalink
Add StandardSurface to replace StandardMaterial
Browse files Browse the repository at this point in the history
  • Loading branch information
dragly committed Mar 21, 2017
1 parent 21eb977 commit 6c736b6
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 56 deletions.
2 changes: 1 addition & 1 deletion examples/simple/main_simple.qml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ ApplicationWindow {
components: [
ShaderBuilderMaterial {
id: material
fragmentColor: StandardMaterial {
surface: StandardSurface {
color: "green"
normal: Bump {
texture: Noise {
Expand Down
1 change: 1 addition & 0 deletions src/imports/ShaderNodes/ShaderBuilderMaterial.qml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import QtQuick.Scene3D 2.0

Material {
id: root
property alias surface: shaderBuilderEffect.fragmentColor
property alias fragmentColor: shaderBuilderEffect.fragmentColor
property alias deferredColor: shaderBuilderEffect.deferredColor
property alias vertexPosition: shaderBuilderEffect.vertexPosition
Expand Down
59 changes: 4 additions & 55 deletions src/imports/ShaderNodes/StandardMaterial.qml
Original file line number Diff line number Diff line change
@@ -1,58 +1,7 @@
import QtQuick 2.5
import ShaderNodes 1.0
import QtQuick 2.0

ShaderNode {
property var color: "darkgrey"
property var attenuationOffset: 0.0
property var ambientColor: color
property var diffuseColor: color
property var specularColor: color
property var ambientIntensity: 1.0
property var diffuseIntensity: 1.0
property var specularIntensity: 1.0
property var hardness: 1.0

property var normal: ShaderBuilderBinding {
property: "normal"
defaultValue: Qt.vector3d(0.0, 0.0, 1.0)
}
property var position: ShaderBuilderBinding {
property: "position"
defaultValue: Qt.vector3d(0.0, 0.0, 0.0)
}

property var lights: [_defaultLight]

onLightsChanged: markDirty()

property Light _defaultLight: Light {
position: Qt.vector3d(46, 20, -10)
attenuation: 0.0
strength: 1.0
StandardSurface {
Component.onCompleted: {
console.warn("WARNING: StandardMaterial is deprecated. Please use StandardSurface.")
}

exportedTypeName: "StandardMaterial"

arrayProperties: ["lights"]

name: "diffuse"
type: "vec4"
source: {
var output = ""
output += "$this = vec4(0.0, 0.0, 0.0, 0.0);\n"
output += "$this.a = $(diffuseColor, vec4).a;\n"

for(var i in lights) {
output += "$this.xyz += standardMaterialLight($lights[" + i + "], $(normal, vec3), $(position, vec3), eyePosition,\n"
output += " $(ambientColor, vec3), $(diffuseColor, vec3), $(specularColor, vec3),\n"
output += " 0.01 * $(ambientIntensity, float), $(diffuseIntensity, float), 0.01 * $(specularIntensity, float),\n"
output += " 150.0 * $(hardness, float), $(attenuationOffset, float));\n"
}
return output
}

headerFiles: [
"qrc:/ShaderNodes/shaders/light.glsl",
"qrc:/ShaderNodes/shaders/standard_material.glsl"
]
}
58 changes: 58 additions & 0 deletions src/imports/ShaderNodes/StandardSurface.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import QtQuick 2.5
import ShaderNodes 1.0

ShaderNode {
property var color: "darkgrey"
property var attenuationOffset: 0.0
property var ambientColor: color
property var diffuseColor: color
property var specularColor: color
property var ambientIntensity: 1.0
property var diffuseIntensity: 1.0
property var specularIntensity: 1.0
property var hardness: 1.0

property var normal: ShaderBuilderBinding {
property: "normal"
defaultValue: Qt.vector3d(0.0, 0.0, 1.0)
}
property var position: ShaderBuilderBinding {
property: "position"
defaultValue: Qt.vector3d(0.0, 0.0, 0.0)
}

property var lights: [_defaultLight]

onLightsChanged: markDirty()

property Light _defaultLight: Light {
position: Qt.vector3d(46, 20, -10)
attenuation: 0.0
strength: 1.0
}

exportedTypeName: "StandardMaterial"

arrayProperties: ["lights"]

name: "diffuse"
type: "vec4"
source: {
var output = ""
output += "$this = vec4(0.0, 0.0, 0.0, 0.0);\n"
output += "$this.a = $(diffuseColor, vec4).a;\n"

for(var i in lights) {
output += "$this.xyz += standardMaterialLight($lights[" + i + "], $(normal, vec3), $(position, vec3), eyePosition,\n"
output += " $(ambientColor, vec3), $(diffuseColor, vec3), $(specularColor, vec3),\n"
output += " 0.01 * $(ambientIntensity, float), $(diffuseIntensity, float), 0.01 * $(specularIntensity, float),\n"
output += " 150.0 * $(hardness, float), $(attenuationOffset, float));\n"
}
return output
}

headerFiles: [
"qrc:/ShaderNodes/shaders/light.glsl",
"qrc:/ShaderNodes/shaders/standard_material.glsl"
]
}
1 change: 1 addition & 0 deletions src/imports/ShaderNodes/qmldir
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Split 1.0 Split.qml
ShaderBuilderMaterial 1.0 ShaderBuilderMaterial.qml
ShaderBuilderEffect 1.0 ShaderBuilderEffect.qml
StandardMaterial 1.0 StandardMaterial.qml
StandardSurface 1.0 StandardSurface.qml
Subtract 1.0 Subtract.qml
Sum 1.0 Sum.qml
UniformValue 1.0 UniformValue.qml
Expand Down
1 change: 1 addition & 0 deletions src/imports/shadernodes_imports.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,6 @@
<file>ShaderNodes/ShaderBuilderEffect.qml</file>
<file>ShaderNodes/CombineRgba.qml</file>
<file>ShaderNodes/CombineRgbVectorAlpha.qml</file>
<file>ShaderNodes/StandardSurface.qml</file>
</qresource>
</RCC>

0 comments on commit 6c736b6

Please sign in to comment.