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

Custom three.js shader material #4

Merged
merged 30 commits into from
Jun 28, 2017
Merged

Custom three.js shader material #4

merged 30 commits into from
Jun 28, 2017

Conversation

Aadjou
Copy link
Contributor

@Aadjou Aadjou commented Jun 21, 2017

See issue #3

  • I took the shader & shader includes directly from three.js and created our own base-shaderMaterial based on their MeshPhong Material:
    MeshPhong Fragment
    MeshPhong Vertex

  • I stripped it from includes that we currently are not using, eg. skinning, shadowmaps etc.
    we can add any of these easily if it turns out that we need them.

  • finally I added the lightmap controls (based on the editor) in the fragment shader.

looking forward to your review on this pull request

@Aadjou Aadjou requested review from tomas-polach and AVGP June 21, 2017 14:44
Copy link
Contributor

@AVGP AVGP left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-- removed --

@@ -88,7 +89,8 @@ View.prototype = {
// three.js materials
if (!self._materials3d[ meshId ]) {
// (one material pro mesh, because some of our mesh properties are material properties and it does not matter performance wise)
material3d = new THREE.MeshPhongMaterial({ opacity: 0.5, transparent: true })
//material3d = new THREE.MeshPhongMaterial({ opacity: 0.5, transparent: true})
material3d = BaseMaterial()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a problem, but I think we should restructure it later to be a proper constructor. Depending on how it'll evolve we might even be able to inherit a bunch of stuff from MeshPhongMaterial

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to get your help with this. @AVGP

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4cc39cb \o/

.apdisk
node_modules
build
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tomas-polach the build folder can be added to .gitignore right?


<a-entity light="type: point; intensity: 0.75; distance: 50; decay: 2" position="-3.2 -2.2 -4.5"></a-entity>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the light in the example here is there to replace the standard light, right?

How are we going to deal with people who have only the default light in the scene?

Copy link
Contributor Author

@Aadjou Aadjou Jun 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tomas-polach wants to build a a-frame component for an archilogic light scene.

the problem with the lights is that if there is no light present, any object with no lightmap (eg. all products) are not illuminated at all and therefore appear black.
if you add a three.js light, you can illuminate the scene (which is a pretty cool feature IMHO that comes for free) but the lightmapped objects will react much stronger to it.
It would be an option to use the lightMapIntensity parameter for a base illumination factor. (i tested that before and the results were good)


// specular coefficient

material3d.shininess = _attributes.specularCoef !== undefined ? _attributes.specularCoef : 0.1
material3d.shininess = (_attributes.specularCoef !== undefined) ? (_attributes.specularCoef / 100) : 0.1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if it's "shininess" or "specular" that's the problem but the sink isn't particularly shiny :(

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay so it turns out that three.js is super inconsistent and "shininess" is one of the rare parameters that goes from 0 to 100 and instead of using a unit float. My bad.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and thanks for the catch.


if (_attributes.colorEmissive) {
if (_attributes.colorEmissive && material3d.emissive) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we reformat this to match diffuse and specular?
Also: Where is the corresponding uniform being set?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

f71d1b0

the emission color is not yet implemented in the shader, because we currently do not support that in the editor. I could however implement it, if that is something we want to support.

@@ -117,9 +121,12 @@ export default function setMaterial (args) {
// lightmap settings
if (_attributes.mapLight || _attributes.mapLightPreview) {
material3d.enhancedLightMap = material3d.enhancedLightMap || {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need the enhancedLightMap property? It was used in the editor as a switch to enable our lightmap shader...

Copy link
Contributor Author

@Aadjou Aadjou Jun 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i removed enhancedLightMap because we don't need it anymore

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commit:
487a76a

@@ -267,6 +267,7 @@ export default function loadTextures ( queue, TEXTURE_TYPES, vm, _attributes, ma
}
// add new texture
material3d[ texture3dKeys[ i ] ] = textures[ i ]
material3d.uniforms[ texture3dKeys[ i ] ].value = textures[ i ]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume this sets .lightMap?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also specularMap, normalMap, alphaMap und map


vec3 totalEmissiveRadiance = emissive;

#include <logdepthbuf_fragment>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is logdepthbuf_pars_fragment missing in the includes previously?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Considering the comment of Stavros, we say nay to logdepthbuffer for now
a54d300

IMHO there's no need for a logarithmic depth buffer in our context (interior scenes). It usually helps when you're doing very large-scale stuff, such as terrain rendering.

RE_IndirectDiffuse( irradiance, geometry, material, reflectedLight );

#endif

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mark end-of-replaced-block here, please

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lightMapCenter: { value: 0.5 },
normalMap: { value: null },
shininess: { value: 1.0 },
specular: { value: new THREE.Color(0.0, 0.0, 0.0) },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this meant to be black by default?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point. I will consider this together with the general specularity issue.


#include <uv_pars_vertex>
#include <uv2_pars_vertex>

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logdepthbuffer yea/nay?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nay.


#include <begin_vertex>
#include <project_vertex>

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logdepthbuffer yea/nay?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO there's no need for a logarithmic depth buffer in our context (interior scenes). It usually helps when you're doing very large-scale stuff, such as terrain rendering.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @stavros-papadopoulos. i will remove the one include then that accidentally is there

@AVGP
Copy link
Contributor

AVGP commented Jun 27, 2017 via email

Copy link
Contributor

@AVGP AVGP left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me

emissive.g = _attributes.colorEmissive[ 1 ]
emissive.b = _attributes.colorEmissive[ 2 ]
} else if (_attributes.lightEmissionCoef) {
var emissiveIntensity = _attributes.lightEmissionCoef / 10
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this is reasonable but I'd welcome a small comment explaining why we're dividing by 10

@AVGP AVGP merged commit 02a306f into master Jun 28, 2017
@Aadjou Aadjou deleted the custom-three-material branch June 30, 2017 15:48
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants