Where Code Meets Creative Content

Discuss about anything related to the Irrlicht Engine, or read announcements about any significant features or usage changes.

Re: Where Code Meets Creative Content

Postby CuteAlien » Mon Sep 19, 2016 10:49 pm

Hey, nice demo! Runs fine even in WINE. Beautifiying code... add a little whitespace ;-)
IRC: #irrlicht on irc.freenode.net
Code snippets, patches&stuff: http://www.michaelzeilfelder.de/irrlicht.htm
Free racer created with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
User avatar
CuteAlien
Admin
 
Posts: 8365
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany

Re: Where Code Meets Creative Content

Postby Nadro » Mon Sep 19, 2016 11:44 pm

Both drivers doesn't work for me (bugs in shaders).

OpenGL:
Image

D3D9:
Image
Nadro
 
Posts: 1647
Joined: Sun Feb 19, 2006 9:08 am
Location: Warsaw, Poland

Re: Where Code Meets Creative Content

Postby Vectrotek » Tue Sep 20, 2016 8:35 am

Hi Nadro..

For the GL code, try replacing all the code in "GL_0001_VERT_WATER.glsl" with...

cpp Code: Select all
 
 
 // Based on code by Elvman.
 
 //uniform mat4 View;
 uniform mat4   M05WorldViewProjection;
 uniform mat4   M24WorldReflectionViewProj;
 uniform float  WaveLength;
 uniform float  Time;
 uniform float  WindForce;
 uniform vec2   WindDirection;
 // Vertex shader output structure
 varying vec2 bumpMapTexCoord;
 varying vec2 bumpMapTexCoord02;
 varying vec3 refractionMapTexCoord;
 varying vec3 reflectionMapTexCoord;
 varying vec3 position3D;
// varying vec3 VertexGLPosition;
 
 //----------------- --- -- -
 void main()
  {// color = gl_Color; // We may later want to see what we can do with this..
   // Transform position to clip space..
   vec4 pos = M05WorldViewProjection * gl_Vertex;
   gl_Position = pos;
   // VertexGLPosition  = vec3(M01World * vec4(gl_Vertex.xyz,1)).xyz;
   // Calculate Wave Coords..
   bumpMapTexCoord = gl_MultiTexCoord0.xy / WaveLength + (Time * WindForce * WindDirection);
   // Old code..
   // WindDirection.x *= 1.333;
   // WindDirection.y *= 0.777;
   // New code..
   vec2 SecondWindDir = WindDirection; // Avoid assigning a uniform any values..
   SecondWindDir.x *= 1.333;
   SecondWindDir.y *= 0.777;
   
   // bumpMapTexCoord02 = gl_MultiTexCoord0.xy / WaveLength + (Time * WindForce * -WindDirection);
   bumpMapTexCoord02 = gl_MultiTexCoord0.xy / WaveLength + (Time * WindForce * -SecondWindDir);
   
   // Refraction texcoords..
   refractionMapTexCoord.x = 0.5 * (pos.w + pos.x);
   refractionMapTexCoord.y = 0.5 * (pos.w + pos.y);
   refractionMapTexCoord.z = pos.w;
   // Reflection texcoords..
   pos = M24WorldReflectionViewProj * gl_Vertex;
   reflectionMapTexCoord.x = 0.5 * (pos.w + pos.x);
   reflectionMapTexCoord.y = 0.5 * (pos.w + pos.y);
   reflectionMapTexCoord.z = pos.w;
   // position of the vertex
   position3D = gl_Vertex.xyz;
  }
 
 // END..
 
 

I'd like to know if it made a difference.
Last edited by Vectrotek on Tue Sep 20, 2016 8:41 am, edited 1 time in total.
User avatar
Vectrotek
Competition winner
 
Posts: 1056
Joined: Sat May 02, 2015 5:05 pm
Location: South Africa

Re: Where Code Meets Creative Content

Postby Vectrotek » Tue Sep 20, 2016 8:38 am

Nadro.. What happens in DX mode when you press "0" (disable post processing)?

Because if you press "0" and you see the water than I know it must be the Post Processor HLSL shaders
that are very fussy about assigning values to uniforms which usually isn't a problem in GLSL.

It is funny however that GLSL complains about setting a uniform though. (some systems ore OK with it)
I see now that setting a uniform in the shader code isn't a good idea anyway!

I Learnt something here..

Still, also it would be nice if you let me know if the GLSL Vertex program fix worked..
User avatar
Vectrotek
Competition winner
 
Posts: 1056
Joined: Sat May 02, 2015 5:05 pm
Location: South Africa

Re: Where Code Meets Creative Content

