Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


#ActualnewObjekt

Posted 18 April 2013 - 12:15 PM

IME:

"if()" seems fairly cheap if it is working with uniforms (such as to enable/disable certain features, at least as far as tested thus-far).

 

OTOH, if using the conditionals for things which tend to vary, such as per-pixel data, then they will cost a fair bit more.

 

 

 

I have actually been considering moving between several smaller shaders possibly to a bigger one.

 

the issue is mostly that there are at present several different lighting shaders, which need to be switched between for various combinations of light-source settings and materials, and it may be cheaper in this case to use a single bigger shader, which enables/disables various lighting features instead (say, we can enable or disable shadow-mapping, normal and specular mapping, the use of projection and falloff textures, ...).

 

granted, in this case, I would probably have to make a split between light-source and material attributes (as-is, all are being setup in a big ugly mass every time either the light-source or bound material changes).

 

but, either way, the idea is that it may make sense for the code to instead just change which attributes are relevant to the current material (say, enable/disable normal-mapping, ...).

 

 

however, if what the shaders do is unrelated, say, they operate at different stages of the rendering pipeline, then it probably makes sense to use different shaders.

 

I am not entirely sure what the actual cost of an if based on a uniform actually is.

 

Ah, that's interesting. For the most part I have uniforms that just enable and disable features.

 

It kind of looks like this... (I'm not on my linux HDD right now so I can't get the exact code)

 

uniform boolean unlit;

uniform integer normalSource;

uniform integer specularSource;

uniform integer illuminationSource;

uniform integer transparencySource;

 

if(!unlit) {

//lighting stuff

}

 

//do diffuse texture and detail mixing and crap

 

 

if(specularSource> -1) {

//do specular mapping

}

 

if(normalSource > -1) {

//do normal mapping

}

 

 

if(illuminationSource> -1) {

//do illum mapping

}

 

 

 

if(transparencySource> -1) {

//do transparency mapping

}

 

///finish up and set fragColor

 

 

Also, I'd like to point out that the reason I use integers for the differnt texture sources is I have a system where I use integers to specify which textures and color channels to use for operations. IE If i set specularSource to 14 it will use the diffuse.alpha for specular. Or if I set illuminationSource to 11 it would use the diffuse.red channel.


#3newObjekt

Posted 18 April 2013 - 12:14 PM

IME:

"if()" seems fairly cheap if it is working with uniforms (such as to enable/disable certain features, at least as far as tested thus-far).

 

OTOH, if using the conditionals for things which tend to vary, such as per-pixel data, then they will cost a fair bit more.

 

 

 

I have actually been considering moving between several smaller shaders possibly to a bigger one.

 

the issue is mostly that there are at present several different lighting shaders, which need to be switched between for various combinations of light-source settings and materials, and it may be cheaper in this case to use a single bigger shader, which enables/disables various lighting features instead (say, we can enable or disable shadow-mapping, normal and specular mapping, the use of projection and falloff textures, ...).

 

granted, in this case, I would probably have to make a split between light-source and material attributes (as-is, all are being setup in a big ugly mass every time either the light-source or bound material changes).

 

but, either way, the idea is that it may make sense for the code to instead just change which attributes are relevant to the current material (say, enable/disable normal-mapping, ...).

 

 

however, if what the shaders do is unrelated, say, they operate at different stages of the rendering pipeline, then it probably makes sense to use different shaders.

 

I am not entirely sure what the actual cost of an if based on a uniform actually is.

 

Ah, that's interesting. For the most part I have uniforms that just enable and disable features.

 

It kind of looks like this... (I'm not on my linux HDD right now so I can't get the exact code)

 

uniform boolean unlit;

uniform integer normalSource;

uniform integer specularSource;

uniform integer illuminationSource;

uniform integer transparencySource;

 

if(!unlit) {

//lighting stuff

}

 

//do diffuse texture and detail mixing and crap

 

 

if(specularSource> -1) {

//do specular mapping

}

 

if(normalSource > -1) {

//do normal mapping

}

 

 

if(illuminationSource> -1) {

//do illum mapping

}

 

 

 

if(transparencySource> -1) {

//do transparency mapping

}

 

///finish up and set fragColor

 

 

