Jump to content

Recommended Posts

Posted

+1

 

It will make life a lot easier. Specially in situation where a lot of different shaders needs same functions and constants. Currently it is damn hard to maintain constant changes between shaders.

  • Windows 10 Pro 64-Bit-Version
  • NVIDIA Geforce 1080 TI
Posted

The reason we don't is because the shader editor would no longer be able to show the line an error occurs on, and it would make dynamic shader reloading impossible.

 

 

Posted

Well, i understand why you may focus on other things currently, but both of your points are not truely valid.

 

1. not getting the correct error-line:

Might be a bit harder to implement, but keeping the original and processed code (maybe even with some metadata) a simple diff should already work. You should be able to register if an errorline is in the included part or not and be able to jump into the correct file.

 

2. impossible to reload?

Definetly not impossible, but might be a bit tricky. Short solution: ignore includes for the reload, just track saves for the main shader. I could live with that.

 

  • Windows 10 Pro 64-Bit-Version
  • NVIDIA Geforce 1080 TI
Posted

After the flags parameter, there is a hidden feature I use for lighting shaders:

Shader* Shader::Load(const std::string& path, const int flags, const std::string& precode)

 

I use it to pass preprocessor defines to the shaders so I don't have to keep a lot of extra versions of them.

My job is to make tools you love, with the features you want, and performance you can't live without.

Posted

Just as reminder:

You can do something like this in glsl:

 

code with #pragma include:

 

#version 400

uniform sampler2D texture1;
uniform sampler2D texture2;
uniform bool isbackbuffer;
uniform vec2 buffersize;
uniform float currenttime;
uniform float intensity = 2.0;

out vec4 fragData0;

#pragma include "functions.glsl"

void main(void)
{
 vec2 icoord = vec2(gl_FragCoord.xy/buffersize);
 if (isbackbuffer) icoord.y = 1.0 - icoord.y;

 vec4 scene = texture2D(texture1, icoord); // rendered scene
 vec4 blur = texture2D(texture2, icoord); // glowmap
 fragData0 = clamp(scene + (blur*intensity), 0.0, 1.0);
}

 

and the merged code:

 

 

#version 400

uniform sampler2D texture1;
uniform sampler2D texture2;
uniform bool isbackbuffer;
uniform vec2 buffersize;
uniform float currenttime;
uniform float intensity = 2.0;

out vec4 fragData0;

#line 1 'functions.glsl'
//code of functions.glsl
#line 12 0

void main(void)
{
 vec2 icoord = vec2(gl_FragCoord.xy/buffersize);
 if (isbackbuffer) icoord.y = 1.0 - icoord.y;

 vec4 scene = texture2D(texture1, icoord); // rendered scene
 vec4 blur = texture2D(texture2, icoord); // glowmap
 fragData0 = clamp(scene + (blur*intensity), 0.0, 1.0);
}

 

An idea for the auto reloading: maybe you can only scan open shader files if they use the #include statement and reload only these.

  • Windows 10 Pro 64-Bit-Version
  • NVIDIA Geforce 1080 TI
Posted

no, you need to parse it and replace it with the '#line ...' part. Unfortunalty the Khronos group ignores the include requests for ages. HLSL can do this out of the box.

 

Sorry if this wasn't clear. I only choosed #pragma because glsl will ignore everything after #pragma if it is not known to the glsl compiler.

  • Windows 10 Pro 64-Bit-Version
  • NVIDIA Geforce 1080 TI

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
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.

×
×
  • Create New...