Turbochist
Member
Content count
46 
Joined

Last visited
Community Reputation
241 NeutralAbout Turbochist

Rank
Member

Webgl bindBufer depends on buffer size or not?
Turbochist posted a topic in Graphics and GPU Programming
Does bindBuffer operation depends on binded buffer size? For example I have an array of indices I want to draw, also I have a few vertex buffer(sources of my vertices) first is 100 vertices second is 10000000 vertices buffers(allready created buffers) for example. The question is that changing(or binding) vertex buffers depends on their sizes or not? Ofcource rendering and creating buffers depends on buffer size but for refine I'm interesting only bindBuffer operation performance. Thank for any advice. 
How to separately discard in multiple rendering targets fragment?
Turbochist posted a topic in Graphics and GPU Programming
Hi. There is a problem. I make billboard picking, and i render it in one pass with two gl_FragData. First  is a billboard image and second is a quad color mask. Billboards are transparent, and pixel with zero alpha discarded in fragment shader. I dont want to sort them)) And discard works fine, but it's also discard zero pxels in second FragData, but I needn't that. Could is it possible to make discard in first FragData, but not in a second? P.S. Sorting solves this but I dont want to sort. Thanks. 
Getting a distance to thr fragment.
Turbochist replied to Turbochist's topic in Graphics and GPU Programming
Thanks! But how to calculate distance from camera eye to the pixel of the depth? And what if I use logarithm z ? Is it not matter? 
I try to get the distance to the 3d objects by clicking, and I've made some "float to rgba" coded framebuffer texture, then gets a rgba and decode to the float back. And it's good till I use blending(you understand)...But I know that there some other way to get the distance to the fragment trough the depth, but I dont understand how to make it step by step. Please could anybody help me to understand that problem, how to make depth texture, and how to retrieve real distance from eye to pixel from that. Thanks!

Directional lighting trouble.
Turbochist replied to Turbochist's topic in Graphics and GPU Programming
I've solved it! Thanks all. This is becouse I have to multyply direction to the normalMatrix. Mistake is I mul direction to modelView. 
Directional lighting trouble.
Turbochist replied to Turbochist's topic in Graphics and GPU Programming
attribute vec3 aVertexNormal; attribute vec3 aVertexPosition; attribute vec2 aTextureCoord; uniform mat4 uPMatrix; uniform mat4 uMVMatrix; uniform mat3 uNMatrix; varying vec2 vTextureCoord; varying vec3 vTransformedNormal; varying vec4 vPosition; void main(void) { vTransformedNormal = uNMatrix * aVertexNormal; vTextureCoord = aTextureCoord; vPosition = uMVMatrix * vec4(aVertexPosition, 1.0); gl_Position = uPMatrix * vPosition; } And frag: precision highp float; varying vec2 vTextureCoord; varying vec3 vTransformedNormal; varying vec4 vPosition; uniform vec4 uColor; uniform sampler2D uSampler; #define MAX_POINT_LIGHTS 1 uniform int pointLightsQuantity; uniform vec4 pointLightsPositions[MAX_POINT_LIGHTS]; uniform vec3 pointLightsParamsv[MAX_POINT_LIGHTS * 3]; uniform float pointLightsParamsf[MAX_POINT_LIGHTS]; void main(void) { vec3 lightWeighting; vec3 lightDirection; vec3 normal; vec3 eyeDirection; vec3 reflectionDirection; float specularLightWeighting; float diffuseLightWeighting; lightDirection = normalize(pointLightsPositions[0].xyz); //float distance = length(dir); //float attenuation = 1.0/(1.0+0.1*distance+0.01*distance*distance); normal = normalize(vTransformedNormal); eyeDirection = normalize(vPosition.xyz); reflectionDirection = reflect(lightDirection, normal); specularLightWeighting = pow(max(dot(reflectionDirection, eyeDirection), 0.0), pointLightsParamsf[0]); diffuseLightWeighting = max(dot(normal, lightDirection), 0.0); lightWeighting = pointLightsParamsv[0] + pointLightsParamsv[1] * diffuseLightWeighting + pointLightsParamsv[2] * specularLightWeighting; vec4 cc = texture2D( uSampler, vTextureCoord.st ); gl_FragColor = vec4(lightWeighting, uColor.a) * cc * uColor; } uNMatrix is normal matrix. I dont' know..where is a mistake? 
Directional lighting trouble.
Turbochist replied to Turbochist's topic in Graphics and GPU Programming
Ok I dont translate direction, but how to direct the light to fragment now? 
Directional lighting trouble.
Turbochist replied to Turbochist's topic in Graphics and GPU Programming
I made only direction that translate to model view, but nothing. 
Hi. I've stucked. Point light source works fine, but directional not. Help please. pointLightPosition.xyz = modelViewMatrix * lightPos; pointLightPosition.w = 0.0; //vertex ... vPosition = modelViewMatrix * vec4(aVertexPosition, 1.0); gl_Position = projectionMatrix * vPosition; //fragment ... vec3 normal = normalize(uNMatrix * vNormal); vec3 lightDirection; if(pointLightsPositions[0].w == 0.0){ lightDirection = normalize(pointLightPosition.xyz); }else{ lightDirection = normalize(pointLightPosition.xyz  vPosition.xyz); } vec3 eyeDirection = normalize(vPosition.xyz); float diffuseLightWeighting = max(dot(normal, lightDirection), 0.0); vec3 lightWeighting = ambient + diffuse * diffuseLightWeighting; ...

