Re: Bump mapping for Animated meshes
Posted: Tue Sep 15, 2015 9:34 pm
I don't like your specular is that blinn-phong specular?
Official forum of the Irrlicht Engine
https://irrlicht.sourceforge.io/forum/
Code: Select all
.makeInverse():
Code: Select all
getTransposed();
Code: Select all
// - V E R T E X P R O G R A M -
uniform mat4 mWorld;
varying vec3 Tangent;
varying vec3 Binormal;
varying vec2 UVCoordsXY;
varying vec3 VNormal;
varying vec3 VertexGLPosition;
void main()
{UVCoordsXY = gl_MultiTexCoord0.xy;
// Are these normalisations really necessary?
// Tangent = normalize(gl_MultiTexCoord1); // Acuired here and passed on to the FRAGMENT SHADER
// Binormal = normalize(gl_MultiTexCoord2); // (make sure about skipping this!!!)
// Is a normalisation quicker here or quicker in the appcode?
Tangent = gl_MultiTexCoord1; // Acuired here and passed on to the FRAGMENT SHADER..
Binormal = gl_MultiTexCoord2; // (make sure about skipping the normalisation!!!)
VNormal = gl_Normal; // Unseen normal passed from the User App.. Must happen here..
// VNormal = normalize(vec3(mWorld * vec4(VNormal.xyz, 0 )).xyz); // Model your normals correctly!
VNormal = vec3(mWorld * vec4(VNormal.xyz, 0 )).xyz; // Looks like we got away with this..
Tangent = normalize(vec3(mWorld * vec4(Tangent.xyz, 0 )).xyz); // "mWorld" is our "Golden Thread"..
Binormal = normalize(vec3(mWorld * vec4(Binormal.xyz,0)).xyz);
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; // "glModelview...." is mostly UNSEEN, and ensures that Object "ROTATION" is considered..
VertexGLPosition = vec3(mWorld * vec4(gl_Vertex.xyz,1)).xyz; // This ensures that Object "TRANSLATION" and "SCALE" is considered..
}
}
Code: Select all
// - FR A G M E N T S H A D E R -
uniform sampler2D DiffuseMap; // The "ClipMap" is determined (among others) in the Diffuse ALPHA Channel (we need to override the A if the image was 24 bit to be sure)..
uniform sampler2D NSGMap; // Normal Specular and Gloss in four bytes. The Normal map was in "Y-Up" standard..
uniform sampler2D EmissionMap; // RGB values not influenced by any calclations. Simulated Emmision..
uniform sampler2D Image004; // Still worked
uniform sampler2D Image005; // Engine had to be recompiled for this! (not simply a change in the API "irrCompileConfig.h" file)
uniform sampler2D Image006; // Without the recompiled "irrlicht.dll" file in the system or app directory these wont appear!
uniform sampler2D Image007; // New dll and lib was needed by recompiling irrlicht engine code with change in compile options header file..
uniform sampler2D Image008;
uniform int GPURendermode; // An Integer that is controlled from the program used to change the RENDER MODE of this Fragment Shader (press buttons 1 to 0..)
uniform int GpuPLAECFActive; // PLAECF Implemented ot not. (ON by default).. (can we pass BOOLS to the shader?) If you make millions I wantin!
uniform mat4 GPUFloatArray; // In the form of a "MATRIX4" Variable, but used here as an Array of [4][4] i.e. 16 floats..
// A cool way to talk to the shader via ONE VARIABLE in a bandwidth of 16 floating point numbers!!..
// We can go crazy in our app with floats in the shader!!
// We can animate hoards of lights and even animate their colour!
// We could also have conditionally rendered "Falloff lights" and all their parameters..
// We could have vertex or bone linked "Negative Radiators" to simulate superfast soft shadows and AO..
// The same goes for "radiating lines" which Im currently looking at.
// (interesting concept youre sure to see more of)
// Tables should be set up on which parts of the "mat4" would be assigned to which info like Position, colour, falloff etc..
// While Glossyness is a mainly a "Material Specific Atribute", we can, as seen in photography have
// "diffusion lights" and have in here some way to control it (debatable)..
// These "Special Lights" do not result (at least not visibly) in shiny specular highlights on even a "Glossy" surface..
// We could have this comm-bandwidth for the Vertex Program too!
uniform vec3 SECONDFloatArray[]; // How do we pass arrays of values without having to conform to GLSL datatypes ???
uniform vec4 CameraPos; // The Position of the camera i.e. the EYE, is what the main calculations are fed..
// For demostrative purposes we have a one light hooked to the camera..
uniform vec3 LightPos001; // This could eventually become an ARRAY filled with Irrlicht Light Positions (allmost solved and now very possible)..
varying vec2 UVCoordsXY; // Passed on to here from the Vertex Program..
varying vec3 VNormal; // Effectively (interpolated?) "Fragment Normal" after passing through the Vertex Progam.
// The success of "Radiating Finite Lines" depend on how successfully GLSL does this. (CG does a good job)..
// There is a trick that has to do with the quality of this interpolation in CG..
varying vec3 Tangent; // Lovely things!
varying vec3 Binormal; // BiNormal and NOT BiTangent.. (as per accepted standard like "DVD" not really meaing anything)
varying vec3 VertexGLPosition; // UNSEEN GLSL (attribute) thing as also occurs in HLSL, FX, CG, and CGFX methods..
varying vec3 LightColour; // Not fed from our user app yet, but high on the priority list..
// We need an array of lights from the scene which is either processed
// for "importance" by the CPU in the code or in here by the GPU..
// =============================================================================
vec4 Interpolate(float Slider, vec4 ArgA, vec4 ArgB)
{vec4 OutputVal = ArgB * Slider + ArgA * (1 - Slider);
return OutputVal;
} // I thought "mix" could do this, but it doesnt???
// = M A I N = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
void main()
{bool DropletEnabled = 1; // A special efect for "Glassy" Surfaces..
// normalize (VNormal); // If not normalised in Vertex Program or properly normalised during Modelling..
vec4 MAPDiffuseRGBA = texture2D(DiffuseMap,UVCoordsXY.xy); // ALPHA is "Clipmap"..
vec4 FinalDiffuse = MAPDiffuseRGBA;
vec4 MapNSGRGBA = texture2D(NSGMap,UVCoordsXY.xy); // ALPHA is "Droplet Shader Mask"..
vec4 MAPSpecXGlossY; // = texture2D(SpecGlossMap,UVCoordsXY.xy); // Specila MIXED Specular and Gloss..
vec4 MAPEmissionRGB = texture2D(EmissionMap,UVCoordsXY.xy); // Emmision Mapping for wider effect domain..
vec4 MapRGBA004 = texture2D(Image004,UVCoordsXY.xy);
vec4 MapRGBA005 = texture2D(Image005,UVCoordsXY.xy);
vec4 MapRGBA006 = texture2D(Image006,UVCoordsXY.xy);
vec4 MapRGBA007 = texture2D(Image007,UVCoordsXY.xy);
vec4 MapRGBA008 = texture2D(Image008,UVCoordsXY.xy);
// == MAPPED DIFFUSE BRIGHTNESS CHANGES FROM USER APP ==
FinalDiffuse.xyz *= GPUFloatArray[0][2]; // Multiply these in here with value passed from user app.. [[FIXXXX]]
// MAPDiffuseRGBA.xyz *= GPUFloatArray[0][2]; // Multiply these in here with value passed from user app..
// == MAPPED SPECULAR / REFLECTIVE INTENSITY CHANGES FROM USER APP ==
MapNSGRGBA.z *= GPUFloatArray[0][0];
// == MAPPD GLOSS / SHINYNESS CHANGES FROM USER APP ==
MapNSGRGBA.w += GPUFloatArray[0][1]; // See the "LAECF" at work!
// This "fixes" a copy of any incoming UVs that fall outside of the 1.0 Unit Square..
// This is mainly done so that when we render the UVs (via this copy) in X=Red Y=Green for tests.
// Delete this procedure and its variables when you no longer want to see your UVs as modelled.
// It has no bearing on the Final Render..
vec2 RenderedUVs = UVCoordsXY;
if (RenderedUVs.x < 0.0){RenderedUVs.x += 1.0;}
if (RenderedUVs.x > 1.0){RenderedUVs.x -= 1.0;}
if (RenderedUVs.y < 0.0){RenderedUVs.y += 1.0;}
if (RenderedUVs.y > 1.0){RenderedUVs.y -= 1.0;}
// Tests.. Emulate a "Flat Blue Normal Map" to see other things like specular without the bumps..
/*
MapNSGRGBA.x = 0.5; // where 0.5 refers to ZERO on the imaginary X axis..
MapNSGRGBA.y = 0.5; // See "Range compression" of NSGMaps..
MapNSGRGBA.z = 1.0; // Note that an even higher resolution is possible when we dont use the negative values (in most cases!)..
//*/
// Tests.. Emulate a "Single Colour" SPEC_GLOSS map to see the model as if it was rendered without fixed Spec or GLoss..
/*/
MapNSGRGBA.z = 1.0; // 1.0 is the Maximum Mappable "Intensity" (Brightness) for speclar highlight..
MapNSGRGBA.w = 1.0; // 1.0 is the Maximum mappable "Average Gloss Radius" (Shinyness) for Speclar Highlights..
// In here we can exceed 1.0 for both values..
//*/
// Tests.. Replace the "Mapped Diffuse Colour" by any other colour..
/*
MAPDiffuseRGBA.x = 0.5;
MAPDiffuseRGBA.y = 0.5;
MAPDiffuseRGBA.z = 0.5;
//*/
// -- Replace the Diffuse Colour with Simple Greyscale. (not the true accurate optical formula) --
/*
vec3 Greyscaled; // An average of RGBA colours..
Greyscaled.x = ( MAPDiffuseRGBA.x + MAPDiffuseRGBA.y + MAPDiffuseRGBA.z ) / 3.0;
Greyscaled.y = ( MAPDiffuseRGBA.x + MAPDiffuseRGBA.y + MAPDiffuseRGBA.z ) / 3.0;
Greyscaled.z = ( MAPDiffuseRGBA.x + MAPDiffuseRGBA.y + MAPDiffuseRGBA.z ) / 3.0;
MAPDiffuseRGBA.xyz = Greyscaled.xyz;
// --------------------------------------------------
//*/
vec4 LerpSliderDiffmap; // How much is the final render is "lerped" toward the Originally Mapped Raw Diffuse Colour..
// We want this controlled from the User App..
vec3 UnCompressedNormal;
// We IGNORE the incoming Z value (now another free channel) as we use a derivative of Pythagoras's Theorem to aquire Z..
UnCompressedNormal.xy = (MapNSGRGBA.xy -0.5) * 2.0;
// The "droplet" mask will also have to fit into the Diffuse Alpha. Which is very possible as we use the alpha channel for "Clipmapping".
// Now, Clipmapping requires only a small contrast between pixel intensity allowing us to assign this droplet mask
// to, say, a value of anything above 60% and as a bonus still giving us a "smooth" border which we shall define in the shader..
// We could cut of the intensity between 60% and 100% as a finite line which we then convert to a "softness"
// for the Droplet Mask..
// CALCULATE Z ON THE FLY USING A DERIVATIVE OF PYTHAGORAS'S THEOREM!!
UnCompressedNormal.z = sqrt(-(UnCompressedNormal.x*UnCompressedNormal.x) - (UnCompressedNormal.y*UnCompressedNormal.y) + 1.0);
// This is aquired by "Solving For" the Z variable in the Pythagorean Theorem, given X, Y and 1.0 (as normals modules are 1.0)..
// Because of Quadrarics there are a Negative and a Positive answer to this! We must select the RIGHT ONE!
// There! I did all the hard work for you!! :)..
// normalize(UnCompressedNormal); // Only if your normal baking wasn't cool. (neglible)
// - LIGHTS - // We need a sensible way to get these from our app..
// For now we control them in here..
LightPos001 = CameraPos.xyz; // So we have at least one moving light..
vec3 LightPos002 = vec3( 0.0 , -100.0 , 0.0);
vec3 LightPos003 = vec3( 0.0 , 100.0 , 0.0);
vec3 LightPos004 = vec3( 0.0 , 100.0 , 0.0);
LightPos004.x = LightPos001.y + 0.0; // Just to get it to move differently from the camera..
LightPos004.y = LightPos001.z + 0.0;
LightPos004.z = LightPos001.x + 0.0;
// Light colouring should come from the user app.. We'll do this once we have a good basis to work from..
vec3 LightCol001 = vec3( 1.0 , 1.0 , 1.0 );
LightCol001.xyz *= 1.00; // Global Intensity Scale.
// vec3 LightCol002 = vec3( 1.0 , 0.1 , 0.0 ); LightCol002.xyz *= 0.90; // Global Intensity Scale.
vec3 LightCol002 = vec3( 0.5 , 0.0 , 0.0 );
LightCol002.xyz *= 1.0; // Global Intensity Scale.
vec3 LightCol003 = vec3( 0.0 , 0.5 , 0.5 );
LightCol003.xyz *= 1.0; // Global Intensity Scale.
vec3 LightCol004 = vec3( 1.0 , 0.5 , 0.0 );
LightCol004.xyz *= 1.0; // Global Intensity Scale.
// Simply different lighting setups to play with..
if (GPURendermode == 11) {LightCol001.xyz *= 1; LightCol002.xyz *= 1; LightCol003.xyz *= 1; LightCol004.xyz *= 1; }
if (GPURendermode == 12) {LightCol001.xyz *= 0; LightCol002.xyz *= 1;LightCol003.xyz *= 1; LightCol004.xyz *= 1;}
if (GPURendermode == 13) {LightCol001.xyz *= 1; LightCol002.xyz *= 0; LightCol003.xyz *= 0; LightCol004.xyz *= 0;}
// Global Lighting Multiplier (will be looped when we get lights from Irrlicht)..
LightCol001.xyz *= float (GPUFloatArray[1][0]);
// LightCol002.xyz *= float (GPUTestFloatArray.x);
LightCol002.xyz *= float (GPUFloatArray[1][0]);
LightCol003.xyz *= float (GPUFloatArray[1][0]);
LightCol004.xyz *= float (GPUFloatArray[1][0]);
// IMPORTANT.. Use Tangents and Binormals to FIX the final normal..
// This was quite a Headache but now it works Perfectly!
vec3 FinalNormal;
FinalNormal = normalize((UnCompressedNormal.x * Tangent)
+(UnCompressedNormal.y * Binormal)
+(UnCompressedNormal.z * VNormal));
// =============================================================
// What follows is a "Broken Down" version of the above for you to see how it works..
// Comment the one and uncomment the other to see..
// =============================================================
/*
vec3 AddA; vec3 AddB; vec3 AddC;
// - T A N G E N T -
AddA.x = UnCompressedNormal.x * Tangent.x; // WAS STATIC, NOW DYNAMIC!
AddA.y = UnCompressedNormal.x * Tangent.y;
AddA.z = UnCompressedNormal.x * Tangent.z;
// - B I N O R M A L -
AddB.x = UnCompressedNormal.y * Binormal.x; // WAS STATIC, NOW DYNAMIC!
AddB.y = UnCompressedNormal.y * Binormal.y;
AddB.z = UnCompressedNormal.y * Binormal.z;
// - V E R T E X N O R M A L - (updated with skinned deformation)
AddC.x = UnCompressedNormal.z * VNormal.x; // DYNAMIC !!
AddC.y = UnCompressedNormal.z * VNormal.y;
AddC.z = UnCompressedNormal.z * VNormal.z;
vec3 AddFin;
AddFin.x = AddA.x + AddB.x + AddC.x;
AddFin.y = AddA.y + AddB.y + AddC.y;
AddFin.z = AddA.z + AddB.z + AddC.z;
FinalNormal = normalize (AddFin);
//*/
// DO NOT TRY TO CALCULATE THE BINORMALS IN THE SHADER..
// The BINORMAL IS "NOT" ALWAYS A SIMPLE CROSS PRODUCT BETWEEN TANGENT AND NORMAL!!
// =============================================================
// - NORMALISED DIRECTIONS - (used for Diffuse and Specularity)
vec3 ViewDir = normalize(CameraPos - VertexGLPosition);
vec3 LightDir001 = normalize(LightPos001 - VertexGLPosition); // Fragment Position??
vec3 LightDir002 = normalize(LightPos002 - VertexGLPosition);
vec3 LightDir003 = normalize(LightPos003 - VertexGLPosition);
vec3 LightDir004 = normalize(LightPos004 - VertexGLPosition);
// DIFFUSE BASE FOR ALL LIGHTS..
float DiffBASE001 = max(dot(FinalNormal, (LightDir001)),0.0);
float DiffBASE002 = max(dot(FinalNormal, (LightDir002)),0.0);
float DiffBASE003 = max(dot(FinalNormal, (LightDir003)),0.0);
float DiffBASE004 = max(dot(FinalNormal, (LightDir004)),0.0);
// MULTIPLY BY INDIVIDUAL LIGHT COLOURS..
vec3 DiffColByLight001 = DiffBASE001 * LightCol001; // All xyz..
vec3 DiffColByLight002 = DiffBASE002 * LightCol002;
vec3 DiffColByLight003 = DiffBASE003 * LightCol003;
vec3 DiffColByLight004 = DiffBASE004 * LightCol004;
// FINAL COLOURED DIFFUSE MIX..
vec3 FinalDiffLightsColed = DiffColByLight001 + DiffColByLight002 + DiffColByLight003 + DiffColByLight004; // Combine the diffuse results of different lights..
// S P E C U L A R I T Y versus G L O S S..
// Specularity is the amount of Light reflected or intensity of the Specular highlight (mathematically similar to reflection),
// where Gloss is the Size of that Highlight..(Unpolished Metal Gloss has a "bigger" highlight and lower Specularity whereas
// a shiny Apple would have a "smaller" highlight and higher specularity)..
// The following procedure is the result of an in-depth study in the physics of light and is
// "Highly Protected Academic Intellectual Property"..:) (only if you make millions with your game or app!!) You can still use it!
// Here is the Standard "Phongs Method" for generating "Specular Highlights" on a surface..
// It is very cool, but has one very big weakness.. How does the artist who makes a Glossmap know which level of grey would correspond
// to which "Tightness" of the Specuar Highlight? Many have tried, and many have failed!
// However, Phong works fine and you can still contoll the "General Glossyness" changeing the "77.777" value in the lines below..
// The "Gloss Controll" also still works but not like we would like it..
// "PLAECF" is MUCH BETTER though and promisses to change things throughout the CG world forever..
// Try using "K" and "L" (gloss param) with "PLAECF" active and then try "PLAECF" Deactivated to see what "PLAECF" actually means..
// Without "PLAECF", having a Glossmap as a human-understandable or generateable "Greyscale Map" is SIMPLY NOT POSSIBLE
// as many coders of graphics apps and games have discovered!
// (I could point to a few examples) In fact if there was any successful implementations out there before today, Id like to know of it!
// The imporance of "PLAECF" will become apparent in time and you'll understand why I want to keep the credit for being the
// sole developer of the formula!!
float SpecBASE001; float SpecBASE002; float SpecBASE003; float SpecBASE004; // Specular intensity from all lights (position and not colour, yet)..
if (GpuPLAECFActive == 0)
{SpecBASE001 = clamp(pow(clamp(dot(normalize((ViewDir + LightDir001)),FinalNormal),0.0,1.0), MapNSGRGBA.w * 77.777 ), 0.0 , 1.0 ); // A (alpha) for Gloss!!
SpecBASE002 = clamp(pow(clamp(dot(normalize((ViewDir + LightDir002)),FinalNormal),0.0,1.0), MapNSGRGBA.w * 77.777 ), 0.0 , 1.0 ); //
SpecBASE003 = clamp(pow(clamp(dot(normalize((ViewDir + LightDir003)),FinalNormal),0.0,1.0), MapNSGRGBA.w * 77.777 ), 0.0 , 1.0 ); //
SpecBASE004 = clamp(pow(clamp(dot(normalize((ViewDir + LightDir004)),FinalNormal),0.0,1.0), MapNSGRGBA.w * 77.777 ), 0.0 , 1.0 ); //
}
// That was "Phong"s Specularity method..
// start **** PLAECF ***
if (GpuPLAECFActive == 1)
{// "PLAECF" ACTIVATED!!
SpecBASE001 = clamp(pow(clamp(dot(normalize((ViewDir + LightDir001)),FinalNormal),0.0,1.0), pow(2, (MapNSGRGBA.w * 10.0)) ), 0.0 , 1.0 );
SpecBASE002 = clamp(pow(clamp(dot(normalize((ViewDir + LightDir002)),FinalNormal),0.0,1.0), pow(2, (MapNSGRGBA.w * 10.0)) ), 0.0 , 1.0 );
SpecBASE003 = clamp(pow(clamp(dot(normalize((ViewDir + LightDir003)),FinalNormal),0.0,1.0), pow(2, (MapNSGRGBA.w * 10.0)) ), 0.0 , 1.0 );
SpecBASE004 = clamp(pow(clamp(dot(normalize((ViewDir + LightDir004)),FinalNormal),0.0,1.0), pow(2, (MapNSGRGBA.w * 10.0)) ), 0.0 , 1.0 );
}
// end **** PLAECF ***
// WITH RECENT THE ADVENT OF OCULUS RIFT AND CONSIDERING THE POSSIBILITIES, THE ISSUES WITH THE ABOVE PROCEDURE SHOULD BE REITERATED AND THUS YOU ARE INFORMED
// THAT THE USE OF IT OR ANY DERIVATIVE THEREOF IN ANY COMMERCIAL MATERIAL IS PROHIBITED BAR MY PERSONAL WRITTEN PERMISSION.
// PLEASE CONTACT ME FOR LEGAL INFORMATION.
vec3 SpecBasColled001 = LightCol001.xyz * SpecBASE001 ; // Now the Light Colours comes into it..
vec3 SpecBasColled002 = LightCol002.xyz * SpecBASE002 ;
vec3 SpecBasColled003 = LightCol003.xyz * SpecBASE003 ;
vec3 SpecBasColled004 = LightCol004.xyz * SpecBASE004 ;
vec3 SpecColforAllLights = (SpecBasColled001 + SpecBasColled002 + SpecBasColled003 + SpecBasColled004); // Will be in a loop..
// SPECULAR (quite colourless in itself) is mathematically based on REFLECTION and should thus reflect LIGHT COLOUR..
vec3 SpecularColour;
SpecularColour.xyz = MapNSGRGBA.z * SpecColforAllLights.xyz;
// This is still quite GREY, but will change to colour depending on light colour.
// We use ".z" (blue) from "NSGMap" for the "Specular Intensity" and ".w" (alpha) for the Gloss..
// Test render the "Emmision Map" in a darkened scene..
// The other parts of this Shader Command is under // - SHADER COMMAND - later
// This is done here so we can dim the lights..
if (GPURendermode == 10) {FinalDiffLightsColed.xyz *= 0.3; SpecularColour.xyz *= 0.6;}
// keep in mind that this (above) would eventually be a loop of some sort to handle
// all the lights once we have more lights and a good system to feed the lights from the main program..
// =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=
// =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=
// -- DROPLET SHADER EFFECT --
// Droplet Shading simulates the effect created when a light shines on, for instance,
// a red round glassy gem in a ring where we have a Specular Highlight and then also a
// reversed-bigger sort of highlight that is the same colour as the
// material which the gem is made of..
// This effect is useful for, well, gems and particularly the irisses in eyes..
// It also works for "wet" surfaces like rain on a tar road or blood on a character.
vec4 DiffuseMinusDropletMask;
DiffuseMinusDropletMask.xyz = MAPDiffuseRGBA.xyz; // (NOT "w") DO THIS BEFORE OTHER CALCULATIONS..
if (DropletEnabled)
{vec3 AlteredUCN = UnCompressedNormal;
float GlobalDropConcavity = -1.0; // Think of the "Convexity" of the "Lens" of an eye then of the "Concavity" of the "Iris"..
AlteredUCN.x *= GlobalDropConcavity; // Tweakable value.. Originally -1.
AlteredUCN.y *= GlobalDropConcavity; // It is not a mathematically perfect thing so tweaking is O.K..
vec3 DropletNormal = normalize((AlteredUCN.y * Binormal) // The "Altered Normal" is an Inverse of the X and Y of the
+(AlteredUCN.x * Tangent)
+((AlteredUCN.z * VNormal) * 1.0));
float GlobalDropFact = 1.0;
float GlobalDropPhong = 8.0; // "Tightness" of "Reversed" back light (8.0 works)..
// - ALL LIGHTS -
vec3 DropletColled001 = LightCol001;
vec3 DropletColled002 = LightCol002;
vec3 DropletColled003 = LightCol003;
vec3 DropletColled004 = LightCol004;
float DropletEffect001 = clamp(dot(normalize((ViewDir + LightDir001)),DropletNormal),0.0,1.0);
float DropletEffect002 = clamp(dot(normalize((ViewDir + LightDir002)),DropletNormal),0.0,1.0);
float DropletEffect003 = clamp(dot(normalize((ViewDir + LightDir003)),DropletNormal),0.0,1.0);
float DropletEffect004 = clamp(dot(normalize((ViewDir + LightDir004)),DropletNormal),0.0,1.0);
// Phong 8.0 is good..(here we dont use the Standardising "PLAECF" as we
// manually controll the Sharpness of the "Inner Hhighlight")
DropletEffect001 = clamp(pow(DropletEffect001, GlobalDropPhong ), 0.0 , 1.0 );
DropletEffect001 *= GlobalDropFact; DropletColled001.xyz *= DropletEffect001;
DropletEffect002 = clamp(pow(DropletEffect002, GlobalDropPhong ), 0.0 , 1.0 );
DropletEffect002 *= GlobalDropFact; DropletColled002.xyz *= DropletEffect002;
DropletEffect003 = clamp(pow(DropletEffect003, GlobalDropPhong ), 0.0 , 1.0 );
DropletEffect003 *= GlobalDropFact; DropletColled003.xyz *= DropletEffect003;
DropletEffect004 = clamp(pow(DropletEffect004, GlobalDropPhong ), 0.0 , 1.0 );
DropletEffect004 *= GlobalDropFact; DropletColled004.xyz *= DropletEffect004;
vec3 DropletFINAL = DropletColled001 + DropletColled002 + DropletColled003 + DropletColled004;
float DropletMask = 0;
if (MAPDiffuseRGBA.w > 0.6) // Referring to the Upper 40% of Alpha Intensity..
{DropletMask = (MAPDiffuseRGBA.w - 0.6) * 2.5; // Convert our Upper 40% into 100% for smooth bordering..
}
FinalDiffuse.xyz *= (1.0 - DropletMask); // Blacken the areas covered by the droplet mask..
FinalDiffuse.xyz += DropletFINAL.xyz * MAPDiffuseRGBA.xyz * DropletMask;
// See how "OpenGL Clip Cutoff" occurs at just below 50% grey allowing us
// some latitude above that value.. (We use above 60% to be safe)..
}
// END of "Droplet Shader Effect"
// =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=
// =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=
// FINAL STUFF..
FinalDiffuse.xyz *= FinalDiffLightsColed.xyz;
if (GPURendermode == 0) // -- LERPED -- (default)
{// Interpolate between the raw mapped diffuse colour and the shaded colour as a way of emulating ambient lighting..
LerpSliderDiffmap = 0.7;
} else {LerpSliderDiffmap = 1.0;}
FinalDiffuse.xyz += SpecularColour.xyz; // FINAL SPECULAR "ADD"..
MAPDiffuseRGBA.w *= 3.0; // A cool (hardcoded) way to finetune the Alpha Channel to get "Thicker or Thinner" cover on the CLipMap..
// This should be done "after" we extracted and converted the different "ranges of intensity"
// from the Alpha channel for other things like "Droplet Mask"..
FinalDiffuse.w = MAPDiffuseRGBA.w;
FinalDiffuse.w *= GPUFloatArray[0][3]; // Inc/Dec very slowly by tapping "C" or "V"..
gl_FragColor = Interpolate(LerpSliderDiffmap, MAPDiffuseRGBA, FinalDiffuse);
gl_FragColor.w = FinalDiffuse.w;
// (there is still something funny here)..
//||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// O.K.
// - SHADER COMMANDS - // Override the Final Calculations above..
// When youre done playing with the different rendermodes dele these to save GPU time..
if (GPURendermode == 10) // ADD the "Emmision Map" to everything else. Darkened Scenes (which we did elsewhere) works better..
{gl_FragColor.xyz += MAPEmissionRGB.z; gl_FragColor.w = MAPDiffuseRGBA.w; } // No return this time..
if (GPURendermode == 2) // Render the "Mapped Raw Diffuse Colour" only..
{gl_FragColor = MAPDiffuseRGBA; return;}
if (GPURendermode == 3) // Render "Final Normals" after all the "Tangent, Binormal and Matrix Calculations"..
{gl_FragColor.xyz = (FinalNormal.xyz / 2.0) + 0.5;
gl_FragColor.w = MAPDiffuseRGBA.w; // We want to see our "Adjusted" clipmapping always..
return;
}
if (GPURendermode == 4) // Show Diffuse by LIGHT_001 only..
{gl_FragColor.xyz = DiffColByLight001.xyz * 1.0; gl_FragColor.w = MAPDiffuseRGBA.w; return; }
if (GPURendermode == 5) // Show only DIFFUSE and SPECULAR (diffuse subdued for a better effect)..
{float DiffSub = 0.25; float SpecSub = 1.0; // Tweak them..
gl_FragColor.xyz = FinalDiffLightsColed.xyz * DiffSub; gl_FragColor.xyz += (SpecularColour.xyz * SpecSub);
gl_FragColor.w = MAPDiffuseRGBA.w; return;
}
if (GPURendermode == 6) // Render TANGENTS..
{gl_FragColor.xyz = (Tangent.xyz / 2.0) + 0.5; gl_FragColor.w = MAPDiffuseRGBA.w; return;}
if (GPURendermode == 7) // Render BINORMALS..
{gl_FragColor.xyz =(Binormal.xyz/2.0)+0.5; gl_FragColor.w = MAPDiffuseRGBA.w; return;}
if (GPURendermode == 8) // Normals as mapped in the "NSG Map" in R and G along with our Cool Calculated Z..
{gl_FragColor.xyz = (UnCompressedNormal.xyz / 2.0) + 0.5; gl_FragColor.w = MAPDiffuseRGBA.w; return; }
if (GPURendermode == 9) // Render Geometric Vertex Normals.. If you can see one of your "Extra Images" then your recompile and new dll works!..
{vec4 VnormalRepresentation; VnormalRepresentation.xyz = (VNormal.zyx / 2.0) + 0.5;
// We test our EXTRA FOUR IMAGES here!
// gl_FragColor.xyz = MapRGBA004.xyz;
// gl_FragColor.xyz = MapRGBA005.xyz; // From here we have to change "irrCompileConfig.h" and recompile the Irrlicht Engine to get a new DLL and LIB)
// gl_FragColor.xyz = MapRGBA006.xyz; // See details of this elsewhere.
// gl_FragColor.xyz = MapRGBA007.xyz;
// gl_FragColor.xyz = MapRGBA008.xyz;
gl_FragColor = Interpolate(0.25, VnormalRepresentation, MapRGBA006); // Just for fun..
gl_FragColor.w = MAPDiffuseRGBA.w; // We want to see our "Adjusted" clipmapping always..
return;
}
if (GPURendermode == 14) // Mapped Spec & Gloss as if it was mapped with R and G..
{gl_FragColor.x = MapNSGRGBA.z; gl_FragColor.y = MapNSGRGBA.w; gl_FragColor.z = MAPSpecXGlossY.z;
gl_FragColor.w = MAPDiffuseRGBA.w; return;}
if (GPURendermode == 15) // Mapped Specular..
{gl_FragColor.xyz = MapNSGRGBA.z; gl_FragColor.w = MAPDiffuseRGBA.w; return;}
if (GPURendermode == 16) // Mappped Gloss..
{gl_FragColor.xyz = MapNSGRGBA.w; gl_FragColor.w = MAPDiffuseRGBA.w; return;}
if (GPURendermode == 17) // UV Representation..
{gl_FragColor.xy = RenderedUVs.xy; gl_FragColor.z = 0.0; gl_FragColor.w = MAPDiffuseRGBA.w; return;}
}// -- END -- You fix the rest!
Code: Select all
// H O W T H I N G S W E R E P A S S E D F R O M A P P C O D E ..
// Snippet..
virtual void OnSetConstants(irr::video::IMaterialRendererServices* PrivateServices, irr::s32 userData)
{irr::core::matrix4 matWorld;
TheWorldMatrix = TheVideoDriver->getTransform(ETS_WORLD); // THIS IS VERY IMPORTANT!
TheCameraPosition = TheSceneManager->getActiveCamera()->getPosition();
PrivateServices->setVertexShaderConstant("mWorld", TheWorldMatrix.pointer(), 16); // All we need here from our side! (there are some "unseens" under GLSL though)..
int TexAddresses [8]; // 4 is current max..
/*
#define DIFFUSE 0
#define NORSPEGLOSS 1 // Very cool..
// #define SPECGLOSS XX // New implementation where we "Combine" Specular and Gloss in a single image..
#define EMMISION 2 // Emission for "Glow" effects..()
#define IMAGEX004 3 // Future stuff would be SSS, LSSOMS,
#define IMAGEX005 4
#define IMAGEX006 5
#define IMAGEX007 6
#define IMAGEX008 7
*/
TexAddresses [DIFFUSE] = DIFFUSE;
TexAddresses [NORSPEGLOSS] = NORSPEGLOSS;
TexAddresses [EMMISION] = EMMISION;
TexAddresses [IMAGEX004] = IMAGEX004;
TexAddresses [IMAGEX005] = IMAGEX005;
TexAddresses [IMAGEX006] = IMAGEX006;
TexAddresses [IMAGEX007] = IMAGEX007;
TexAddresses [IMAGEX008] = IMAGEX008; // Bit of a mess but it works..
PrivateServices->setPixelShaderConstant("DiffuseMap", (int*)(&TexAddresses [DIFFUSE]), 1);
PrivateServices->setPixelShaderConstant("NSGMap", (int*)(&TexAddresses [NORSPEGLOSS]), 1);
PrivateServices->setPixelShaderConstant("EmissionMap", (int*)(&TexAddresses [EMMISION]), 1); //
PrivateServices->setPixelShaderConstant("Image004", (int*)(&TexAddresses [IMAGEX004]), 1); //
PrivateServices->setPixelShaderConstant("Image005", (int*)(&TexAddresses [IMAGEX005]), 1); // I5 IMAGE O.K.
PrivateServices->setPixelShaderConstant("Image006", (int*)(&TexAddresses [IMAGEX006]), 1); // I6 IMAGE O.K.
PrivateServices->setPixelShaderConstant("Image007", (int*)(&TexAddresses [IMAGEX007]), 1); // I7 IMAGE O.K.
PrivateServices->setPixelShaderConstant("Image008", (int*)(&TexAddresses [IMAGEX008]), 1); // I8 IMAGE O.K.
// CGparameter cgEnvironmentMap; // Textures.. WHAT IS THIS CG THING'S COUNTERPART IN GLSL? (comes from CG!!)
PrivateServices->setPixelShaderConstant("GPURendermode", (int*)(&FragmentRendermode), 1);
if (PLAECFActive == 1){int Valll = 1; PrivateServices->setPixelShaderConstant("GpuPLAECFActive", (int*)(&Valll) , 1);}
if (PLAECFActive == 0){int Valll = 0; PrivateServices->setPixelShaderConstant("GpuPLAECFActive", (int*)(&Valll) , 1);}
// HOW DO WE USE "SAMPLER CUBE" ?? (there must be a way as the keyword exists under GLSL)..
PrivateServices->setPixelShaderConstant("CameraPos", &TheCameraPosition.X, 4); // see how we have the ".x" to indicate the first in an array..
PrivateServices->setPixelShaderConstant("GPUFloatArray", (float*)(&ShaderFloatArray), 16); // As a "mat4" type..
}
// etc etc..
Code: Select all
setVertexShaderConstant()
Code: Select all
SetPixelShaderConstant()
Code: Select all
getVertexShaderConstantID