Jump to content


Photo

3D Forward + Deferred Rendering


  • Please log in to reply
49 replies to this topic

#1 jsorgeagames

jsorgeagames

    GMC Member

  • GMC Member
  • 710 posts
  • Version:GM:Studio

Posted 12 August 2013 - 10:15 PM

What's The Difference?

Forward Rendering: Every object is drawn with a lighting shader of some sort, where the lights are passed in to the shader via uniforms.

Pros:

- Easy to set up

- Each object can have its own shader

Cons:

- Slow

- Limited by hardware

 

Deferred Rendering: Every object is drawn to multiple surfaces that store the diffuse, normal, depth, specular, etc. of the objects, then the lights are drawn as ellipsoids, using the surfaces to correctly light the scene.

Pros:

- Fast, 100s of lights

- Not limited by hardware

Cons:

- Can't handle transparent objects

- Every object has to use the same shader

 

3D Deferred Rendering

Here's a demo with 100 point lights, which are drawn as ellipsoids and use texture look-ups to reconstruct the scene. Commented-out code is included for axis-aligned normal mapping, specular mapping, and (currently broken) screen-space ambient occlusion.

 

Update 1.1: Added an extra pass for ambient lighting, so separate ambient values can be set for each model. This could be included in the specular pass as one of the channels, but the demo is designed for flexibility over performance.

Update 1.2: Fixed some variable names and cleaned up some code.

 

znnObDo.png

 

3D Forward Rendering

Here's a demo with 4 point lights, passed in using arrays. You can have as many lights as you want, depending on hardware, but the problem is, forward rendering is fairly slow.

htmuUHb.png


Edited by jsorgeagames, 15 August 2013 - 07:11 AM.

  • 21

#2 xygthop3

xygthop3

    You may know me from such forums as "Shaders"

  • GMC Member
  • 3367 posts
  • Version:GM:Studio

Posted 12 August 2013 - 10:47 PM

Very nice, runs about 3200FPS on my PC and looks FANTASTIC!!!!
However this is the first shader demo to make my GPU give off a very high pitched squeal, not sure whats going on there.

 

Great work!!!!


  • 0

#3 Venomous

Venomous

    GMC Member

  • GMC Member
  • 1626 posts
  • Version:GM:Studio

Posted 12 August 2013 - 11:06 PM

 Runs great. Nice and easy system to set up lights too. Getting over 5000 fps, so speed isn't an issue, at least not for the simple demo scene.

 

@xygthop3 - Since it is running at such a high FPS, it's most likely coil whine from your graphics card.


  • 0

#4 boxyman_16

boxyman_16

    GMC Member

  • GMC Member
  • 517 posts
  • Version:GM:Studio

Posted 13 August 2013 - 08:46 AM

Sorry but what exactly is this? Does this allow you to have infinite lights or something?


  • 0

#5 Indecom4000

Indecom4000

    GMC Member

  • GMC Member
  • 1636 posts
  • Version:GM:Studio

Posted 13 August 2013 - 09:13 AM

Not infinite, just more than one. He's got a deferred shader in the works right now that will work with many many more lights in a much more efficient manor, if you want tons of lights i'd hold out for him to finish that. Looks really good :)


  • 0

LD-Logo-sml.png


#6 TheSnidr

TheSnidr

    Heavy metal viking dentist

  • GMC Elder
  • 3345 posts
  • Version:GM:Studio

Posted 13 August 2013 - 10:01 AM

Impressive! So exactly what limits the number of lights?
  • 0

#7 Indecom4000

Indecom4000

    GMC Member

  • GMC Member
  • 1636 posts
  • Version:GM:Studio

Posted 13 August 2013 - 06:26 PM

Performance I'd say. One of the major downfalls of multilight solutions is that the more lights you have, the more times you essentially have to redraw the scene, unless he's doing something different here, i'm mostly talking from past experience. The advantage of using a deferred system is that you just draw the scene a couple of times to a buffer, one with scene colors, another with scene depth, and one more with scene normals, then you apply all sorts of crazy lighting to it. It's much faster for handling larger numbers of lights.


  • 0

LD-Logo-sml.png


#8 jsorgeagames