O'Neil atmosphere mountains bug.
Turbochist replied to Turbochist's topic in Graphics and GPU Programming
It is not a bug, it is becouse algorithm wwork with flat sphere. And I need to calculate scattering on the mountain. 
I'm using http://http.developer.nvidia.com/GPUGems2/gpugems2_chapter16.html And have a visual bug, when mountains higher than camera height. Here: Please help. P.S. next day i'll get with Brunetone scattering...

How to calculate lighting by point light with size of the lightsource like Sun?
Turbochist posted a topic in Graphics and GPU Programming
I calculate lightWeighting with that: lightDirection = normalize(pointLightsPosition  vPosition.xyz); normal = normalize(vTransformedNormal); eyeDirection = normalize(vPosition.xyz); reflectionDirection = reflect(lightDirection, normal); specularLightWeighting = pow(max(dot(reflectionDirection, eyeDirection), 0.0), pointLightsParamsf[0]); diffuseLightWeighting = max(dot(normal, lightDirection), 0.0); lightWeighting = ambient + diffuse * diffuseLightWeighting + specular * specularLightWeighting; It is point light source in pointLightsPosition, how to calculate lightWeighting if light source has a size like radius(Sun, lamp etc.)? Thanks. 
OpenGL GLSL optimization. What is faster?
Turbochist replied to Turbochist's topic in Graphics and GPU Programming
Yes! Thank you very much WiredCat and Alex! I think I understand. Thank you! 
I'm using OpenGL ES. And have two types of calculation "dir" vector, which code is fastest? attribute vec2 order; code1: if( abs(sinA) < 0.2 ) { if(order.x == 1.0){ dir = sNormalPrev; } else { dir = sNormalNext; } } else { dir *= order.x / sinA; } code2: float k = step(0.2, abs(sinA)); dir = k * dir * order.x / sinA  (k1.0) * (step(1.0, order.x + 1.0) * sNormalPrev + step(1.0, order.x + 1.0) * sNormalNext);

