当前位置: 首页 > news >正文

新鸿儒网站建设烟台网站建设求职简历

新鸿儒网站建设,烟台网站建设求职简历,广州深圳外贸公司,大埔县住房城乡规划建设局网站文章目录 介绍自定义shaderNodeMaterial骨骼材质特殊处理 介绍 Tri-panner 在babylonjs中有支持 但是three.js目前的基础材质并不支持 需要自己定义shader 或者使用目前还没有什么完善的文档的 NodeMaterial 下面展示两种实现方式 自定义shader /*** description: 替换三角面…

文章目录

        • 介绍
          • 自定义shader
          • NodeMaterial
          • 骨骼材质特殊处理

请添加图片描述

在这里插入图片描述

介绍

Tri-panner 在babylonjs中有支持 但是three.js目前的基础材质并不支持
需要自己定义shader 或者使用目前还没有什么完善的文档的 NodeMaterial

下面展示两种实现方式

自定义shader
/*** @description: 替换三角面贴图  https://doc.babylonjs.com/toolsAndResources/assetLibraries/materialsLibrary/triPlanarMat* @param {SingleMaterialMesh} mesh* @return {*}*/
export const useTriplanarMapping = (mesh: SingleMaterialMesh) => {const material = mesh.material.clone();mesh.material = material;material.map!.wrapS = THREE.RepeatWrapping;material.map!.wrapT = THREE.RepeatWrapping;material.onBeforeCompile = (shader) => {shader.vertexShader = shader.vertexShader.replace("#include <common>",`#include <common>varying vec3 tripPosition;varying vec3 tripNormal;`);shader.vertexShader = shader.vertexShader.replace("#include <fog_vertex>",`#include <fog_vertex>vec4 tripPosition4 = modelMatrix * vec4(position,1.) ;tripPosition = tripPosition4.xyz;tripNormal = normal * normalMatrix;vec3 world_space_normal = vec3(modelMatrix * vec4(normal, 0.0));tripNormal = normal;`);shader.fragmentShader = shader.fragmentShader.replace("#include <common>",`#include <common>varying vec3 tripPosition;varying vec3 tripNormal;vec3 blendNormal(vec3 normal){vec3 blending = abs( normal );blending = normalize(max(blending, 0.00001)); // Force weights to sum to 1.0 float b = (blending.x + blending.y + blending.z);blending /= vec3(b, b, b);return blending;}vec3 triplanarMapping (sampler2D tex, vec3 normal, vec3 position) {vec3 normalBlend = blendNormal(normal);vec3 xColor = texture(tex, position.yz).rgb;vec3 yColor = texture(tex, position.xz).rgb;vec3 zColor = texture(tex, position.xy).rgb;return (xColor * normalBlend.x + yColor * normalBlend.y + zColor * normalBlend.z);}`);shader.fragmentShader = shader.fragmentShader.replace("#include <map_fragment>",`#include <map_fragment>diffuseColor.rgb = vec3(triplanarMapping( map ,tripNormal,tripPosition));`);// shader.fragmentShader = shader.fragmentShader.replace(//     "#include <color_fragment>",//     `//     #include <color_fragment>//     diffuseColor.rgb = vec3(triplanar_mapping( map ,tripNormal,tripPosition,1.0));// `// );};
};
NodeMaterial

这是threejs新系统充满未来 目前还没有一个完善的文档 并且不太稳定 r132的时候支持这个材质 r138就被删除了 一些api也都有变化 可以先参考 https://raw.githack.com/sunag/three.js/dev-nodes-doc/docs/index.html#manual/en/introduction/How-to-use-node-material

import {MeshBasicNodeMaterial,texture,triplanarTexture,
} from "three/examples/jsm/nodes/Nodes.js";
import { nodeFrame } from "three/examples/jsm/renderers/webgl/nodes/WebGLNodes.js";const skyMat = new MeshBasicNodeMaterial();skyMat.colorNode = triplanarTexture(texture(this.helper.loadTexture("/public/textures/coral_stone_wall_diff_1k.jpg",(map) => {map.colorSpace = THREE.SRGBColorSpace;map.wrapS = THREE.RepeatWrapping;map.wrapT = THREE.RepeatWrapping;}))
);
skyMat.side = THREE.DoubleSide;const sky = new THREE.Mesh(new THREE.SphereGeometry(2, 32, 15), skyMat);
scene.add(sky);animation() {nodeFrame.update();
}

要注意每一次render 同时调用 nodeFrame.update(); 否则报错

骨骼材质特殊处理

这个问题需要根据three版本进行区别处理

r160版本 使用的是 position
r155版本使用的是 nodeUniform2 * vec4( 忘了叫什么了, 1.0 )
总之每个版本可能不一样 因为 节点系统正在开发 需要对应版本对应处理

r160版本写法如下

material.onBeforeCompile = (shader) => {material.vertexShader = shader.vertexShader.replace("#include <skinning_vertex>",`#include <skinning_vertex>nodeVarying2 = (modelMatrix * vec4(transformed,1.0)).xyz;`);
};

r155版本写法如下

material.onBeforeCompile = (shader) => {material.vertexShader = shader.vertexShader.replace("#include <skinning_vertex>",`#include <skinning_vertex>nodeVarying2 = ( nodeUniform2 * vec4( transformed, 1.0 ) );`);};
http://www.yayakq.cn/news/64971/

相关文章:

  • 静安做网站公司网站推广怎么样做
  • 重庆市做网站的公司九江网页设计公司
  • 网站空间管理站视觉设计主要学什么
  • erp网站建设网站 微信认证
  • 微信用大型网站站做跳板怎样开物流网站
  • 帮助中心网站模板网站备案 域名过期
  • 哪家网站建设公司专业济南网络公司工资排名
  • 超链接对做网站重要吗wamp环境下做网站
  • 做家教网站的资源是什么网站导航网站怎么做
  • 如何设计一个公司网站步骤百度游戏中心
  • asp网站开发参考文献齐齐哈尔做网站的公司
  • 铜仁市网站建设如何引流推广
  • 网站发语音功能如何做网站上的公告怎么做参考文献
  • jsp做网站都可以做什么wordpress文章排序插件
  • 安丘做网站的万网总裁张向东
  • 我做夫人那些年网站登录php网站只能打开首页
  • 织梦网站被植入广告网站空间域名多少钱
  • 辽宁网站建设哪里好找大连公共资源交易平台官网
  • 什么大型网站用python做的沈阳前端好找工作吗
  • 青白江网站建设保安公司
  • 米课中有个内贸网站建设杨浦网站建设 网站外包
  • wordpress怎么开启注册东莞seo网站优化
  • 广州冼村地铁站几号线西安百度竞价托管公司
  • 织梦网站怎么搬家网站正在备案中
  • 章丘做网站中国塑料商业网
  • 免费域名建站网站空间租用和自己搭建服务器
  • 房产中介做租单用哪个付费网站更好如何制作个人作品网页
  • 多种大连网站建设外贸都用什么网站
  • 网站建设的题目竞价网站做seo
  • 建设一个网站需要学习什么网站建设 模板