करने के लिए एक GLSL कांच शेडर संपादितबंदरगाह के लिए प्रसंस्करण 3.0
मैं प्रसंस्करण भाषा और GLSL shaders पर शुरुआत कर रहा हूँ कोशिश कर रहा है। मैं एक गिलास सामग्री के लिए एक fresnel + cubemap शेडर बंदरगाह बंद करने की कोशिश कर रहा हूँ। लेकिन जैसे-जैसे मेरी आकार परिणाम कभी गायब हो जाते हैं, बजाय ... :-(
मेरे शिखर शेडर है:
const float Air = 1.0;
const float Glass = 1.51714;
const float Eta = Air/Glass;
const float R0 = ((Air - Glass) * (Air - Glass))/((Air + Glass) * (Air + Glass));
uniform mat4 transform;
uniform mat4 modelview;
uniform mat3 normalMatrix;
attribute vec4 vertex;
attribute vec3 normal;
varying vec3 v_reflection;
varying vec3 v_refraction;
varying float v_fresnel;
void main(void){
vec4 t_vertex = modelview * vertex;
vec3 incident = normalize(vec3(t_vertex));
vec3 t_normal = normalMatrix * normal;
v_refraction = refract(incident, t_normal, Eta);
v_reflection = reflect(incident, t_normal);
v_fresnel = R0 + (1.0 - R0) * pow((1.0 - dot(-incident, t_normal)), 5.0);
gl_Position = transform * t_vertex;
}
और टुकड़ा शेडर:
#ifdef GL_ES
precision mediump float;
precision mediump int;
#endif
uniform samplerCube cubemap;
varying vec3 v_refraction;
varying vec3 v_reflection;
varying float v_fresnel;
void main(void){
vec4 refractionColor = textureCube(cubemap, normalize(v_refraction));
vec4 reflectionColor = textureCube(cubemap, normalize(v_reflection));
gl_FragColor = mix(refractionColor, reflectionColor, v_fresnel);
}
मैं के साथ इस शेडर का परीक्षण कर रहा हूँ 3.0 स्केच bellow (संपादित), प्रसंस्करण एंड्रॉयड मोड पर:
PShader shader;
PShape sphere;
void setup() {
fullScreen(P3D);
noStroke();
shader = loadShader("glass.frag.glsl", "glass.vert.glsl");
openCubeMap("posx.png", "negx.png", "posy.png", "negy.png", "posz.png", "negz.png");
shader.set("cubemap", 1);
sphere = createShape(SPHERE, 120);
sphere.setFill(color(-1, 50));
}
void draw() {
background(0);
directionalLight(102, 102, 102, 0, 0, -1);
lightSpecular(204, 204, 204);
directionalLight(102, 102, 102, 0, 1, -1);
specular(100, 150, 150);
translate(width/2, height/2);
shader(shader);
shape(sphere);
}
void openCubeMap(String posX, String negX, String posY, String negY, String posZ, String negZ) {
PGL pgl = beginPGL();
// create the OpenGL-based cubeMap
IntBuffer envMapTextureID = IntBuffer.allocate(1);
pgl.genTextures(1, envMapTextureID);
pgl.activeTexture(PGL.TEXTURE1);
pgl.enable(PGL.TEXTURE_CUBE_MAP);
pgl.bindTexture(PGL.TEXTURE_CUBE_MAP, envMapTextureID.get(0));
pgl.texParameteri(PGL.TEXTURE_CUBE_MAP, PGL.TEXTURE_WRAP_S, PGL.CLAMP_TO_EDGE);
pgl.texParameteri(PGL.TEXTURE_CUBE_MAP, PGL.TEXTURE_WRAP_T, PGL.CLAMP_TO_EDGE);
pgl.texParameteri(PGL.TEXTURE_CUBE_MAP, PGL.TEXTURE_WRAP_R, PGL.CLAMP_TO_EDGE);
pgl.texParameteri(PGL.TEXTURE_CUBE_MAP, PGL.TEXTURE_MIN_FILTER, PGL.LINEAR);
pgl.texParameteri(PGL.TEXTURE_CUBE_MAP, PGL.TEXTURE_MAG_FILTER, PGL.LINEAR);
//Load in textures
String[] textureNames = { posX, negX, posY, negY, posZ, negZ };
for (int i=0; i<textureNames.length; i++) {
PImage texture = loadImage(textureNames[i]);
int w = texture.width;
int h = texture.height;
texture.loadPixels();
pgl.texImage2D(PGL.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, PGL.RGBA, w, h, 0, PGL.RGBA, PGL.UNSIGNED_BYTE, IntBuffer.wrap(texture.pixels));
}
endPGL();
}
और मैं cubemap बनाने के लिए this छवियों का उपयोग कर रहा हूं।
कोई जानता है कि मैं यह काम कैसे कर सकता हूं?
कोड का एक बहुत माध्यम से जाने के लिए कह रहा है यही कारण है कि। यदि आप इसे [mcve] को जितना संभव हो उतना कम तक सीमित करके इसे [mcve] पोस्ट करते हैं तो आपको शायद बेहतर भाग्य मिलेगा। –
आप पूरी तरह से सही हैं, क्षमा करें। पिछली पोस्ट थोड़ा उलझन में थी। कृपया मेरा संपादित प्रश्न देखें। प्रासंगिक भाग वर्टेक्स और खंड कोड हैं। लेकिन मैंने मदद करने के लिए स्केच कोड जोड़ा, और साफ किया। क्षमा करें अगर अभी भी बहुत सी रेखाएं हैं, लेकिन अगर मैं इसे और अधिक कम करता हूं तो मुझे कुछ स्पष्टता बलिदान करने से डर लगता है। सहायता और सलाह के लिए धन्यवाद, @ केविन वर्कमैन। – Renascienza
क्या आपको कभी यह पता चला है? –