How to calculate sun and planets positions around the Earth by real date and time?
Turbochist replied to Turbochist's topic in Math and Physics
Actually I've used this calculations you can watch results on http://www.openglobus.org: It's not best like Simon's but good enough for me now and comparatively low calculations. og.math.TWO_PI = 2.0 * Math.PI; og.math.PI_TWO = Math.PI / 2.0; og.math.RADIANS = Math.PI / 180.0; og.math.DEGREES = 180.0 / Math.PI; // Angle between J2000 mean equator and the ecliptic plane. // 23 deg 26' 21".448 (Seidelmann, _Explanatory Supplement to the // Astronomical Almanac_ (1992), eqn 3.2221. og.astro.J2000_OBLIQUITY = 23.4392911; og.math.rev = function (x) { return x  Math.floor(x / 360.0) * 360.0; }; og.math.Quaternion.yRotation = function (a) { a *= 0.5; return new og.math.Quaternion(0.0, Math.sin(a), 0.0, Math.cos(a)); }; /** * http://stjarnhimlen.se/comp/tutorial.html * a Mean distance, or semimajor axis * e Eccentricity * T Time at perihelion * * q Perihelion distance = a * (1  e) * Q Aphelion distance = a * (1 + e) * * i Inclination, i.e. the "tilt" of the orbit relative to the * ecliptic. The inclination varies from 0 to 180 degrees. If * the inclination is larger than 90 degrees, the planet is in * a retrogade orbit, i.e. it moves "backwards". The most * wellknown celestial body with retrogade motion is Comet Halley. * * N (usually written as "Capital Omega") Longitude of Ascending * Node. This is the angle, along the ecliptic, from the Vernal * Point to the Ascending Node, which is the intersection between * the orbit and the ecliptic, where the planet moves from south * of to north of the ecliptic, i.e. from negative to positive * latitudes. * * w (usually written as "small Omega") The angle from the Ascending * node to the Perihelion, along the orbit. * * P Orbital period = 365.256898326 * a**1.5/sqrt(1+m) days, * where m = the mass of the planet in solar masses (0 for * comets and asteroids). sqrt() is the square root function. * * n Daily motion = 360_deg / P degrees/day * * t Some epoch as a day count, e.g. Julian Day Number. The Time * at Perihelion, T, should then be expressed as the same day count. * * t  T Time since Perihelion, usually in days * * M Mean Anomaly = n * (t  T) = (t  T) * 360_deg / P * Mean Anomaly is 0 at perihelion and 180 degrees at aphelion * * L Mean Longitude = M + w + N * * E Eccentric anomaly, defined by Kepler's equation: M = E  e * sin(E) * An auxiliary angle to compute the position in an elliptic orbit * * v True anomaly: the angle from perihelion to the planet, as seen * from the Sun * * r Heliocentric distance: the planet's distance from the Sun. * * x,y,z Rectangular coordinates. Used e.g. when a heliocentric * position (seen from the Sun) should be converted to a * corresponding geocentric position (seen from the Earth). */ og.astro.earth.getSunPosition = function (jd) { var d = jd  og.jd.J2000; var w = 282.9404 + 4.70935E5 * d; //longitude of perihelion var a = 1.000000; //mean distance, a.u. var e = 0.016709  1.151E9 * d; //eccentricity var M = og.math.rev(356.0470 + 0.9856002585 * d); //mean anomaly var oblecl = og.astro.J2000_OBLIQUITY  3.563E7 * d; //obliquity of the ecliptic var L = og.math.rev(w + M); //Sun's mean longitude var E = M + og.math.DEGREES * e * Math.sin(M * og.math.RADIANS) * (1 + e * Math.cos(M * og.math.RADIANS)); //eccentric anomaly //Sun rectangular coordiantes, where the X axis points towards the perihelion var x = Math.cos(E * og.math.RADIANS)  e; var y = Math.sin(E * og.math.RADIANS) * Math.sqrt(1  e * e); var r = Math.sqrt(x * x + y * y); // distance var v = Math.atan2(y, x) * og.math.DEGREES; // true anomaly var lon = og.math.rev(v + w); //longitude of the Sun //the Sun's ecliptic rectangular coordinates x = r * Math.cos(lon * og.math.RADIANS); y = r * Math.sin(lon * og.math.RADIANS); //We use oblecl, and rotate these coordinates var xequat = x; var yequat = y * Math.cos(oblecl * og.math.RADIANS); var zequat = y * Math.sin(oblecl * og.math.RADIANS); var theta = og.math.TWO_PI * (d * 24.0 / 23.9344694  259.853 / 360.0); // Siderial spin time return og.math.Quaternion.yRotation(theta).mulVec3(new og.math.Vector3(yequat * og.astro.AU_TO_METERS, zequat * og.astro.AU_TO_METERS, xequat * og.astro.AU_TO_METERS)); //Convert to RA and Decl //var RA = Math.atan2(yequat, xequat) * og.math.DEGREES; //var Decl = Math.atan2(zequat, Math.sqrt(xequat * xequat + yequat * yequat)) * og.math.DEGREES; }; Thanks guys!