three.js使用ShaderMaterial实现聚光灯光源demo

news2024/11/29 0:55:20

文章目录

          • 顶点
          • 片元
          • 全部

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

核心:

顶点
varying vec3 vNormal;

varying vec3 vViewPosition;

void main() {

    vNormal = normalMatrix * normal;
    vNormal = normalize( vNormal );

    vec4 modelViewPosition = modelViewMatrix * vec4(position, 1.0);
    gl_Position = projectionMatrix * modelViewPosition;

    vec3 transformed = vec3( position );

    vec4 mvPosition = vec4( transformed, 1.0 );
    
    mvPosition = modelViewMatrix * mvPosition;

 vViewPosition = - mvPosition.xyz;

}
片元
 varying vec3 vNormal;               
 varying vec3 vViewPosition;
 
 uniform vec3 AmbientLight;
 uniform float roughness;

 
 #if NUM_SPOT_LIGHTS > 0
     struct SpotLight {
         vec3 position;
         vec3 direction;
         vec3 color;
         float distance;
         float decay;
         bool visible;
         float angle;
         float penumbra;
         float coneCos;
         float penumbraCos;
     };

     uniform SpotLight spotLights[ NUM_SPOT_LIGHTS ];
 #endif

 #include <common>

 float getSpotAttenuation( const in float coneCosine, const in float penumbraCosine, const in float angleCosine ) {

     return smoothstep( coneCosine, penumbraCosine, angleCosine );

 }


 float getDistanceAttenuation( const in float lightDistance, const in float cutoffDistance, const in float decayExponent ) {

     // based upon Frostbite 3 Moving to Physically-based Rendering
     // page 32, equation 26: E[window1]
     // https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
     float distanceFalloff = 1.0 / max( pow( lightDistance, decayExponent ), 0.01 );

     if ( cutoffDistance > 0.0 ) {

         distanceFalloff *= pow2( saturate( 1.0 - pow4( lightDistance / cutoffDistance ) ) );

     }

     return distanceFalloff;

 }

 void main() {
     gl_FragColor = vec4(vec3( 1,0,0 ) , 1. );

     #if NUM_SPOT_LIGHTS > 0
         #ifdef FLAT_SHADED

             vec3 fdx = dFdx( vViewPosition );
             vec3 fdy = dFdy( vViewPosition );
             vec3 normal = normalize( cross( fdx, fdy ) );

         #else

             vec3 normal =  vNormal ;
             normal = normalize( vNormal );

         #endif

         vec3 geometryPosition = - vViewPosition;
         vec3 geometryNormal = normal;
         vec3 geometryViewDir = normalize( vViewPosition );

         SpotLight spotLight;

         vec3 directSpecular = vec3(0.);
         vec3 diffuse = vec3(0.);

         for ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {
             spotLight = spotLights[ i ];

             vec3 lVector = spotLight.position - geometryPosition;
     
             vec3 lightDirection = normalize( lVector );

             // 漫反射
             float diff = max(dot(normal, lightDirection), 0.0);
             // * spotLight.color

             float angleCos = dot( lightDirection, spotLight.direction);
             
             float spotAttenuation = getSpotAttenuation( spotLight.coneCos, spotLight.penumbraCos, angleCos );
             
             // if(angleCos > spotLight.coneCos){
             //     diffuse = vec3(1.);
             // }else {
             //     diffuse = vec3(0.);
             // }

             if(spotAttenuation > 0.0){
                 float lightDistance = length( lVector );

                 float attenuation = getDistanceAttenuation(lightDistance, spotLight.distance, spotLight.decay);
                 
                 diffuse += diff * spotLight.color * spotAttenuation * attenuation;
             }

         }

         // gl_FragColor = vec4( directSpecular , 1. );
         gl_FragColor = vec4( diffuse + AmbientLight , 1. );

     #endif
 }
