qwert_e Posted January 24, 2019 Posted January 24, 2019 (edited) When i tried to create stars using star generator, i figured out that stars magnitude (parameter that determine star visibility) does not handled correctly by generator. Star magnitude is inverse to star brightness, and star generator makes most low-visible stars to be more brighter, so i could not find any familiar constellations on the generated sky. Can you share the piece of code that handles magnitude on generation? Edited January 24, 2019 by qwert_e
silent Posted January 25, 2019 Posted January 25, 2019 qwert_e Here is the code from Editor1 (UnigineScript): void create_clicked() { if(strlen(catalog_el.getText()) == 0) { dialogMessageOk(TR("Error"),TR("Select catalog")); return; } File file = new File(); if(file.open(catalog_el.getText(),"rb") == 0) { dialogMessageOk(TR("Error"),format(TR("Can't load \"%s\" star catalog\n"),catalog_el.getText())); delete file; return; } billboards.clearBillboards(); class Star { float phi; float theta; float mag; string type; Star(float phi_,float theta_,float mag_,string type_) { phi = phi_; theta = theta_; mag = mag_; type = type_; } int operator<(Star s0,Star s1) { return (s0.mag > s1.mag); } }; Star stars[0]; float min_mag = INFINITY; float max_mag = -INFINITY; while(file.eof() == 0) { string line = file.readLine(); string get_bytes(int from,int to) { string ret = ""; if(strlen(line) < to) return ret; for(int i = from; i <= to; i++) { ret += format("%c",line[i - 1]); } return ret; } float rah = float(get_bytes(6,7)); float ram = float(get_bytes(9,10)); float ras = float(get_bytes(12,17)); float decd = float(get_bytes(27,29)); float decam = float(get_bytes(31,32)); float decas = float(get_bytes(34,38)); float mag = float(get_bytes(124,128)); string type = get_bytes(131,132); float theta = PI2 * (rah + (ram + ras / 60.0f) / 60.0f) / 24.0f; float phi = -PI * (decd + (decam + (decas / 60.0f)) / 60.0f) / 90.0f; stars.append(new Star(phi,theta,mag,type)); min_mag = min(min_mag,mag); max_mag = max(max_mag,mag); } stars.sort(); string types[] = ( 'O' : 0, 'B' : 1, 'A' : 2, 'F' : 3, 'G' : 4, 'K' : 5, 'M' : 6 ); forloop(int i = 0; min(count,stars.size())) { Star star = stars[i]; if(types.check(star.type[0]) == 0) continue; float r = angle * pow((star.mag - min_mag) / (max_mag - min_mag),3.0f); int atlas_x = clamp(int(16.0f * (max_mag - star.mag) / (max_mag - min_mag)),0,15); int atlas_y = types[star.type[0]]; int num = billboards.addBillboard(r,r); billboards.setTexCoord(num,vec4(1.0f / 16.0f,1.0f / 8.0f,atlas_x / 16.0f,atlas_y / 8.0f)); billboards.setAngle(num,engine.game.getRandom(0.0f,360.0f)); float phi = star.phi + latitude * DEG2RAD; float theta = star.theta + longitude * DEG2RAD; billboards.setPosition(num,vec3(cos(phi) * cos(theta),-cos(phi) * sin(theta),sin(phi)) * radius); } stars.delete(); file.close(); delete file; Billboards::update(); } If you can spot an error here - please let us know :) I belive we used FK5 star catalog from here: http://www-kpno.kpno.noao.edu/Info/Caches/Catalogs/FK5/fk5.html Thanks! How to submit a good bug report --- FTP server for test scenes and user uploads: ftp://files.unigine.com user: upload password: 6xYkd6vLYWjpW6SN
qwert_e Posted January 25, 2019 Author Posted January 25, 2019 (edited) float min_mag = INFINITY; float max_mag = -INFINITY; ... min_mag = min(min_mag,mag); max_mag = max(max_mag,mag); min_mag must be highest from all mags, min(min_mag,mag) will choose not the highest and thats below will be more correct: float min_mag = -INFINITY; float max_mag = INFINITY; min_mag = max(min_mag,mag); max_mag = min(max_mag,mag); in the line: float r = angle * pow((star.mag - min_mag) / (max_mag - min_mag),3.0f); angle should be parameter "angle" in star generator, right? then if its right, brighest star FK5 257 "SIRIUS A" with magnitude -1.46 will have r = angle*1 and FK5 1657 with magnitude 8.28 will have r = angle*0 catalog should be that in attached files catalog Edited January 25, 2019 by qwert_e
silent Posted January 25, 2019 Posted January 25, 2019 Thanks, we will take a closer look into this before the next SDK update. How to submit a good bug report --- FTP server for test scenes and user uploads: ftp://files.unigine.com user: upload password: 6xYkd6vLYWjpW6SN
moroz Posted January 29, 2019 Posted January 29, 2019 @qwert_e Hi! If you want get simply stars skymap you should use data\ig\sky_map\textures\stars_c.hdr from IG template as environment texture.
Recommended Posts