jsorgeagames

    GMC Member

  • GMC Member
  • 710 posts
  • Version:GM:Studio

Posted 13 August 2013 - 10:03 PM

Deferred rendering is basically independent of scene complexity. So while it may be slower to actually draw everything, a lot of the scene isn't actually processed (the parts of the scene that are not visible). Deferred rendering has pitfalls of its own but it allows you to have hundreds of lights because you're not limited by the shader uniforms or the hardware. On my mediocre laptop, I can get 60 fps in my deferred renderer with 100 medium-sized point lights.


  • 0

#9 Mike.Dailly

Mike.Dailly

    Evil YoYo Games Employee

  • Administrators
  • 5277 posts
  • Version:GM:Studio

Posted 14 August 2013 - 08:25 AM

Pretty! :)

 

We do have support for multiple render targets, so you should be able to render much of your targets in one pass, which should help a little. Although you'd have to write an HLSL/GSL shader to do this.


  • 0

#10 xygthop3

xygthop3

    You may know me from such forums as "Shaders"

  • GMC Member
  • 3367 posts
  • Version:GM:Studio

Posted 14 August 2013 - 08:27 AM

The deferred example is epic! very nice indeed


  • 0

#11 jsorgeagames

jsorgeagames

    GMC Member

  • GMC Member
  • 710 posts
  • Version:GM:Studio

Posted 14 August 2013 - 08:50 AM

Pretty! :)

 

We do have support for multiple render targets, so you should be able to render much of your targets in one pass, which should help a little. Although you'd have to write an HLSL/GSL shader to do this.

Yeah, I knew about these (rendering everything separately has a pretty big hit on performance), but I have no idea how HLSL works. If I were to use multiple render targets, how would I set them outside the shader?


  • 0

#12 Indecom4000

Indecom4000

    GMC Member

  • GMC Member
  • 1636 posts
  • Version:GM:Studio

Posted 14 August 2013 - 09:10 AM

I would think that you'd handle them from within the shader itself. I've not tried it myself but that's what I'd think.


  • 0

LD-Logo-sml.png


#13 Mike.Dailly

Mike.Dailly

    Evil YoYo Games Employee

  • Administrators
  • 5277 posts
  • Version:GM:Studio

Posted 14 August 2013 - 09:43 AM

Mmm... just tried here, and it's not working. There "should" be a surface_set_ext() which takes the render target you want to set, allowing you to set multiple ones, but its not working just now.

 

We'll take a look.... it was added so that you could do exactly this kind of thing!!!  :(


  • 0

#14 MancVandaL

MancVandaL

    GMC Member

  • GMC Member
  • 213 posts
  • Version:GM:Studio

Posted 14 August 2013 - 11:54 PM

I have no idea what this is, but it looks nice. GJ.


  • 0

#15 jsorgeagames

jsorgeagames

    GMC Member

  • GMC Member
  • 710 posts
  • Version:GM:Studio

Posted 15 August 2013 - 07:01 AM

I have no idea what this is, but it looks nice. GJ.

Basically it's a more complicated way to do 3d lighting that's a lot faster than normal. It does have some drawbacks though.


  • 0

#16 N3QN

N3QN

    :3

  • GMC Member
  • 65 posts
  • Version:GM:Studio

Posted 16 August 2013 - 07:26 PM

I'm going to be using this for my latest game. (The One on my Avatar) Thanks for making it! :D

The Differed Rendering Example was giving me an Exception: "Exception Reading Assets from GMX File "Config::Configs\Default". I ran it on the Steam Version of GM though, and it worked fine. :S

EDIT: Looks like Game Maker Corrupted somehow. Can't seem to open anything from the non-steam version unless I delete the configs. Oh Well, no worries.

 


Edited by N3QN, 17 August 2013 - 03:22 AM.

  • 0

layout_shadowl_button.pnglayout_da_button.pnglayout_yt_button.pnglayout_shadowr_button.png


#17 Erik Leppen

Erik Leppen

    GMC Member

  • GMC Member
  • 2751 posts
  • Version:GM:Studio

Posted 21 August 2013 - 01:38 PM