Also, I'd like to point out that the reason I use integers for the differnt texture sources is I have a system where I use integers to specify which textures and color channels to use for operations. IE If i set specularSource to 14 it will use the diffuse.alpha for specular. Or if I set illuminationSource to 11 it would use the red channel of the diffuse.


#2newObjekt

Posted 18 April 2013 - 12:14 PM

IME:

"if()" seems fairly cheap if it is working with uniforms (such as to enable/disable certain features, at least as far as tested thus-far).

 

OTOH, if using the conditionals for things which tend to vary, such as per-pixel data, then they will cost a fair bit more.

 

 

 

I have actually been considering moving between several smaller shaders possibly to a bigger one.

 

the issue is mostly that there are at present several different lighting shaders, which need to be switched between for various combinations of light-source settings and materials, and it may be cheaper in this case to use a single bigger shader, which enables/disables various lighting features instead (say, we can enable or disable shadow-mapping, normal and specular mapping, the use of projection and falloff textures, ...).

 

granted, in this case, I would probably have to make a split between light-source and material attributes (as-is, all are being setup in a big ugly mass every time either the light-source or bound material changes).

 

but, either way, the idea is that it may make sense for the code to instead just change which attributes are relevant to the current material (say, enable/disable normal-mapping, ...).

 

 

however, if what the shaders do is unrelated, say, they operate at different stages of the rendering pipeline, then it probably makes sense to use different shaders.

 

I am not entirely sure what the actual cost of an if based on a uniform actually is.

 

Ah, that's interesting. For the most part I have uniforms that just enable and disable features.

 

It kind of looks like this... (I'm not on my linux HDD right now so I can't get the exact code)

 

uniform boolean unlit;

uniform integer normalSource;

uniform integer specularSource;

uniform integer illuminationSource;

uniform integer transparencySource;

 

if(!unlit) {

//lighting stuff

}

 

//do diffuse texture and detail mixing and crap

 

 

if(specularSource> -1) {

//do specular mapping

}

 

if(normalSource > -1) {

//do normal mapping

}

 

 

if(illuminationSource> -1) {

//do illum mapping

}

 

 

 

if(transparencySource> -1) {

//do transparency mapping

}

 

///finish up and set fragColor

 

 

Also, I'd like to point out that the reason I use integers for the differnt textures is I have a system where I use integers to specify which textures and color channels to use for operations. IE If i set specularSource to 14 it will use the diffuse.alpha for specular. Or if I set illuminationSource to 11 it would use the red channel of the diffuse.


#1newObjekt

Posted 18 April 2013 - 12:12 PM

IME:

"if()" seems fairly cheap if it is working with uniforms (such as to enable/disable certain features, at least as far as tested thus-far).

 

OTOH, if using the conditionals for things which tend to vary, such as per-pixel data, then they will cost a fair bit more.

 

 

 

I have actually been considering moving between several smaller shaders possibly to a bigger one.

 

the issue is mostly that there are at present several different lighting shaders, which need to be switched between for various combinations of light-source settings and materials, and it may be cheaper in this case to use a single bigger shader, which enables/disables various lighting features instead (say, we can enable or disable shadow-mapping, normal and specular mapping, the use of projection and falloff textures, ...).

 

granted, in this case, I would probably have to make a split between light-source and material attributes (as-is, all are being setup in a big ugly mass every time either the light-source or bound material changes).

 

but, either way, the idea is that it may make sense for the code to instead just change which attributes are relevant to the current material (say, enable/disable normal-mapping, ...).

 

 

however, if what the shaders do is unrelated, say, they operate at different stages of the rendering pipeline, then it probably makes sense to use different shaders.

 

I am not entirely sure what the actual cost of an if based on a uniform actually is.

 

Ah, that's interesting. For the most part I have uniforms that just enable and disable features.

 

It kind of looks like this... (I'm not on my linux HDD right now so I can't get the exact code)

 

uniform boolean unlit;

uniform integer normalSource;

uniform integer specularSource;

uniform integer illuminationSource;

uniform integer transparencySource;

 

if(!unlit) {

//lighting stuff

}

 

//do diffuse texture and detail mixing and crap

 

 

if(specularSource> -1) {

//do specular mapping

}

 

if(normalSource > -1) {

//do normal mapping

}

 

 

if(illuminationSource> -1) {

//do illum mapping

}

 

 

 

if(transparencySource> -1) {

//do transparency mapping

}

 

///finish up and set fragColor


PARTNERS