全部
import * as THREE from "three";
import { ThreeHelper } from "@/src/ThreeHelper";
import { MethodBaseSceneSet, LoadGLTF } from "@/src/ThreeHelper/decorators";
import { MainScreen } from "./Canvas";
import type { GLTF } from "three/examples/jsm/loaders/GLTFLoader";
import { Injectable } from "@/src/ThreeHelper/decorators/DI";
import type { GUI } from "dat.gui";
import { SpotLightMaterial } from "@/src/ThreeHelper/shader/material/SpotLight";
import { SpecularShaderMaterial } from "@/src/ThreeHelper/shader/material/Specular";

@Injectable
// @ThreeHelper.useWebGPU
export class Main extends MainScreen {
    static instance: Main;
    // spotLight = new THREE.SpotLight(0xffffff, 100, 0, 1, 1, 2);
    spotLight = new THREE.SpotLight(0xffffff, 100, 0, 0.5, 1, 2);

    constructor(private helper: ThreeHelper) {
        super(helper);
        helper.main = this;
        this.init();
        Main.instance = this;
    }

    @MethodBaseSceneSet({
        addAxis: true,
        cameraPosition: new THREE.Vector3(-3, 2, 5),
        cameraTarget: new THREE.Vector3(0, 0, 0),
        useRoomLight: false,
        near: 0.1,
        far: 800,
    })
    init() {
        this.spotLight.position.set(0, 0, 2);
        // this.spotLight.target.position.set(0, 0, 0);

        this.helper.add(this.spotLight);

        // const directionalLight = new THREE.DirectionalLight(0xffffff, 0.5);

        // directionalLight.position.set(0, 0, 1);

        // const targetObject = new THREE.Object3D();

        // targetObject.position.set(0, 0, -1);

        // this.helper.scene.add(targetObject);

        // directionalLight.target = targetObject;
        // this.helper.scene.add(directionalLight);

        // const light = new THREE.AmbientLight(0x404040);
        // this.helper.scene.add(light);

        // {
        //     const light = new THREE.PointLight(0xffffff, 10, 100);
        //     light.position.set(0, 0, 3);
        //     this.helper.scene.add(light);
        // }

        {
            const object = this.helper.create.plane(12, 30);

            object.mesh.position.y = -1;
            object.mesh.position.z = -5;

            object.mesh.rotateX(Math.PI / -2);

            object.material(
                new SpotLightMaterial({
                    scene: this.helper.scene,
                    camera: this.helper.camera,
                    roughness: 0,
                })
                // new THREE.MeshStandardMaterial({ roughness: 0, metalness: 0 })
            );

            // const phongMaterial = new THREE.MeshPhongMaterial();

            // object.material(phongMaterial);

            this.helper.add(object.mesh);
        }

        const object = this.helper.create.sphere(1, 64, 64);

        object.material(
            new SpotLightMaterial({
                scene: this.helper.scene,
                camera: this.helper.camera,
                roughness: 0,
            })
            // new THREE.MeshStandardMaterial({ roughness: 0, metalness: 0 })
        );

        this.helper.add(object.mesh);
        {
            const object = this.helper.create.box(0.3, 0.3, 0.3);

            object.mesh.position.y = -1;
            object.mesh.position.x = -1;
            object.mesh.position.z = -2;
            object.mesh.rotateY(Math.PI / 4);

            object.material(
                new SpotLightMaterial({
                    scene: this.helper.scene,
                    camera: this.helper.camera,
                    roughness: 0,
                })
                // new THREE.MeshStandardMaterial({ roughness: 0, metalness: 0 })
            );

            this.helper.add(object.mesh);
        }

        // plane.material(
        //     new SpecularShaderMaterial({
        //         scene: this.helper.scene,
        //         camera: this.helper.camera,
        //         roughness: 0.,
        //     })
        // );

        // const phongMaterial = new THREE.MeshPhongMaterial();

        // object.material(phongMaterial);

        // phongMaterial.onBeforeCompile = (shader) => {
        //     shader.fragmentShader = shader.fragmentShader.replace(
        //         "vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveRadiance;",
        //         `
        //         vec3 outgoingLight = reflectedLight.directDiffuse;
        //         `
        //     );
        //     console.log(shader.fragmentShader);
        // };

        // plane.material(new THREE.MeshStandardMaterial({roughness:0,metalness:0}));
        // plane.material(new THREE.MeshBasicMaterial());
    }