I'm using the "forward" one for a game right now. Looks good! I even managed to edit it so it uses textures. Who thought I could do that :D

Althought I have to look out for lag. I plan on adding more lights and the game world is ~100,000 polygons. Let's hope it manages.

Edited by Erik Leppen, 21 August 2013 - 01:38 PM.

  • 0

promo_briquidmini_500x150.png


#18 jsorgeagames

jsorgeagames

    GMC Member

  • GMC Member
  • 710 posts
  • Version:GM:Studio

Posted 21 August 2013 - 10:59 PM

I'm using the "forward" one for a game right now. Looks good! I even managed to edit it so it uses textures. Who thought I could do that :D

Althought I have to look out for lag. I plan on adding more lights and the game world is ~100,000 polygons. Let's hope it manages.

You should have no problem keeping the game at 60 fps with 4 lights with that many polygons. Beyond that though, it will be a bit slow. Also keep in mind the attenuation in the forward shader is infinite, meaning that objects will always receive light from every light source, even if it is a very small value. You can optimize this a bit by deciding which lights to pass in (probably the best approach) or by only doing the lighting calculations if the distance from the light to the vertex (dist) is less than, say, 8 times the light range (lightPos[i].w). Having solved the attenuation equation algebraically, that amounts to the attenuation being 0.005 I think, which is a pretty low value and won't be missed.


  • 0

#19 Erik Leppen

Erik Leppen

    GMC Member

  • GMC Member
  • 2751 posts
  • Version:GM:Studio

Posted 28 August 2013 - 10:26 AM

I have a question. I am now again using this shader but it looks like all primitives are rendered black. Draw_set_color doesn't seem to do anything as long as the shader is active, even if I set the ambient light to a higher value. Is this correct? How come?

If I set the color and then set the shader, it does work. Apparently not.

Edit: never mind. I changed the shader so it accepted a texture, but apparently it doesn't work anymore without texture.

Edited by Erik Leppen, 28 August 2013 - 10:49 AM.

  • 0

promo_briquidmini_500x150.png


#20 jsorgeagames

jsorgeagames

    GMC Member

  • GMC Member
  • 710 posts
  • Version:GM:Studio

Posted 29 August 2013 - 03:08 AM

Whenever a shader uses a texture, but one is not provided, it will return black for the texture call instead of white. Not really sure if this is a bug or intended behavior.


  • 0

#21 Gamer3D

Gamer3D

    Human* me = this;

  • GMC Member
  • 1819 posts
  • Version:GM:Studio

Posted 29 August 2013 - 03:25 AM

Whenever a shader uses a texture, but one is not provided, it will return black for the texture call instead of white. Not really sure if this is a bug or intended behavior.


Undefined behavior is more likely.


  • 1
Fast Priority Queues - Game Maker's priority queues are O(n). Mine do everything that Game Maker's do, but in O(log n) time.
Dual-Quaternion Skinning - Modifying vertexes in GM is slow. This simple vertex shader does the job both quickly and well.

#22 Alvare

Alvare

    Not an administrator

  • GMC Member
  • 1812 posts
  • Version:None

Posted 19 September 2013 - 04:43 PM

Bump!

 

Does anyone know how forward rendering can use multiple shaders on drawings?

Please, could someone post a example?

 

Also fog doesn't seem to work anymore.


Edited by THE_GAME_EDITOR, 19 September 2013 - 07:52 PM.

  • 0

#23 N3QN

N3QN

    :3

  • GMC Member
  • 65 posts
  • Version:GM:Studio

Posted 19 September 2013 - 07:59 PM

Bump!

 

Does anyone know how forward rendering can use multiple shaders on drawings?

Please, could someone post a example?

 

Well, you can set forward rendering as a series of functions, or as one function all together, and then apply any changes you intend to do to it.

 

Say you wanted to apply a brightness contrast effect after applying forward lighting in order to make a dark room look more burned in, here's what you could do.

 

Spoiler

 

Also, wanted to say, the Defered rendering example doesn't work on Android, presumably for the same reason most view surface based shaders don't work on android, the UVs on mobile devices are slightly different. I'm also noticing that Foward lighting tends to be significantly faster both on PC and Android.

