My problem is that after exporting a 3d model from Blender to json
with 3 uv sets and 3 different textures(diffuse map, normal map and light map) it looks like normal map is using the same uv set as diffuse map.
I've been wondering if it's possible that normalMap in THREE.MeshPhongMaterial can use separate UV set, just like LightMap? Or it only uses the same uv set as DiffuseMap?
With THREE.MeshPhongMaterial, all the maps share the primary UV set, with the exception of the lightMap and the aoMap, which share the 2nd set of UVs.
If you want different behavior, you will have to create a custom ShaderMaterial.
three.js r.71
Related
I have an instance using Drei library with a plane geometry.
According to a state, I would like to display different materials for each instance:
state is false: display a standard material with a simple color
state is true: apply a different texture (an image)
Each instance has its own state (for example 20% can be true and 80% can be false, or another ratio)
What would be the best way to do that?
Retained solution: Instanced Attributes
As mentionned by #Bhushan Wagh, the idea is to store the texture state inside a geometry attribute. Then, you can access this data in the shaders in order to apply a custom logic. You can follow his codesandbox for the R3F solution, or this one for the drei instance solution.
Investigated solutions
Having 2 distinct instances (one for the colored material, one for the image texture):
it's ok when we have only 2 states, but what if we have like 10 possible states? (What would be the best solution in this case?)
Represent a plane with a boxGeometry and display the proper face according to the state
It's also only working when we only have 2 states and are in 2D
I don't think you need to change the material if you just wanna toggle between plain color and texture. You can do this doing some changes in shader of material where you pass the vec4 to gl_fragColor in fragment shader based on the state, you can pass the state as attribute to the mesh, since you using instanced mes you can use the instancedAttribute. I had the codesandbox for solution for using different textures on each object of instanced mesh so I made a changes in that code to solve your problem ( or at least what I think is solution) https://codesandbox.io/s/toggle-texture-of-instanced-mesh-ptcvbb You can toggle state of each plane by clicking on it. and I think this should work even with more than 2 states, you can represent the states with number and based on number you can select particular texture from texture array passed as uniform.
Threejs export part of the Object3ds faces as image after teture has been added trough uv map.
I this even possible ?
EDIT:
I want to export part of my 3d object with texture applied so that i can print that part on sheet of paper
i've got a cinema4D created geometry/material with two different uv-sets/meshes for the material. normalmap & lightmap have a different uv set then the tileable color shading.
is there any possibility two pass two different uv sets? as far as i can see, the faceVertexUVs is an array itself, but what would the shader look like?
thanks for an answer!
I am using a custom shader which creates a sort of environment map effect by referencing from a texture based on the vector normals and the result is a perfect reflection.
I would now like to be able to add color and specular highlights so that the material is not always 100% reflective. Is there any way to do this without reinventing the wheel and creating a new phong shader from scratch?
If I can set the color or allow lighting, how would I then "mix" it with the texture based output? In Three.js there are lots of mixing methods and it would be nice if I could reuse those too so that I can test each method.
Update:
Found something very similar, just looking for a way to use color, ambient & emissive properties.
Using
var phongShader = THREE.ShaderLib.phong;
var uniforms = THREE.UniformsUtils.clone(phongShader.uniforms);
http://jsfiddle.net/edgxtnmv/1/
I want to load a 3D model with a diffuse texture and a normal map using the asset loader of libgdx.
As far as I figured out the fbx (and the converted g3dj/g3db) format can contain a diffuse texture, as I could see in the fbx-conv example. (knight.g3db)
How do I add a normal map texture to it?
Do I have to write my own shader for that or is there a simplified method for that? (like for the diffuse texture)
Normal map is supported from FBX all the way up to the DefaultShader class. So if your model (FBX file) contains a normal map, it should be available in your shader. However the default shader (GLSL files) don't support normal map. So you'll have to write your own shader. The tests contain some examples on normal mapping (ShaderCollectionTest) although it might be a bit hard to read.
The uniform name is u_normalTexture, and set here: https://github.com/libgdx/libgdx/blob/master/gdx/src/com/badlogic/gdx/graphics/g3d/shaders/DefaultShader.java#L228