- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个闪烁的 THREE.Points 问题,具体取决于它们的 UV 坐标,如以下代码笔所示:http://codepen.io/anon/pen/qrdQeY?editors=0010
codepen中的代码尽量精简(171行),
但总结一下我在做什么:
/// FRAGMENT SHADER ===========================================================
const fragmentShader = `
precision highp float;
uniform sampler2D spritesheet;
// number of spritesheet subdivisions both vertically and horizontally
// e.g. for a 4x4 spritesheet this number is 4
uniform float spritesheetSubdivisions;
// vParams[i].x = sprite index
// vParams[i].z = sprite alpha
varying vec3 vParams;
/**
* Maps regular UV coordinates spanning the entire spritesheet
* to a specific sprite within the spritesheet based on the given index,
* which points into a spritesheel cell (depending on spritesheetSubdivisions
* and assuming that the spritesheet is regular and square).
*/
vec2 spriteIndexToUV(float idx, vec2 uv) {
float cols = spritesheetSubdivisions;
float rows = spritesheetSubdivisions;
float x = mod(idx, cols);
float y = floor(idx / cols);
return vec2(x / cols + uv.x / cols, 1.0 - (y / rows + (uv.y) / rows));
}
void main() {
vec2 uv = spriteIndexToUV(vParams.x, gl_PointCoord);
vec4 diffuse = texture2D(spritesheet, uv);
float alpha = diffuse.a * vParams.z;
if (alpha < 0.5) discard;
gl_FragColor = vec4(diffuse.xyz, alpha);
}
`
// VERTEX SHADER ==============================================================
const vertexShader = `
precision highp float;
uniform mat4 modelViewMatrix;
uniform mat4 projectionMatrix;
uniform float size;
uniform float scale;
attribute vec3 position;
attribute vec3 params; // x = sprite index, y = unused, z = sprite alpha
attribute vec3 color;
varying vec3 vParams;
void main() {
vParams = params;
vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );
gl_Position = projectionMatrix * mvPosition;
gl_PointSize = size * ( scale / - mvPosition.z );
}
`
// THREEJS CODE ===============================================================
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
const renderer = new THREE.WebGLRenderer({canvas: document.querySelector("#mycanvas")});
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setClearColor(0xf0f0f0)
const pointGeometry = new THREE.BufferGeometry()
pointGeometry.addAttribute("position", new THREE.BufferAttribute(new Float32Array([
-1.5, -1.5, 0,
-0.5, -1.5, 0,
0.5, -1.5, 0,
1.5, -1.5, 0,
-1.5, -0.5, 0,
-0.5, -0.5, 0,
0.5, -0.5, 0,
1.5, -0.5, 0,
-1.5, 0.5, 0,
-0.5, 0.5, 0,
0.5, 0.5, 0,
1.5, 0.5, 0,
-1.5, 1.5, 0,
-0.5, 1.5, 0,
0.5, 1.5, 0,
1.5, 1.5, 0,
]), 3))
pointGeometry.addAttribute("params", new THREE.BufferAttribute(new Float32Array([
0, 0, 1, // sprite index 0 (row 0, column 0)
1, 0, 1, // sprite index 1 (row 0, column 1)
2, 0, 1, // sprite index 2 (row 0, column 2)
3, 0, 1, // sprite index 3 (row 0, column 4)
4, 0, 1, // sprite index 4 (row 1, column 0)
5, 0, 1, // sprite index 5 (row 1, column 1)
6, 0, 1, // ...
7, 0, 1,
8, 0, 1,
9, 0, 1,
10, 0, 1,
11, 0, 1,
12, 0, 1,
13, 0, 1,
14, 0, 1,
15, 0, 1
]), 3))
const img = document.querySelector("img")
const texture = new THREE.TextureLoader().load(img.src);
const pointMaterial = new THREE.RawShaderMaterial({
transparent: true,
vertexShader: vertexShader,
fragmentShader: fragmentShader,
uniforms: {
spritesheet: {
type: "t",
value: texture
},
spritesheetSubdivisions: {
type: "f",
value: 4
},
size: {
type: "f",
value: 1
},
scale: {
type: "f",
value: window.innerHeight / 2
}
}
})
const points = new THREE.Points(pointGeometry, pointMaterial)
scene.add(points)
const render = function (timestamp) {
requestAnimationFrame(render);
camera.position.z = 5 + Math.sin(timestamp / 1000.0)
renderer.render(scene, camera);
};
render();
// resize viewport
window.addEventListener( 'resize', onWindowResize, false );
function onWindowResize(){
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize( window.innerWidth, window.innerHeight );
}
最佳答案
spriteIndexToUV() 函数中的 mod()/floor() 计算在某些星座中引起问题(当 spriteindex 是 spritesheetSubdivisions 的倍数时)。
我可以通过用一个小 epsilon 调整 cols 变量来修复它:
vec2 spriteIndexToUV(float idx, vec2 uv)
{
float cols = spritesheetSubdivisions - 1e-6; // subtract epsilon
float rows = spritesheetSubdivisions;
float x = mod(idx, cols);
float y = floor(idx / cols);
return vec2(x / cols + uv.x / cols, 1.0 - (y / rows + (uv.y) / rows));
}
float cols = spritesheetSubdivisions;
float rows = spritesheetSubdivisions;
float y = floor ((idx+0.5) / cols);
float x = idx - cols * y;
floor (idx/4)
当
idx
时,有时会产生 0 而不是 1应该正好是4.0,我只能推测
varying vec3 vParams
当它从顶点着色器进入片段着色器阶段时会受到一些插值,从而导致片段着色器看到例如3.999999 而不是 4.0。
关于three.js - 基于相机位置和纹理坐标的三点闪烁,但仅限于 Nvidia 卡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42327736/
我正在尝试在 Google Colab 上运行 stylegan2,但在我的 Drive 上运行所有文件,并避免使用 !git clone 从 github of stylegan2 。 这是我在特定
我需要升级我的 nvidia 驱动程序,以便尝试运行 NVIDIA-LInux-x86_64.run文件 但是,我看到以下消息 ERROR: An NVIDIA kernel module 'nvid
我经历过Cuda programming guide但仍然不清楚 cuda 内核在 GPU 上的什么位置?换句话说,它驻留在哪个内存段? 另外,我怎么知道我的设备支持的最大内核大小是多少?最大内核大小
我想在基于官方nvidia/cuda的容器中运行带有cuvid硬件加速解码的ffmpeg图片。 Ffmpeg 无法找到 libnvcuvid.so,尽管有所有必需的 cuda 库。ldconfig -
当我运行命令 nvidia-smi ,我得到以下两个按总线 ID 排序的 GPU: For GPU 0, 00000000:0A:00.0 For GPU 1, 00000000:41:00.0 但是
我正在使用 Ubuntu 14.04 LTS 运行 AWS EC2 g2.2xlarge 实例。我想在训练 TensorFlow 模型时观察 GPU 利用率。我在尝试运行“nvidia-smi”时遇到
我尝试在安装 docker-ce 后安装 nvidia-docker。我关注的是:https://github.com/NVIDIA/nvidia-docker安装 nvidia-docker。看来已
我一直认为 Hyper-Q 技术不过是 GPU 中的流。后来我发现我错了(是吗?)。所以我读了一些关于 Hyper-Q 的书,却更加困惑了。 我正在浏览一篇文章,它有以下两个陈述: A. Hyper-
我刚刚在安装了两个 K20m GPU 的服务器中运行了 simpleMultiGPU。然后运行 nvidia-smi 命令来显示 GPU 的状态。结果如下: 问题如下: GPU 内存使用情况似乎不
NVIDIA-SMI 抛出此错误: NVIDIA-SMI has failed because it couldn't communicate with the NVIDIA driver. Make
如何使用 Vulkan 来利用 Nvidia 的张量核心(在计算着色器中?!)? Nvidia 有这篇文章 Programming Tensor Cores in CUDA 9 ,但这显然是针对 CU
我在类的一个项目中使用 Chapel,我正在尝试使用我的两个 Nvidia Jetson nano 板进行多语言环境执行。按照本教程 https://chapel-lang.org/docs/usin
我得到nvidia-smi得到Memory-Usage是这样的 $nvidia-smi -i 0,1 Wed Mar 4 16:20:07 2020 +-----------------
我得到nvidia-smi得到Memory-Usage是这样的 $nvidia-smi -i 0,1 Wed Mar 4 16:20:07 2020 +-----------------
有没有区别: nvidia-docker 运行 和 docker run --runtime=nvidia ? 在 official docs他们使用后者,但我在其他在线教程中看到过前者。 最佳答案
我有一个用 C 编写的代码(使用 opencl 规范)来列出所有可用的设备。我的 PC 安装了 AMD FirePro 和 Nvidia 的 Tesla 显卡。我先安装了AMD-APP-SDK-v3.
我读到可以使用内核启动来同步不同的 block ,即,如果我希望所有 block 在进行操作 2 之前完成操作 1,我应该将操作 1 放在一个内核中,将操作 2 放在另一个内核中。这样,我可以实现 b
我目前正在尝试使用函数 NvAPI_Stereo_SetDriverMode 将 nvapi 设置为在直接模式下工作。 根据 Nvidia nvapi site (在手册中),如果你想做一个 dire
我对nvidia GPU的任务调度有些疑惑。 (1)如果一个 block (CTA)中的线程束已经完成,但仍有其他线程在运行,这个线程会等待其他线程完成吗?换句话说,当所有线程都完成时, block
有人在Nvidia Tegra X1上使用了tensorflow吗? 我发现一些资料表明TK1上可能存在这种情况,或者TX1上存在严重的黑客入侵/错误,但尚无确定的配方。 http://cudamus
我是一名优秀的程序员,十分优秀!