Here's a screenshot of Foward Rendering working on a Nexus 4. It's extremely fast, 300-500 fps, which is basically the max this phone can do. :D

vq87.png


 


  • 0

layout_shadowl_button.pnglayout_da_button.pnglayout_yt_button.pnglayout_shadowr_button.png


#24 Alvare

Alvare

    Not an administrator

  • GMC Member
  • 1812 posts
  • Version:None

Posted 20 September 2013 - 02:01 PM

Hmm.. forward shading is nicer than deferred...

But deferred is faster. =/


Edited by THE_GAME_EDITOR, 21 September 2013 - 08:21 PM.

  • 0

#25 Alvare

Alvare

    Not an administrator

  • GMC Member
  • 1812 posts
  • Version:None

Posted 25 September 2013 - 12:17 PM

Just realized; "Also keep in mind the attenuation in the forward shader is infinite"

This is what makes it realistic. Because light isn't just a gradient circle like the deferred, but it bouces of the geometry.

 

Also.. if we would wan't to use shadows in the future, would it be possible to subtract them from the lighted surface?


  • 0

#26 jsorgeagames

jsorgeagames

    GMC Member

  • GMC Member
  • 710 posts
  • Version:GM:Studio

Posted 26 September 2013 - 01:07 AM

Just realized; "Also keep in mind the attenuation in the forward shader is infinite"

This is what makes it realistic. Because light isn't just a gradient circle like the deferred, but it bouces of the geometry.

You can definitely do this with deferred rendering, it's just not practical at all because the drawn light radius has to be extended to 8 times the actual light radius.

Also.. if we would wan't to use shadows in the future, would it be possible to subtract them from the lighted surface?

Basically you'd need to do shadows on a per light basis, because shadows are the absence of light. If you had a lot of lights this would be horribly slow, because you'd need to render the scene from each light 6 times. If you only did it for a few lights though, you could feasibly add it into the shader.


  • 1

#27 Alvare

Alvare

    Not an administrator

  • GMC Member
  • 1812 posts
  • Version:None

Posted 26 September 2013 - 09:22 PM

You can definitely do this with deferred rendering, it's just not practical at all because the drawn light radius has to be extended to 8 times the actual light radius.

I already tried this. It's still a very hard looking circle gradient lighting. Also the blending doesnt look right. In the middle, it's colored white when it's intense.

While in forward it looks eye-candy.

 

Basically you'd need to do shadows on a per light basis, because shadows are the absence of light. If you had a lot of lights this would be horribly slow, because you'd need to render the scene from each light 6 times. If you only did it for a few lights though, you could feasibly add it into the shader.

Hm.. that does sound like a pain in the neck to me! :P

I'm wondering now, you might know, is this gamemake shader, still not developed enough to match the quality standard of modern games?

Or are those shaders all about good programming and will gamemaker be able to reach a normal 3d lighting system in the future?


Edited by THE_GAME_EDITOR, 26 September 2013 - 09:23 PM.

  • 0

#28 jsorgeagames

jsorgeagames

    GMC Member

  • GMC Member
  • 710 posts
  • Version:GM:Studio

Posted 28 September 2013 - 02:55 AM

I already tried this. It's still a very hard looking circle gradient lighting. Also the blending doesnt look right. In the middle, it's colored white when it's intense.

While in forward it looks eye-candy.

You need to change the attenuation equation to match the one used in the forward rendering shader.
 

I'm wondering now, you might know, is this gamemake shader, still not developed enough to match the quality standard of modern games?

Or are those shaders all about good programming and will gamemaker be able to reach a normal 3d lighting system in the future?

These shaders do match the quality of modern games, though they are probably a bit slower because of certain workarounds I used and because they're not natively written in HLSL or GLSL. It all depends on the way they're used in the game.


  • 0

#29 Alvare

Alvare

    Not an administrator

  • GMC Member
  • 1812 posts
  • Version:None

Posted 28 September 2013 - 08:48 AM

You need to change the attenuation equation to match the one used in the forward rendering shader.

Cool, i'll give that a try right away! =D