Postby Nadro » Tue Sep 20, 2016 8:51 am

In D3D9 after '0' pressed all seems to work properly. In OGL I see following errors:
Fragment shader failed to compile with the following errors:
ERROR: 0:164: error(#164) l-value required: assign "UserShaderMode" (can't modify a uniform)
ERROR: 0:178: error(#164) l-value required: assign "GeneralWaterColour" (can't modify a uniform)
ERROR: 0:218: error(#143) Undeclared identifier: lerp
ERROR: 0:218: error(#202) No matching overloaded function found: lerp
ERROR: error(#273) 4 compilation errors. No code generated


You can try to add:
cpp Code: Select all
#version 120

to each glsl file (at beginning of the file), to disable Cg features from GLSL. IMO NV drivers are really bad, if you want to write code OpenGL compliant, instead of NvidiaGL.
Nadro
 
Posts: 1647
Joined: Sun Feb 19, 2006 9:08 am
Location: Warsaw, Poland

Re: Where Code Meets Creative Content

Postby Vectrotek » Tue Sep 20, 2016 9:01 am

Thanks! I'm going to do that "#version 120" thing right now..

I think the reason why some machines won't show the Post processing in HLSL mode is because (like GLSL) there are some compatibility issues..
The "Smart Shader" system already in the code for the static objects makes it so that when "onSetConstants" are called it won't set variables that are not in the shader..
I thought I'd get away with it by not having this for the post the post processing system.

looking at the GLSL thing now...
User avatar
Vectrotek
Competition winner
 
Posts: 1056
Joined: Sat May 02, 2015 5:05 pm
Location: South Africa

Re: Where Code Meets Creative Content

Postby Vectrotek » Tue Sep 20, 2016 9:24 am

1. Added "#version 120" to this file only as yet.
2. Disabled lerp() (will have to code it).
3. Disabled UserShadederMode = XX; (I see GLSL complains about this now with #version 120 which is good )
4. Fixed vec3 vs vec4 errors.


O.K. What happens when you replace the code in "GL_0001_FRAG_WATER.glsl" with...


cpp Code: Select all
 
 
// Allows me to see errors to help make it platform independent??
 #version 120  
 
 uniform vec3       CameraPosition;  // Camera Position..
 uniform vec3       GeneralWaterColour;
 uniform float      TransOpagueLerp; // New thing, see the code for explanation..
 uniform sampler2D  WaterBump;
 uniform sampler2D  RefractionMap;
 uniform sampler2D  ReflectionMap;
 uniform sampler2D  DepthMap;
 uniform int        UserShaderMode; // Change this in here during development tests..
 
 
 varying vec2       bumpMapTexCoord;
 varying vec2       bumpMapTexCoord02;
 varying vec3       refractionMapTexCoord;
 varying vec3       reflectionMapTexCoord;
 varying vec3       position3D;
 
 //===========================================
 void main()
  {
   vec3 upVector = vec3(0.0, 1.0, 0.0);
   float fresnelTerm =  dot(normalize(CameraPosition - position3D), upVector);
   vec4 RGBTanNormals = texture2D(WaterBump, bumpMapTexCoord * 6.0);
   vec4 RGBTanNormals02 = texture2D(WaterBump, bumpMapTexCoord02 * 10.0);
 
   // Depend on the image format i.e. "TGA" vs "PNG" !!!
 
   // Scaleing only AFTER the normals were extracted.. (or reflection ripples hover above or below the zero line which is bad)
   vec2 Perturbence = (2.0 * (RGBTanNormals.rg - 0.5) * 0.1);  // When TGA ??
 
   Perturbence += (2.0 * (RGBTanNormals02.rg - 0.5) * 0.1);
   // Perturbence /= 2.0;
 
   // Perturbence.xy  *= (fresnelTerm + 0.5);  // MUST GO HLSL..
 
   
 
   // vec2 Perturbence = 0.2 * (RGBTanNormals.rg - 0.25);  // When some PNGs ??
   vec2 GeneralCoordsTweak;
   GeneralCoordsTweak.x = 0.000400; // Differs slightly from HLSL..
   GeneralCoordsTweak.y = 0.001;    // Sign differs between GLSL and HLSL..
   vec2 DepthTexCoords = clamp(refractionMapTexCoord.xy / refractionMapTexCoord.z, 0.0, 1.0);
   DepthTexCoords.xy += GeneralCoordsTweak.xy;    // (more is to the left) Small tweak for horizontal allighnment (loss from xyz(rgb) in "some" normal maps)..
   //DepthTexCoords.y += GeneralCoordsTweak.y;    // Very usefull little vertical tweak used to fix some inherent vertical reflection problems..
   vec4 PrimaryDepth = texture2D(DepthMap, DepthTexCoords); // Primary Depth used to get the initial depth..
 
 
   // Perturbence.xy * 10.0;
 
   Perturbence.xy *= PrimaryDepth.y;       // Get perturbence to "gradually flatten out" as it "Visually" approaches "Geometric Water Edges"..
 
   // Perturbence.xy  *= clamp(refractionMapTexCoord.xy, 0.0, 1/0 -PrimaryDepth.y);
 
 
  //  float CamHeightSquared = CameraPosition.y * CameraPosition.y;
 
   // This little trick ensures that the further the camera is from the
   // water surface, the smaller the effect of the purturbance displacement
   // on the reflections and refraction thus avoiding unnatural effects ar greater distances..
   // This is because we are basically displaceing the UV Coords in Screen Space..
   // There is probably a pragmatic formula for this that would be fed
   // the camera height and FOV etc, but that still needs to be determined..
   
   // Perturbence.xy  *= 1.0 - (CameraPosition.y / 100.0);
   
    float InverseHeight = 1.0 - (CameraPosition.y / 250.0);
   
    float HeightCorrection = InverseHeight * InverseHeight;
   
     Perturbence.xy  *= HeightCorrection;
     Perturbence.xy  *= HeightCorrection;
    //  Perturbence.xy  *= HeightCorrection;
    //   Perturbence.xy  *= HeightCorrection;
    //    Perturbence.xy  *= HeightCorrection;
   
   // Perturbence.xy  *= 1.0 - (CameraPosition.y / 100.0);
   
   // Perturbence.xy  *= 1.0 - (CameraPosition.y / 80.0);
   
   // It's not a perfect world so we need a cutoff to avoid negative values..
   if (CameraPosition.y > 250.0) {Perturbence.xy = vec2(0.0, 0.0);}
 
   vec2 DepthUVsPerturbed = clamp(refractionMapTexCoord.xy / refractionMapTexCoord.z + Perturbence, 0.0, 1.0);
   
   DepthUVsPerturbed.xy += GeneralCoordsTweak.xy;  // (more is to the left) SMALL TWEAK FOR HORIZONTAL ALLIGHNMENT (LOSS FROM XYZ(RGB) in "SOME" NORMAL MAPS)..
 
   // MINUS Pert versus PLUS Pert is your opinion..
   // but + & - does emulate a shift between Reflct and Refract..
   vec2 DepthUVsPerturbedINVERT = clamp(refractionMapTexCoord.xy / refractionMapTexCoord.z - Perturbence, 0.0, 1.0);
   
   DepthUVsPerturbedINVERT.xy += GeneralCoordsTweak.xy;  // (more is to the left) SMALL TWEAK FOR HORIZONTAL ALLIGHNMENT (LOSS FROM XYZ(RGB) in "SOME" NORMAL MAPS)..
 
   //||||||||||||||||||||||||||||
   vec4 SecDepthREFRACT = texture2D (DepthMap, DepthUVsPerturbed );
   vec4 SecDepthINVERT = texture2D (DepthMap, DepthUVsPerturbedINVERT );  
   
   vec2 ProjectedRefractionTexCoords = clamp(refractionMapTexCoord.xy / refractionMapTexCoord.z +  Perturbence, 0.0, 1.);
   ProjectedRefractionTexCoords.xy += GeneralCoordsTweak.xy; // (more is to the left) SMALL TWEAK FOR HORIZONTAL ALLIGHNMENT (LOSS FROM XYZ(RGB) in "SOME" NORMAL MAPS)..
   vec4 refractiveColor = texture2D(RefractionMap, ProjectedRefractionTexCoords);
 
 
   //||||||||||||||||||||||||||||
   // AGAIN.. MINUS Pert versus PLUS Pert is your opinion..
   // but + & - does emulate a shift between Reflct and Refract..
   vec2 ProjectedReflectionTexCoords = clamp(reflectionMapTexCoord.xy / reflectionMapTexCoord.z + Perturbence, 0.0, 1.0);
   ProjectedReflectionTexCoords.xy += GeneralCoordsTweak.xy;  // (more is to the left) SMALL TWEAK FOR HORIZONTAL ALLIGHNMENT (LOSS FROM XYZ(RGB) in "SOME" NORMAL MAPS)..
 
   //||||||||||||||||||||||||||||  
   // vec4 reflectiveColor = texture2D(ReflectionMap, ProjectedReflectionTexCoords );
   vec4 reflectiveColor = texture2D(ReflectionMap, ProjectedReflectionTexCoords);
 
 
 
   float ONEMINUSfresnelTerm = 1.0 - fresnelTerm;
   ONEMINUSfresnelTerm *= ONEMINUSfresnelTerm;
 
   float ONEMINFresSOFT = 1.0 - fresnelTerm;
   
 
   ONEMINFresSOFT *= ONEMINFresSOFT;
   ONEMINFresSOFT *= SecDepthREFRACT.z;
 
   float FresSoft = 1.0 - ONEMINFresSOFT;
 
   float ONEMINFresSOFTINVERT = 1.0 - fresnelTerm;
 
   ONEMINFresSOFTINVERT *= ONEMINFresSOFTINVERT;
   ONEMINFresSOFTINVERT *= SecDepthINVERT.z;
 
 
   float FresSOFTINVERT = 1.0 - fresnelTerm;
   
   FresSOFTINVERT *= FresSOFTINVERT;
   FresSOFTINVERT *= SecDepthINVERT.z;
 
   
   // WORK AROUND? (Nadro)
   vec3 NonUniformWaterColour = GeneralWaterColour;
   
   NonUniformWaterColour *= SecDepthREFRACT.z; // SecDepthREFRACT.z is "Tight White Edge"..
   vec3 ColouredWhiteEdge;// = GeneralWaterColour + (1.0 - SecDepthREFRACT.z);
 
   ColouredWhiteEdge = NonUniformWaterColour + (1.0 - SecDepthREFRACT.z);
 
   vec4 TintedRefract;
   TintedRefract.xyz = refractiveColor.xyz;
   TintedRefract.xyz *= (1.0 - SecDepthREFRACT.x);  // PrimaryDepth.x is "Water Opacity"..
   TintedRefract.xyz *= ColouredWhiteEdge.xyz;
 
 
 
   // | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
   //  if (UserShaderMode == 1)  // DEFAULT
   //   {
     // gl_FragColor.xyz = ( (TintedRefract.xyz * FresSoft) + (reflectiveColor.xyz * ONEMINFresSOFT ));
     // Actually better as relfection and refraction phase should differ by approx 180°..
 
   //    vec3 ResultingRGB;
 
     
   //    gl_FragColor.xyz = ResultingRGB.xyz;
 
 
 
 
      // ORIGINAL SAFE..
       // XXXXXXXXXX gl_FragColor.xyz = ( (TintedRefract.xyz * FresSoft) + (reflectiveColor.xyz * ONEMINFresSOFT));
     //  gl_FragColor.xyz = ( (vec3(1.0, 0.0, 0.0) * FresSoft) + (reflectiveColor.xyz * ONEMINFresSOFT));
     
     // /*
  // float3 RawDiffuse =  float3 (0.25, 0.0, 0.0);
   vec3 RawDiffuse =  GeneralWaterColour;
   RawDiffuse.xyz *=  (SecDepthREFRACT.z); // O.K.
   RawDiffuse.xyz +=  (refractiveColor.xyz * (1 - SecDepthREFRACT.z)); // FINALLY
// */
     
     
   vec4 GeneralTransparency = ( vec4(TintedRefract.xyz * FresSoft, 1.0) + (reflectiveColor * ONEMINFresSOFT) );
   vec4 GeneralOpacity = ( vec4(RawDiffuse.xyz * FresSoft, 1.0) + (reflectiveColor * ONEMINFresSOFT) );    
     
  //   gl_FragColor.xyz = lerp (GeneralTransparency.xyz, GeneralOpacity.xyz , TransOpagueLerp );  
     
       gl_FragColor.xyzw = GeneralTransparency;  // NO LERP FOR OPACITY..
 
     // GET THE HADRCODED VERSION OF THIS (i've got it somewhere, just have to find it)    
     // gl_FragColor.xyz = lerp( (TintedRefract.xyz * FresSoft), (reflectiveColor.xyz * ONEMINFresSOFT) ,ONEMINFresSOFTINVERT);
   
  }
 
 
       
 
 
 // END..
 
 
 
 
 
 
 
 
 
Last edited by Vectrotek on Tue Sep 20, 2016 9:29 am, edited 1 time in total.
User avatar
Vectrotek
Competition winner
 
Posts: 1056
Joined: Sat May 02, 2015 5:05 pm
Location: South Africa

Re: Where Code Meets Creative Content

Postby Vectrotek » Tue Sep 20, 2016 9:26 am

Now doing all GLSL "#version 120" . (pandora's box)
User avatar
Vectrotek
Competition winner
 
Posts: 1056
Joined: Sat May 02, 2015 5:05 pm
Location: South Africa

Re: Where Code Meets Creative Content

Postby Vectrotek » Tue Sep 20, 2016 9:52 am

O.K. This is how I think it is..

In GLSL, "#version 120" places the system in "fussy" mode, meaning that you'll see more errors which will help you make the code more compatible to different platforms.
In GLSL you SHOULD NOT assign to UNIFORMS.. ("#version 120") sees to that..
In GLSL (under "#version 120") the function "lerp()" is not available so you have to code that in yourself.. (should be easy enough)
- - - - - - - - - - - -
In HLSL you are ABSOLUTELY NOT allowed to assign to UNIFORMS.. (particularly visible in the Post Processor)
In HLSL you MUST also ensure that "onSetconstants" feeds parameters to the shader that DOES EXIST..
(also particularly visible in the Post Processor with Buffer Width and Height)

For HLSL and GLSL thing the only true solution would be to have the "Smart Shader" system selectively feed parameters to the Post Processor Shaders too..
I think?
User avatar
Vectrotek
Competition winner
 
Posts: 1056
Joined: Sat May 02, 2015 5:05 pm
Location: South Africa

Re: Where Code Meets Creative Content

Postby Nadro » Tue Sep 20, 2016 9:56 am

It works now :) It will be good to use 24 bit ZBuffer -> createDeviceEx. I saw in your comments that you have a problems with 24 bit RT in D3D9. If you use trunk you can manually attach depth texture (16bit depth, 32bit depth and 24bit depth + 8bit stencil) to RT.
Nadro
 
Posts: 1647
Joined: Sun Feb 19, 2006 9:08 am
Location: Warsaw, Poland

Re: Where Code Meets Creative Content

Postby Vectrotek » Tue Sep 20, 2016 10:04 am

Thanks for your help Nadro!
I'll look into the trunk thing..
User avatar
Vectrotek
Competition winner
 
Posts: 1056
Joined: Sat May 02, 2015 5:05 pm
Location: South Africa

Re: Where Code Meets Creative Content

Postby Vectrotek » Tue Sep 20, 2016 10:13 am

I thought I'd post this..
It is a version of the Water Code from an "Experimental Syntax" highlighter I'm working on.
If you have "Open Office" installed (just the "writer" needed) then these "*.odt" files might amuse you..

It's just a way for me with my poor eye-sight to keep track of things..

here is the zip file: http://s000.tinyupload.com/?file_id=00012524955169428605

Thanks again. I hope you'll let me know of any other problems.
User avatar
Vectrotek
Competition winner
 
Posts: 1056
Joined: Sat May 02, 2015 5:05 pm
Location: South Africa

Re: Where Code Meets Creative Content

Postby Vectrotek » Tue Sep 20, 2016 11:33 am

Here is a Custom Lerp Function that can be used instead of lerp()..

The function definition..
cpp Code: Select all
 
 vec4 InterpolateV4(vec4 ArgA, vec4 ArgB, float Slider)
  {vec4 OutputVal = ArgB * Slider + ArgA * (1 - Slider);
   return OutputVal;
  }
 // AND..
 vec3 InterpolateV3( vec3 ArgA, vec3 ArgB, float Slider)
  {vec3 OutputVal = ArgB * Slider + ArgA * (1 - Slider);
   return OutputVal;
  }
 


Here is the usage..
cpp Code: Select all
 
  //  gl_FragColor.xyz = lerp (GeneralTransparency.xyz, GeneralOpacity.xyz , TransOpagueLerp );  
  // Relpaced with..
  gl_FragColor.xyz = InterpolateV3(GeneralTransparency.xyz, GeneralOpacity.xyz, TransOpagueLerp);
 
 

If you had to do this with HLSL too let me know..Thanks!
User avatar
Vectrotek
Competition winner
 
Posts: 1056
Joined: Sat May 02, 2015 5:05 pm
Location: South Africa

Re: Where Code Meets Creative Content

Postby Vectrotek » Tue Sep 20, 2016 11:50 am

Oh, sorry about the language at the end of the music.. Didn't realize..
Just press "G"..
User avatar
Vectrotek
Competition winner
 
Posts: 1056
Joined: Sat May 02, 2015 5:05 pm
Location: South Africa

Re: Where Code Meets Creative Content

Postby Nadro » Wed Sep 21, 2016 10:12 am

Instead of custom 'lerp' in GLSL you can just use built-in 'mix'.
Nadro
 
Posts: 1647
Joined: Sun Feb 19, 2006 9:08 am
Location: Warsaw, Poland

PreviousNext

Return to Open Discussion and Dev Announcements

Who is online

Users browsing this forum: No registered users and 1 guest