    @LoadGLTF("/public/models/.glb")
    loadModel(gltf?: GLTF) {
        if (gltf) {
            this.helper.add(gltf.scene);
        }
    }

    @ThreeHelper.InjectAnimation(Main)
    animation() {
        // this.spotLight.target.rotation.x += 0.1
    }

    @ThreeHelper.AddGUI(Main)
    createEnvTexture(gui: GUI) {
        gui.add(this.spotLight, "visible").name("three.spotLight");

        const prev = this.spotLight.position.clone();
        const lightPosition = this.spotLight.position;

        const tempObj = new THREE.Object3D();

        this.helper.gui?.add({ v: 0 }, "v", -360, 360).onChange((v) => {
            lightPosition.copy(prev);

            tempObj.rotation.x = v * (Math.PI / 180);

            tempObj.updateMatrix();

            lightPosition.applyMatrix4(tempObj.matrix);

            // lightDirection.copy(lightPosition).multiplyScalar(-1).normalize();
        });

        gui.add(this.spotLight, "angle", 0, Math.PI / 3).onChange((val) => {
            this.spotLight.angle = val;
        });

        gui.add(this.spotLight, "penumbra", 0, 1).onChange((val) => {
            this.spotLight.penumbra = val;
        });

        gui.add(this.spotLight, "decay", 1, 4).onChange((val) => {
            this.spotLight.decay = val;
        });

        gui.add(this.spotLight, "intensity", 0, 100).onChange((val) => {
            this.spotLight.intensity = val;
        });

        gui.addFunction(() => {
            this.helper.scene.traverse((obj) => {
                const mesh = obj as THREE.Mesh<THREE.BufferGeometry, THREE.Material>;

                if (mesh.material) {
                    if (mesh.material.type == "ShaderMaterial") {
                        mesh.userData.material = mesh.material;
                        mesh.material = new THREE.MeshPhongMaterial();
                    } else {
                        mesh.userData.material && (mesh.material = mesh.userData.material);
                    }
                }
            });
        }, "Toggle Material");
    }
}

import * as THREE from "three";

interface SpotLightUniforms {
    color: THREE.SpotLight["color"];
    intensity: THREE.SpotLight["intensity"];
    distance: THREE.SpotLight["distance"];

    decay: THREE.SpotLight["decay"];
    visible: THREE.SpotLight["visible"];
    position: THREE.SpotLight["position"];

    coneCos: number;
    penumbraCos: number;
}

export class SpotLightMaterial extends THREE.ShaderMaterial {
    Lights: SpotLightUniforms[] = [];
    original: ConstructorParameters<typeof THREE.ShaderMaterial>[0];
    color = new THREE.Color(0xffffff);

    onBeforeRender(renderer: THREE.WebGLRenderer, scene: THREE.Scene, camera: THREE.Camera): void {
        const Lights: SpotLightUniforms[] = [];

        const viewMatrix = camera.matrixWorldInverse;
        const vector3 = new THREE.Vector3();

        scene.traverse((obj) => {
            if (obj.type == "SpotLight") {
                const light = obj as THREE.SpotLight;
                const uniforms = {
                    position: new THREE.Vector3(),
                    direction: new THREE.Vector3(),
                    color: light.color.clone().multiplyScalar(light.intensity),
                    intensity: light.intensity,
                    distance: light.distance,
                    decay: light.decay,
                    visible: light.visible,

                    coneCos: Math.cos(light.angle),
                    penumbraCos: Math.cos(light.angle * (1 - light.penumbra)),
                };

                uniforms.position.setFromMatrixPosition(light.matrixWorld);
                uniforms.position.applyMatrix4(viewMatrix);

                uniforms.direction.setFromMatrixPosition(light.matrixWorld);
                vector3.setFromMatrixPosition(light.target.matrixWorld);
                uniforms.direction.sub(vector3);
                uniforms.direction.transformDirection(viewMatrix);

                // console.log(uniforms.position)
                // console.log(uniforms.direction)

                Lights.push(uniforms);
            }
        });

        // this.fragmentShader = this.replaceLightNums(this.original!.fragmentShader!, {
        //     numPointLights: PointLights.length,
        // });

        this.uniforms.spotLights.value = Lights;
    }