These shaders do match the quality of modern games, though they are probably a bit slower because of certain workarounds I used and because they're not natively written in HLSL or GLSL. It all depends on the way they're used in the game.

I see, I'm not really familier with them (HLSL and GLSL) but I'll try to do some research.


  • 0

#30 Alvare

Alvare

    Not an administrator

  • GMC Member
  • 1812 posts
  • Version:None

Posted 28 September 2013 - 11:23 PM

 

 

You need to change the attenuation equation to match the one used in the forward rendering shader.

 

Wait a min.. =s You're right. So why even bother about the forward one, As deferred is a better version?

Or am I missing a more important difference between the two?


Edited by THE_GAME_EDITOR, 28 September 2013 - 11:24 PM.

  • 0

#31 Gizmo199

Gizmo199

    Dapper Dan Man Band

  • GMC Member
  • 369 posts
  • Version:GM:Studio

Posted 29 September 2013 - 06:22 PM

I got an error, and I am really confused by it. 

in object scene, event create, action 1 at line 2: unknown function or script: d3d_model_load

Not really sure, it is definately a function built in, it will even pop up when typing it in, but for some reason won't register?


  • 0

Games: Shadow of the sea | Druknsmas Eve | LOST (alpha) | The Machine

Need epic game music? check out my soundcloud series EPIC GAME MUSIC

and give me some feed back :D


#32 Noel_Abercrombie

Noel_Abercrombie

    Hexagon of Justice

  • GMC Member
  • 327 posts
  • Version:GM5

Posted 30 September 2013 - 12:31 PM

I got an error, and I am really confused by it. 

in object scene, event create, action 1 at line 2: unknown function or script: d3d_model_load

Not really sure, it is definately a function built in, it will even pop up when typing it in, but for some reason won't register?

What context is this in? Can you post the surrounding code?


  • 0

#33 jsorgeagames

jsorgeagames

    GMC Member

  • GMC Member
  • 710 posts
  • Version:GM:Studio

Posted 01 October 2013 - 01:28 AM

Wait a min.. =s You're right. So why even bother about the forward one, As deferred is a better version?

Or am I missing a more important difference between the two?

At some point deferred rendering becomes faster than forward rendering. If you're only using like 4 lights deferred is much slower and more inefficient. Plus it has its own cons; you can't use anti-aliasing, you can't draw transparent objects, and large lights can be very slow. But if you're drawing a ton of small lights, deferred rendering is the way to go.


  • 1

#34 Alvare

Alvare

    Not an administrator

  • GMC Member
  • 1812 posts
  • Version:None

Posted 01 October 2013 - 04:57 PM

At some point deferred rendering becomes faster than forward rendering. If you're only using like 4 lights deferred is much slower and more inefficient. Plus it has its own cons; you can't use anti-aliasing, you can't draw transparent objects, and large lights can be very slow. But if you're drawing a ton of small lights, deferred rendering is the way to go.

Okay, I understand. Thanks for the information. :thumbsup:


  • 0

#35 Gizmo199

Gizmo199

    Dapper Dan Man Band

  • GMC Member
  • 369 posts
  • Version:GM:Studio

Posted 02 October 2013 - 08:41 PM

 

I got an error, and I am really confused by it. 

in object scene, event create, action 1 at line 2: unknown function or script: d3d_model_load

Not really sure, it is definately a function built in, it will even pop up when typing it in, but for some reason won't register?

What context is this in? Can you post the surrounding code?

 

 

That is just the error message, the code is just the codes in the example. Unedited or anything. I just opened it to see how it looked, and got an immediate error. GM bug?


  • 0

Games: Shadow of the sea | Druknsmas Eve | LOST (alpha) | The Machine

Need epic game music? check out my soundcloud series EPIC GAME MUSIC

and give me some feed back :D


#36 UKDutyPaid

UKDutyPaid

    GMC Member

  • GMC Member
  • 254 posts
  • Version:GM:Studio

Posted 06 October 2013 - 08:18 PM

Big thanks for this, it's great to escape the 8 hardware light limit... finally I can really try to create some atmosphere in my 3d game...

 

Anyway, I'm an utter noob when it comes to shaders.  I wondered if anyone could help me with adding texture support to the Forward shader?

 

