我有一個我加載到Scenekit中的Collada模型。 當我在模型上執行命中測試時,我能夠檢索命中的模型的紋理座標。IOS8 Scenekit在紋理座標上繪畫
有了這些紋理座標,我應該可以用顏色替換紋理座標。 所以這種方式,我應該可以借鑑模型
如果我錯了,糾正我到目前爲止。
我讀了很多文章到現在,但我只是沒有讓我的着色器正確。 (雖然我沒有得到一些時髦的效果;-)
我的頂點着色器:
precision highp float;
attribute vec4 position;
attribute vec2 textureCoordinate;
attribute vec2 aTexureCoordForColor; //coordinates from the hittest
uniform mat4 modelViewProjection;
varying vec2 aTexureCoordForColorVarying; // passing to the fragment shader here
varying vec2 texCoord;
void main(void) {
// Pass along to the fragment shader
texCoord = textureCoordinate;
aTexureCoordForColorVarying = aTexureCoordForColor; //assigning here
// output the projected position
gl_Position = modelViewProjection * position;
}
我的片段着色器
precision highp float;
uniform sampler2D yourTexture;
uniform vec2 uResolution;
uniform int uTexureCoordsCount;
varying vec2 texCoord;
varying vec2 aTexureCoordForColorVarying;
void main(void) {
??????????? no idea anymore what to do here
gl_FragColor = texture2D(yourTexture, texCoord);
//
如果您需要更多的代碼,請讓我知道。
哇......這是迄今爲止最好的信息......謝謝。我將處理這些信息,並讓您知道哪些方法最有效。 – Vilois 2014-10-01 09:14:06
是的..謝謝....事情現在有了很多更清楚的.....我添加了shaderModifier,稍微加大了上面的代碼,但總的來說它是一樣的.....非常感謝你 – Vilois 2014-10-01 11:43:45
@rickster你的回答很清楚,我認爲這會幫助我解決我自己的問題。它沒有解決,所以我已經發布了一個問題http://stackoverflow.com/questions/38999782/how-to-use-a-shadermodifier-to-alter-the-color-of-specific-triangles希望像你這樣的人能夠幫助你。順便說一句,你提供的第一個鏈接「這個答案」實際上鍊接到相同的「SCNShadable參考」;那是故意的。另外,在你最後的筆記中你提到_surface.color,我認爲你的意思是_surface.diffuse。 – PKCLsoft 2016-08-19 03:34:37