    constructor(
        params?: ConstructorParameters<typeof THREE.ShaderMaterial>[0] & {
            scene: THREE.Scene;
            camera: THREE.PerspectiveCamera;
            roughness: number;
            AmbientLight?: THREE.Color;
        }
    ) {
        const original = {
            uniforms: {
                spotLights: {
                    value: [] as SpotLightUniforms[],
                },
                roughness: {
                    value: params?.roughness,
                },
                AmbientLight: { value: params?.AmbientLight ?? new THREE.Color(0x000000) },
            },
            defines: {
                RECIPROCAL_PI: 1 / Math.PI,
                // 平直着色 关闭则 平滑着色
                FLAT_SHADED: false,
            },
            vertexShader: /* glsl */ `
                varying vec3 vNormal;
                
                varying vec3 vViewPosition;

                void main() {

                    vNormal = normalMatrix * normal;
                    vNormal = normalize( vNormal );

                    vec4 modelViewPosition = modelViewMatrix * vec4(position, 1.0);
                    gl_Position = projectionMatrix * modelViewPosition;

                    vec3 transformed = vec3( position );

                    vec4 mvPosition = vec4( transformed, 1.0 );
                    
                    mvPosition = modelViewMatrix * mvPosition;

	                vViewPosition = - mvPosition.xyz;

                }`,
            fragmentShader: /* glsl */ `
                varying vec3 vNormal;               
                varying vec3 vViewPosition;
                
                uniform vec3 AmbientLight;
                uniform float roughness;

                
                #if NUM_SPOT_LIGHTS > 0
                    struct SpotLight {
                        vec3 position;
                        vec3 direction;
                        vec3 color;
                        float distance;
                        float decay;
                        bool visible;
                        float angle;
                        float penumbra;
                        float coneCos;
                        float penumbraCos;
                    };

                    uniform SpotLight spotLights[ NUM_SPOT_LIGHTS ];
                #endif

                #include <common>

                float getSpotAttenuation( const in float coneCosine, const in float penumbraCosine, const in float angleCosine ) {

                    return smoothstep( coneCosine, penumbraCosine, angleCosine );

                }


                float getDistanceAttenuation( const in float lightDistance, const in float cutoffDistance, const in float decayExponent ) {

                    // based upon Frostbite 3 Moving to Physically-based Rendering
                    // page 32, equation 26: E[window1]
                    // https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
                    float distanceFalloff = 1.0 / max( pow( lightDistance, decayExponent ), 0.01 );

                    if ( cutoffDistance > 0.0 ) {

                        distanceFalloff *= pow2( saturate( 1.0 - pow4( lightDistance / cutoffDistance ) ) );

                    }

                    return distanceFalloff;

                }

                void main() {
                    gl_FragColor = vec4(vec3( 1,0,0 ) , 1. );

                    #if NUM_SPOT_LIGHTS > 0
                        #ifdef FLAT_SHADED

                            vec3 fdx = dFdx( vViewPosition );
                            vec3 fdy = dFdy( vViewPosition );
                            vec3 normal = normalize( cross( fdx, fdy ) );

                        #else

                            vec3 normal =  vNormal ;
                            normal = normalize( vNormal );

                        #endif

                        vec3 geometryPosition = - vViewPosition;
                        vec3 geometryNormal = normal;
                        vec3 geometryViewDir = normalize( vViewPosition );

                        SpotLight spotLight;

                        vec3 directSpecular = vec3(0.);
                        vec3 diffuse = vec3(0.);

                        for ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {
                            spotLight = spotLights[ i ];

                            vec3 lVector = spotLight.position - geometryPosition;
                    
                            vec3 lightDirection = normalize( lVector );

                            // 漫反射
                            float diff = max(dot(normal, lightDirection), 0.0);
                            // * spotLight.color

                            float angleCos = dot( lightDirection, spotLight.direction);
                            
                            float spotAttenuation = getSpotAttenuation( spotLight.coneCos, spotLight.penumbraCos, angleCos );
                            
                            // if(angleCos > spotLight.coneCos){
                            //     diffuse = vec3(1.);
                            // }else {
                            //     diffuse = vec3(0.);
                            // }

                            if(spotAttenuation > 0.0){
                                float lightDistance = length( lVector );

                                float attenuation = getDistanceAttenuation(lightDistance, spotLight.distance, spotLight.decay);
                                
                                diffuse += diff * spotLight.color * spotAttenuation * attenuation;
                            }

                        }

                        // gl_FragColor = vec4( directSpecular , 1. );
                        gl_FragColor = vec4( diffuse + AmbientLight , 1. );

                    #endif
                }
            `,
        };

        const SpotLights: SpotLightUniforms[] = [];

        const viewMatrix = params!.camera.matrixWorldInverse;
        const vector3 = new THREE.Vector3();

        params!.scene.traverse((obj) => {
            if (obj.type == "SpotLight") {
                const light = obj as THREE.SpotLight;
                const uniforms = {
                    position: new THREE.Vector3(),
                    direction: new THREE.Vector3(),
                    color: light.color.clone().multiplyScalar(light.intensity),
                    intensity: light.intensity,
                    distance: light.distance,
                    decay: light.decay,
                    visible: light.visible,

                    coneCos: Math.cos(light.angle),
                    penumbraCos: Math.cos(light.angle * (1 - light.penumbra)),
                };

                console.log(uniforms.coneCos);
                console.log(uniforms.penumbraCos);

                uniforms.position.setFromMatrixPosition(light.matrixWorld);
                uniforms.position.applyMatrix4(viewMatrix);

                uniforms.direction.setFromMatrixPosition(light.matrixWorld);
                vector3.setFromMatrixPosition(light.target.matrixWorld);
                uniforms.direction.sub(vector3);
                uniforms.direction.transformDirection(viewMatrix);

                SpotLights.push(uniforms);
            }
        });

        const replaceLightNums = (string: string, parameters: { numSpotLights: number }) => {
            return string.replace(/NUM_SPOT_LIGHTS/g, "" + parameters.numSpotLights);
        };

        original.uniforms.spotLights = { value: SpotLights };

        original.fragmentShader = replaceLightNums(original!.fragmentShader!, {
            numSpotLights: SpotLights.length,
        });

        super(original);
        this.original = original;
    }
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2227409.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

WPF+MVVM案例实战(三)- 动态数字卡片效果实现

1、创建项目 打开 VS2022 &#xff0c;新建项目 Wpf_Examples&#xff0c;创建各层级文件夹&#xff0c;安装 CommunityToolkit.Mvvm 和 Microsoft.Extensions.DependencyInjectio NuGet包,完成MVVM框架搭建。搭建完成后项目层次如下图所示&#xff1a; 这里如何实现 MVVM 框…

深入理解 SQL 中的 WITH AS 语法

在日常数据库操作中&#xff0c;SQL 语句的复杂性往往会影响到查询的可读性和维护性。为了解决这个问题&#xff0c;Oracle 提供了 WITH AS 语法&#xff0c;这一功能可以极大地简化复杂查询&#xff0c;提升代码的清晰度。本文将详细介绍 WITH AS 的基本用法、优势以及一些实际…

【云原生】Kubernets1.29部署StorageClass-NFS作为存储类,动态创建pvc(已存在NFS服务端)

文章目录 在写redis集群搭建的时候,有提到过使用nfs做storageclass,那时候kubernetes是1.20版本,https://dongweizhen.blog.csdn.net/article/details/130651727 现在使用的是kubernetes 1.29版本,根据之前的修改方式并未生效,反而提示:Error: invalid argument "Re…

算法日记 11 day 二叉树

新的篇章&#xff0c;二叉树&#xff01;&#xff01;&#xff01; 二叉树的种类 满二叉树&#xff1a;如果一棵二叉树只有度为0的结点和度为2的结点&#xff0c;并且度为0的结点在同一层上&#xff0c;则这棵二叉树为满二叉树。 这棵二叉树为满二叉树&#xff0c;也可以说深度…

IDEA->EasyCode(mapper.xml) 字段无逗号分隔和修改全局变量问题

1.mapperxml字段无逗号分隔 在easycode的设置里找到&#xff1a; 1、Template下的 mapper.xml.vm脚本 2、Global Config下的 mybatisSupport.vm脚本 将脚本里的 $velocityHasNext 替换成 $foreach.hasNext&#xff0c;然后保存。Mybatis-Plus框架操作一样 github->issue连…

红队工具---Behinder学习

1.什么是Behinder&#xff1f; Behinder 是一款用于网络渗透测试的安全工具&#xff0c;主要用于对 Web 应用进行攻击和漏洞利用。它提供了强大的功能&#xff0c;是一款红队的大杀器&#xff0c;几乎是现代web安全必须学习的一款webshell管理工具。 主要用途 渗透测试&#…

中航资本:商业卫星产业链建设加快 无人机军民两用空间广阔

互联网医疗迎多重边沿改进 我国居民医疗保健开支稳步添加&#xff0c;据国家统计局数据&#xff0c;2023年全国居民医疗保健人均消费开支为2460元&#xff0c;占人均消费总开支的比例从2018年的8.5%前进至2023年的9.2%。跟着慢病患者群扩展、业态相似的外卖、产品电商翻开以及…

基于springboot+vue实现的免费体育馆场地预约系统 (源码+L文+ppt)4-099

基于springbootvue实现的免费体育馆场地预约系统 &#xff08;源码L文ppt&#xff09;4-099 4.1 系统总体结构设计 本系统是基于B/S架构的网站系统&#xff0c;分为系统前台和系统后台&#xff0c;前台主要是提供给注册用户和未注册登录的游客使用的&#xff0c;包括首页、场馆…

雷军救WPS“三次”,WPS注入新生力量,不再“抄袭”微软

救WPS“三次” 1989年&#xff0c;求伯君用128万行代码编写出了WPS1.0&#xff0c;宣告了中国自主办公时代的开启。 那时候&#xff0c;雷军还在武汉大学深造&#xff0c;他早就把求伯君当成了自己的榜样&#xff0c;这一来二去的&#xff0c;雷军和WPS之间也就结下了不解之缘…

基于GFlowNets的蚁群抽样算法在组合优化中的应用(arXiv 2024)(未完) -1

文章目录 Abstract1 Introduction2 Related works2.1 蚁群优化2.2 神经组合优化2.3 GFlowNets与组合优化3 Preliminary3.1 旅行商问题3.2 蚁群优化3.3 生成流网络Abstract 本文介绍了一种神经引导的概率搜索算法——生成流蚁群采样器(GFACS),用于解决组合优化(CO)问题。G…

【C++】类和对象(四):析构函数

大家好&#xff0c;我是苏貝&#xff0c;本篇博客带大家了解C的析构函数&#xff0c;如果你觉得我写的还不错的话&#xff0c;可以给我一个赞&#x1f44d;吗&#xff0c;感谢❤️ 目录 1. 概念2. 特性 1. 概念 通过前面构造函数的学习&#xff0c;我们知道一个对象是怎么来的…

VulkanTutorial(8·Shader modules)

Shader modules 与早期的API不同&#xff0c;Vulkan中的着色器代码必须以字节码格式指定&#xff0c;而不是人类可读的语法&#xff0c;如GLSL和HLSL。这种字节码格式称为SPIR-V它是一种可用于编写图形和计算着色器的格式 使用像SPIR-V这样简单的字节码格式&#xff0c;不会面…

详解PHP正则表达式中的转义操作

PHP正则表达式中的特殊字符和转义 在 PHP 正则表达式中&#xff0c;有许多特殊字符具有特定的意义。这些特殊字符通常用于定义匹配模式的一部分&#xff0c;或者改变匹配的行为。以下是 PHP 正则表达式中一些常用的特殊字符及其含义: .匹配除换行符之外的任何单个字符 ^在方括…

27.Redis哨兵架构

Redis哨兵高可用架构 Sentinel&#xff08;哨兵&#xff09;是一种特殊的 Redis 服务&#xff0c;其主要功能并非提供常规的读写服务&#xff0c;而是专门用于监控 Redis 实例节点。 1.在哨兵架构下&#xff0c;客户端&#xff08;client 端&#xff09;首次会从哨兵处找出 Re…

STM32G474硬件CRC7和软件CRC7校验

1、CRC7的多项式和初始值 #define CRC_Hardware_POLYNOMIAL_7B 0x09//硬件CRC多项式为0x09 //SD卡中的校验算法CRC7&#xff0c;生成多项式为x^7 x^3 1&#xff0c;由于bit7不存在&#xff0c;只有bit31和bit01&#xff0c;所以多项式为0x09#define CRC7_INIT_VALUE 0…

Java基础 —— IO流详解

IO流 在Java中&#xff0c;IO&#xff08;输入/输出&#xff09;流是用于在程序与外部世界&#xff08;如文件、网络、内存等&#xff09;之间传输数据的机制。IO流分为两大类&#xff1a;输入流&#xff08;InputStream/Reader&#xff09;和输出流&#xff08;OutputStream/…

【01初识】-初识 RabbitMQ

目录 学习背景1- 初识 MQ1-1 同步调用什么是同步调用&#xff1f;小结&#xff1a;同步调用优缺点 1-2 异步调用什么是异步调用&#xff1f;小结&#xff1a;异步调用的优缺点&#xff0c;什么时候使用异步调用&#xff1f; 1-3 MQ 技术选型 学习背景 异步通讯的特点&#xff…

STK与MATLAB互联——仿真导航卫星与地面用户间距离和仰角参数

文章目录 构建GPS星座创建单个PRN的GPS卫星创建GPS星座&#xff0c;并为其添加发射机 北斗星座构建搭建低轨铱星星座构建一颗轨道高度为800km/1000km/1200km的低轨卫星构建一颗轨道高度为800km/1000km/1200km的低轨卫星建立地面站&#xff0c;可见性分析确定地面站坐标分析单颗…

Excel菜单选项无法点击?两种原因及解决方法全解析

在使用Excel处理数据时&#xff0c;有时会遇到菜单选项无法点击的情况。这种问题会影响到正常的操作和编辑。出现这种情况的原因可能有多种&#xff0c;本文将介绍两种常见的原因&#xff0c;并提供相应的解决方法&#xff0c;帮助小伙伴们快速恢复菜单选项的正常使用。 原因一…

【银河麒麟高级服务器操作系统·实例分享】裸金属服务器开机失败分析及处理建议

了解更多银河麒麟操作系统全新产品&#xff0c;请点击访问 麒麟软件产品专区&#xff1a;https://product.kylinos.cn 开发者专区&#xff1a;https://developer.kylinos.cn 文档中心&#xff1a;https://documentkylinos.cn 现象描述 裸金属物理服务器开机卡在EFI stub页面…