Many thanks.


  • 0

#37 Alvare

Alvare

    Not an administrator

  • GMC Member
  • 1812 posts
  • Version:None

Posted 06 October 2013 - 09:39 PM

Big thanks for this, it's great to escape the 8 hardware light limit... finally I can really try to create some atmosphere in my 3d game...

 

Anyway, I'm an utter noob when it comes to shaders.  I wondered if anyone could help me with adding texture support to the Forward shader?

 

Many thanks.

I'm a noob too. Try to create an empty shader and look at how the texture is applied. You'll see the *blahblahblah after frag_color. That's the one.


Edited by THE_GAME_EDITOR, 06 October 2013 - 09:40 PM.

  • 1

#38 UKDutyPaid

UKDutyPaid

    GMC Member

  • GMC Member
  • 254 posts
  • Version:GM:Studio

Posted 07 October 2013 - 06:47 PM

 

Big thanks for this, it's great to escape the 8 hardware light limit... finally I can really try to create some atmosphere in my 3d game...

 

Anyway, I'm an utter noob when it comes to shaders.  I wondered if anyone could help me with adding texture support to the Forward shader?

 

Many thanks.

I'm a noob too. Try to create an empty shader and look at how the texture is applied. You'll see the *blahblahblah after frag_color. That's the one.

 

Thanks for that, much obliged.  I've been playing with other shaders to try and work it out, but this helps me focus what I'm looking for at least!


  • 1

#39 japjap

japjap

    GM-LINUX GM-PS4 user

  • GMC Member
  • 166 posts
  • Version:GM8

Posted 30 October 2013 - 04:06 PM

Good idea. Very nice lighting samples
  • 0

#40 fel666

fel666

    GMC Member

  • GMC Member
  • 1883 posts
  • Version:GM:Studio

Posted 26 November 2013 - 09:22 AM

Could someone make an example of how to use the differed rendering with the bump maps, specular and all the other shaders available plz? For some reason, I can't get them to work.

[edit] bumpmap, not bomb XD [edit]


Edited by fel666, 03 December 2013 - 04:34 PM.

  • 0

This forum is old and archived, Whatever it is i said up above may no longer reflect my opinion.

GMWolf
GMIterator
RefactorTool
OptimizedDecals

#41 qorwhddlr

qorwhddlr

    GMC Member

  • GMC Member
  • 21 posts
  • Version:GM:Studio

Posted 01 December 2013 - 02:27 PM

I also want the texture.
However d3d_model_draw (wall, x, y, z, tex); this does
The texture is doeneungunyo black.
How to apply a texture to it?


  • 0

dc5w92.png


#42 Alvare

Alvare

    Not an administrator

  • GMC Member
  • 1812 posts
  • Version:None

Posted 13 December 2013 - 05:26 PM

~Nope, solved it.~


Edited by Alvare, 14 December 2013 - 08:06 PM.

  • 0

#43 Phantom107

Phantom107

    Graphics Enthusiast

  • GMC Member
  • 2774 posts
  • Version:GM:Studio

Posted 23 March 2014 - 12:53 PM

Excellent work jsorgeagames!
 
I get 136 fps in the deferred rendering example. I can use your screen space normals for the SSAO shader I'm working on. I ran into a bunch of problems. Totally awesome.


  • 0

GMCSignature.png

 

The most advanced GM game yet. Check out the Titan Rush GMC topic here! Developed by Phantom Technology

Talented spriting artist, looking for work? PM me. I'm working on a small project and need assistance. :)


#44 Sezze 99

Sezze 99

    GMC Member

  • GMC Member
  • 72 posts
  • Version:GM:Studio

Posted 13 August 2014 - 02:49 PM

Could a directional light be possible? It would be really necessary, for me, and probably most other projects.

If it's already possible, how do I do it?

Edit: On deferred rendering


Edited by Sezze 99, 13 August 2014 - 02:50 PM.

  • 0

lwr2k6Q.png


#45 fel666

fel666

    GMC Member

  • GMC Member
  • 1883 posts
  • Version:GM:Studio

Posted 14 August 2014 - 01:42 AM

