Jump to content

Surface reflections


Michael_Chang

Recommended Posts

So I don't know whether or not this exists yet, but does anyone know how to create chrome/metallic dynamic reflections for aircrafts? i know ramzzess and danklau have done it, but after investigating with both of them, it turns out they can't be done for big parts like wings and fuselage. does anyone know a system that works with fuselage parts that will create dynamic reflections that are clear and sharp?

Link to comment
Share on other sites

Got a link to some video of Dan and Ramzzes work?

well dan used this object design to make it happen, his chrome engine rims rotate with the pitch of the plane so that it looks like the reflections,

ramzzess's 777 uses a cockpit object htat moves back and forth to simulate reflections, si it's actually object based, not texture based

Link to comment
Share on other sites

i asked him earlier, about the same question, he gave me a great answer!

-google

well, i extensively searched around, but i cant find anything, and even i trie to download GLSL shader samples and tried to implement it to x-plane...i failed :P

i wanted this kind of things so my windows in my airport buildings can be reflective.....

maybe his reply was like that because he wanted to keep it a secret? like KFC's secret recipe :D

Edited by Peter T.
  • Upvote 1
Link to comment
Share on other sites

Oh sorry that came out wrong i meant on this subject i tried for a couple days now and couldn't find it. So i thought since adults are a bit better at serching (because they have experience) then they might find it faster but i will look again.

Thanks for the PUSH in the right direction :)

- Remlap -

Link to comment
Share on other sites



#ifndef __XGL_SHADER__
#define __XGL_SHADER__


/*
#if IBM
#include "GL/glu.h"
#include "GL/glext.h"
#else
#include <OpenGL/glu.h>
#include <OpenGL/glext.h>
#endif
*/
//usefull STL classes
//#include "X_STL.h"


#define printOpenGLError() this->printOglError(__FILE__, __LINE__)

class XGLShader{
public:
int compileShaders( const char *shdrVertex, const char *shdrFragment );

void enable();
void disable();

void setUniFloat( const char *name, float fV );

GLhandleARB sp; // <-- shaders handle for openGL.

//private:
int validShader; //will only set to 1 if the compile succeeds. controls enable disable logic too.

void printOglError( char *file, int line );
void printInfoLog(GLhandleARB obj);

GLint getUniLoc(GLhandleARB program, const GLcharARB *name);
protected:

};





#endif



void XGLShader::printOglError( char *file, int line ){
GLenum glErr;
int retCode = 0;
char *err;

// returns 1 if an OpenGL error occurred, 0 otherwise.

glErr = glGetError();
while (glErr != GL_NO_ERROR) {
err = (char*)gluErrorString(glErr);
fprintf(stderr,"file: %s \n line: %d \n glError: %s\n",file,line,err);
retCode = 1;
glErr = glGetError();
}
//return retCode
};


void XGLShader::printInfoLog(GLhandleARB obj)
{
int infologLength = 0;
int charsWritten = 0;
GLcharARB *infoLog;

printOpenGLError(); // Check for OpenGL errors

glGetObjectParameterivARB(obj, GL_OBJECT_INFO_LOG_LENGTH_ARB,
(GLint*)&infologLength);
printOpenGLError(); // Check for OpenGL errors

if (infologLength > 0)
{
infoLog = (GLcharARB*)malloc(infologLength);
if (infoLog == NULL)
{
printf("ERROR: Could not allocate InfoLog buffer\n");
exit(1);
}
glGetInfoLogARB(obj, infologLength, (GLint*)&charsWritten, infoLog);
printf("InfoLog:\n%s\n\n", infoLog);
free(infoLog);
}
printOpenGLError(); // Check for OpenGL errors
}



GLint XGLShader::getUniLoc(GLhandleARB program, const GLcharARB *name)
{
GLint loc;

loc = glGetUniformLocationARB(program, name);

if (loc == -1)
printf("No such uniform named \"%s\"\n", name);

printOpenGLError(); // Check for OpenGL errors
return loc;
}




int XGLShader::compileShaders( const char *shdrVertex, const char *shdrFragment )
{

GLhandleARB shdrVS, shdrFS;//, shdrProg; // handles to objects
GLint vertCompiled, fragCompiled; // status values
GLint linked;

// Create a vertex shader object and a fragment shader object

shdrVS = glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB);
shdrFS = glCreateShaderObjectARB(GL_FRAGMENT_SHADER);
// Load source code strings into shaders



glShaderSourceARB(shdrVS, 1, &shdrVertex, NULL);
glShaderSourceARB(shdrFS, 1, &shdrFragment, NULL);



// Compile the shdr vertex shader and print out
// the compiler log file.

