第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

在 ThreeJS DataTexture 中尋址 Texel

在 ThreeJS DataTexture 中尋址 Texel

紅糖糍粑 2021-11-04 16:40:44
我正在尋找在 Javascript 中計(jì)算 THREE.DataTexture 的 texel 引用,以便在片段著色器中使用。我已經(jīng)成功地計(jì)算了點(diǎn)的屏幕空間坐標(biāo),并將它們以 x 和 y 值的統(tǒng)一浮點(diǎn)數(shù)組形式傳遞給著色器,然后通過(guò)著色器中的索引引用這些點(diǎn)。我現(xiàn)在想要渲染太多點(diǎn)以在統(tǒng)一浮點(diǎn)數(shù)組中傳遞坐標(biāo),所以我想使用 DataTexture 并在 RGBA 紋素的 RG 值中寫入坐標(biāo)。var tDataWidth = points.length;var tData = new Uint8Array( Math.pow(tDataWidth, 2) );var texelSize = 1.0 / tDataWidth;var texelOffset = new THREE.Vector2(0.5 * texelSize, 0.5 * texelSize);for(var i = 0; i < points.length; i++){    //convert data to 0-1, then to 0-255    //inverse is to divide by 255 then multiply by width, height respectively    tData[i * 4] = Math.round(255 * (points[i].x / window.innerWidth));    tData[i * 4 + 1] = Math.round(255 * ((window.innerHeight - points[i].y) / window.innerHeight));    tData[i * 4 + 2] = 0;    tData[i * 4 + 3] = 0;    //calculate UV texel coordinates here    //Correct after edit    var u = ((i % tDataWidth) / tDataWidth) + texelOffset;    var v = (Math.floor(i / tDataWidth) + texelOffset);    var vUV = new THREE.Vector2(u, v);    //this function inserts the reference to the texel at the index into the shader    //referenced in the frag shader:    //cvec = texture2D(tData, index);    shaderInsert += ShaderInsert(vUV, screenPos.x, window.innerHeight - screenPos.y);}var dTexture = new THREE.DataTexture( sdfUItData, tDataWidth, tDataWidth, THREE.RGBAFormat, THREE.UnsignedByteType );//I think this is necessarydTexture.magFilter = THREE.NearestFilter;dTexture.needsUpdate = true;//update uniforms of shader to get this DataTexturerenderer.getUniforms("circles")["tData"].value = dTexture;//return string insert of circle//I'm editing the shader through javascript then recompiling it//There's more to it in the calling function, but this is the relevant part I think    ...對(duì)我出錯(cuò)的地方有什么幫助嗎?現(xiàn)在輸出都在左下角,所以 (0, window.innerHeight) 據(jù)我所知。謝謝!
查看完整描述

1 回答

?
BIG陽(yáng)

TA貢獻(xiàn)1859條經(jīng)驗(yàn) 獲得超6個(gè)贊

所以答案其實(shí)很簡(jiǎn)單。在片段著色器中,rgba 值為 0.0 - 1.0,因此不需要像在片段著色器中那樣除以 255。

我還想說(shuō),我發(fā)現(xiàn)了 Spector.js Chrome 擴(kuò)展程序,它允許查看所有 webgl 調(diào)用和緩沖區(qū)。很酷!

http://img1.sycdn.imooc.com//61839cc10001571725551286.jpg

如果有人想了解更多關(guān)于片段著色器中繪圖函數(shù)是如何工作的,這一切都在我沒(méi)有寫的這個(gè)很棒的著色器中:

https://www.shadertoy.com/view/4dfXDn

<3


查看完整回答
反對(duì) 回復(fù) 2021-11-04
  • 1 回答
  • 0 關(guān)注
  • 352 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)