For directional light, i think you would have to add a new vec 4 uniform for the direction and intencity.
Then in the lighting shader, just do a dot product of the light direction and normal map to find how lit it is, and times it by the intencity.
  • 0

This forum is old and archived, Whatever it is i said up above may no longer reflect my opinion.

GMWolf
GMIterator
RefactorTool
OptimizedDecals

#46 raisins

raisins

    GMC Member

  • GMC Member
  • 349 posts
  • Version:GM:Studio

Posted 08 January 2015 - 01:45 PM

I'm sorry but how do you apply textures on the teapot? I'm new to shaders and I don't know how to pass textures to the script.

 

I'm using Forward Deffering shaders by the way.


Edited by raisins, 08 January 2015 - 02:36 PM.

  • 0

fxYmZ6o.png

 

Visit my blog for GM tutorials and more! Ask.fm me a question! :D

 

kWb6ZYf.png  Vd9fN4l.png


#47 Noel_Abercrombie

Noel_Abercrombie

    Hexagon of Justice

  • GMC Member
  • 327 posts
  • Version:GM5

Posted 11 January 2015 - 06:48 PM

I'm sorry but how do you apply textures on the teapot? I'm new to shaders and I don't know how to pass textures to the script.

 

I'm using Forward Deffering shaders by the way.

 

Add all the texture bits from the default shader,

 

Vertex :
attribute vec2 in_TextureCoord;      
varying vec2 v_vTexcoord;

~
v_vTexcoord = in_TextureCoord;

 

Fragment :

varying vec2 v_vTexcoord;

 

And modify the last line of fragment to read
    gl_FragColor = texture2D( gm_BaseTexture, v_vTexcoord )*vec4((materialAmbient.rgb + diffuse.rgb) * vertexColor.rgb + specular.rgb * materialSpecular.rgb,vertexColor.a);

 

Testing it, I think everything needs a texture for this to work, however.

 

tumblr_ni0ztnBip41u4ktqbo1_1280.png


  • 1

#48 raisins

raisins

    GMC Member

  • GMC Member
  • 349 posts
  • Version:GM:Studio

Posted 11 January 2015 - 07:01 PM

Nice! Thanks dude. :D


  • 0

fxYmZ6o.png

 

Visit my blog for GM tutorials and more! Ask.fm me a question! :D

 

kWb6ZYf.png  Vd9fN4l.png


#49 GS-games

GS-games

    Creative

  • GMC Member
  • 362 posts
  • Version:GM:Studio

Posted 28 December 2015 - 09:58 PM

 

Deferred Rendering.

How do I use a normal and specular map?

 

After reading the manual and checked the code for a long time I

thought this seemed logical, but I do not know, I might be completely wrong

because it does not work. I am fairly new to Shaders.

I am grateful for all the help I can get.

 

 

Draw Event in Object Scene - Trying to draw the teapot with the "texRandom" normal map included.

 d3d_transform_set_scaling(0.2,0.2,0.2);
d3d_transform_add_translation(0,0,6.4);
shader_set(global.renderShader);
if (global.renderShader == shaderAmbient) {shader_set_uniform_f(global.uAmbient,0.05,0.05,0.05)};
if (global.renderShader == shaderDeferred) {texture_set_stage(global.uTexNormal, tex_random);}; // <-? My code/attempt. No apparent effect.
d3d_model_draw(global.modelTeapot,0,0,0,back_floor);
shader_reset();
d3d_transform_set_identity();

 

 


Edited by GS-games, 28 December 2015 - 10:37 PM.

  • 0

Hi there!

Twitter: https://twitter.com/GabrielSandsted

Website (under development) gsgames.net: http://gsgames.net/ 

Facebook page: https://www.facebook.com/gsgames.net 

tx5PmL9.png


#50 GS-games

GS-games

    Creative

  • GMC Member
  • 362 posts
  • Version:GM:Studio

Posted 16 January 2016 - 07:17 PM

Bump


  • 0

Hi there!

Twitter: https://twitter.com/GabrielSandsted

Website (under development) gsgames.net: http://gsgames.net/ 

Facebook page: https://www.facebook.com/gsgames.net 

tx5PmL9.png