glCompileShaderARB(shdrVS);
printOpenGLError(); // Check for OpenGL errors
glGetObjectParameterivARB(shdrVS,
GL_OBJECT_COMPILE_STATUS_ARB, &vertCompiled);
this->printInfoLog(shdrVS);

// Compile the shdr vertex shader and print out
// the compiler log file.

glCompileShaderARB(shdrFS);
printOpenGLError(); // Check for OpenGL errors
glGetObjectParameterivARB(shdrFS,
GL_OBJECT_COMPILE_STATUS_ARB, &fragCompiled);
this->printInfoLog(shdrFS);

if (!vertCompiled || !fragCompiled)
return 0;
// Create a program object and attach the two compiled shaders

this->sp = glCreateProgramObjectARB();
glAttachObjectARB(this->sp, shdrVS);
glAttachObjectARB(this->sp, shdrFS);

// Link the program object and print out the info log

glLinkProgramARB(this->sp);
printOpenGLError(); // Check for OpenGL errors
glGetObjectParameterivARB(this->sp,
GL_OBJECT_LINK_STATUS_ARB, &linked);
this->printInfoLog(this->sp);

if (!linked)
return 0;

// Install program object as part of current state

//glUseProgramObjectARB(shdrProg);

// Set up initial uniform values

//glUniform3fARB( getUniLoc(shdrProg, "BrickColor"), 1.0, 0.3, 0.2);
//glUniform3fARB( getUniLoc(shdrProg, "MortarColor"), 0.85, 0.86, 0.84);
//glUniform2fARB( getUniLoc(shdrProg, "BrickSize"), 0.30, 0.15);
//glUniform2fARB( getUniLoc(shdrProg, "BrickPct"), 0.90, 0.85);
//glUniform3fARB( getUniLoc(shdrProg, "LightPosition"), 0.0, 0.0, 4.0);

this->validShader = 1;

return 1;
}

void XGLShader::setUniFloat( const char *name, float fV ){
glUniform1fARB( getUniLoc(this->sp, name), fV );
//printf("set uni float %s to: %f\n", name, fV);
}


void XGLShader::enable(){
if( this->validShader ){
//we need this in versions of x-plane prior to about 8.4 or 8.5 that did not have native shader support
//glEnable(GL_VERTEX_PROGRAM_ARB);
//glEnable(GL_FRAGMENT_PROGRAM_ARB);

glUseProgramObjectARB( this->sp );

}else{
printf("XGLShader - tried to enable an invalid shader instance. Ignored.\n");
}
}

void XGLShader::disable(){
if( this->validShader ){
//we need this in versions of x-plane prior to about 8.4 or 8.5 that did not have native shader support
//glDisable(GL_VERTEX_PROGRAM_ARB);
//glDisable(GL_FRAGMENT_PROGRAM_ARB);

glUseProgramObjectARB( 0 );
}
}


  • Upvote 1
Link to comment
Share on other sites

  • Create a new plugin project.
  • Import the code above.
  • Use the code above to load and compile shader scripts of your choice.
  • Create appropriate drawing callbacks that fire at the desired phase of X-Planes rendering system.
  • Call the code above that enables shader drawing.
  • Draw custom mesh loaded by your own code. (Eg: You'll need to write/find an OBJ8/FBX reader too.)
  • Call the code above that disables shader drawing.

Or, you can look into Gizmo, which has a shader API, and makes all of the above far far easier.

Link to comment
Share on other sites

it's not that i'm asking you to create it for me, i would like to learn! although i can't access the link for obvious reasons

There are two aspects to the word 'learn' here:

1.) Learn how to do it

2.) Learn how its done

These are different. #1 means pretty much being a full-fledge experienced programmer with higher education (read college) level of knowledge. #2 is simply satistying your curiosity...and that is much easier to explain. There are NO true reflections in X-Plane. There will be NO true reflections in x-plane for many many years to come. Dan Klaue and Roman have done what are called "hacks", albeit they are good hacks and the "ideas" for coming up with these hacks are diverse.

The best reflective effect (as accepted in the industry) is done with OpenGL custom programming and with shaders and only BenR here has done it in XP thus far. X-Plane's shader engine presents lots of challenges and obstacles with implementing shader tech though...so until Laminar implments "reflections" on OBJs, I wouldn't expect to see it.

-Tom

Edited by tkyler
  • Upvote 1
Link to comment
Share on other sites

Give a man a fire and he'll be warm for a day.

Set a man on fire and he'll be warm for the rest of his life.

Nothing like OpenGL to keep your head warm! On all the many occasions (both of them) when I tried to learn to use it, I couldn't even compile the Hello World example.

Link to comment
Share on other sites

  • 1 month later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...