Jump to content

Shader programming: where to start?


Recommended Posts

If you are using OpenGL :

OpenGL Shading Language "the orange book".

It seems you can download for free the second edition, if your not to far of an university you can look at their math/computer library, mine have the book...

nvidia GPU gems are often cited to have some good examples. Also you canf ound some publications about some shaders... I am myself learning and writing an opengl application using shaders, so if you have some good resources plz share it :D

Link to comment
Share on other sites

A few 0 A.D.-specific resources to get you started:

0 A.D. Modding Guide - explains about modding the game and mentions some popular tools

Material system - technical details about the game's shader and material system, including what versions we use. No doubt it won't answer every question, then you'll have to delve into the engine source code or ask someone (y)

Personally, I'm on Windows most of the time, and I just use Notepad++ to modify the shaders. A tool that can be priceless in debugging your work is gDEBugger.

Link to comment
Share on other sites

there is some software for shaders dev. Saddly (for me) most of them are written for windows... I read some time that RenderMonkey (ATI) is a very good software. I never used RenderMonkey, I don't know if it's still up to date or not, if it's good for opengl and/or directx... When I tried for myself to found a software, I found some other (on sourceforge iirc) who looked interesting but all for windows... So I'm writing my own application, it will never as good as RenderMonkey or such (so far).... but it will enough for my needs.

  • Like 1
Link to comment
Share on other sites

I'm using openscenegraph too. Saddly most of the documentation on the web are outdated, there is two books I have them at university. You have to use the mailling list to get some help. OSG is a 3D engine, so you can use shaders and write a program, but there is no tools for shaders dev (for what I know). OSG is used for virtual environment, not for games. The reason of why is not use in games isn't really clear for me, some peoples say scene graph is not good for games, but I read one time that was true ~20 years ago but not anymore today. If you are looking for a 3D engine which use a lot shaders (with opengl) peek a look at Horde3D.

(hope my english isn't too crappy because I'm tired)

edit :: when I send to the OSG mailling list a mail about the lack of documentation, they told me to study the examples who come with OSG.

Edited by ProvencalLeGaullois
Link to comment
Share on other sites

  On 27/12/2013 at 7:41 PM, niektb said:

Any tools to display the result quickly? I used Shader Designer, but it seems to me that these shaders won't work in the game.

Actually you shouldn't need to use a specific tool just to display it, Pyrogenesis should automatically detect that a file has been changed and update the display. Just open up Atlas and add an object using the shader you're working on and save the file when you want to see the result.

Link to comment
Share on other sites

  On 29/12/2013 at 7:44 PM, niektb said:

I tried to implement a simple post-proc shader but nothing happened at all in the Atlas! Even the other shaders didn't change anything. (I'm sorry. I'm unable to upload my shader due to permission restrictions.)

We could enable more file formats, but I'm generally against it - it's better if people put their files in ZIPs/7zips/GZs/some compressed format as that takes up less space on the servers/is quicker for people to download :)

Link to comment
Share on other sites

  • 5 weeks later...

It took a while before I started again on programming shaders.

This time I tried creating a FXAA-shader. No luck however:

post-15513-0-42911100-1391003102_thumb.p

Does anybody has some thoughts on this?

I tried modifying the following shader:

https://code.google.com/p/processing/source/browse/trunk/processing/java/libraries/opengl/examples/Shaders/FXAA/data/fxaa.glsl?r=9668

Some background information on FXAA:

http://developer.download.nvidia.com/assets/gamedev/files/sdk/11/FXAA_WhitePaper.pdf

The code:

fxaa.xml

<?xml version="1.0" encoding="utf-8"?><program type="glsl">    <vertex file="glsl/hdr.vs">        <stream name="pos"/>        <stream name="uv0"/>        <attrib name="a_vertex" semantics="gl_Vertex"/>        <attrib name="a_uv0" semantics="gl_MultiTexCoord0"/>    </vertex>    <fragment file="glsl/fxaa.fs"/></program>

fxaa.fs

#version 120uniform sampler2D renderedTex;varying vec2 v_tex;void main() {  // The parameters are hardcoded for now, but could be  // made into uniforms to control fromt he program.  float FXAA_SPAN_MAX = 8.0;  float FXAA_REDUCE_MUL = 1.0/8.0;  float FXAA_REDUCE_MIN = (1.0/128.0);  vec3 rgbNW = texture2D(renderedTex, v_tex + (vec2(-1.0, -1.0) )).rgb;  vec3 rgbNE = texture2D(renderedTex, v_tex + (vec2(+1.0, -1.0))).rgb;  vec3 rgbSW = texture2D(renderedTex, v_tex + (vec2(-1.0, +1.0))).rgb;  vec3 rgbSE = texture2D(renderedTex, v_tex + (vec2(+1.0, +1.0))).rgb;  vec3 rgbM  = texture2D(renderedTex, v_tex).rgb;	  vec3 luma = vec3(0.299, 0.587, 0.114);  float lumaNW = dot(rgbNW, luma);  float lumaNE = dot(rgbNE, luma);  float lumaSW = dot(rgbSW, luma);  float lumaSE = dot(rgbSE, luma);  float lumaM  = dot( rgbM, luma);	  float lumaMin = min(lumaM, min(min(lumaNW, lumaNE), min(lumaSW, lumaSE)));  float lumaMax = max(lumaM, max(max(lumaNW, lumaNE), max(lumaSW, lumaSE)));	  vec2 dir;  dir.x = -((lumaNW + lumaNE) - (lumaSW + lumaSE));  dir.y =  ((lumaNW + lumaSW) - (lumaNE + lumaSE));	  float dirReduce = max((lumaNW + lumaNE + lumaSW + lumaSE) * (0.25 * FXAA_REDUCE_MUL), FXAA_REDUCE_MIN);	    float rcpDirMin = 1.0/(min(abs(dir.x), abs(dir.y)) + dirReduce);	  dir = min(vec2(FXAA_SPAN_MAX,  FXAA_SPAN_MAX),         max(vec2(-FXAA_SPAN_MAX, -FXAA_SPAN_MAX), dir * rcpDirMin));		  vec3 rgbA = (1.0/2.0) * (              texture2D(renderedTex, v_tex + dir * (1.0/3.0 - 0.5)).rgb +              texture2D(renderedTex, v_tex + dir * (2.0/3.0 - 0.5)).rgb);  vec3 rgbB = rgbA * (1.0/2.0) + (1.0/4.0) * (              texture2D(renderedTex, v_tex + dir * (0.0/3.0 - 0.5)).rgb +              texture2D(renderedTex, v_tex + dir * (3.0/3.0 - 0.5)).rgb);  float lumaB = dot(rgbB, luma);  if((lumaB < lumaMin) || (lumaB > lumaMax)){    gl_FragColor.rgb=rgbA;  } else {    gl_FragColor.rgb=rgbB;  }  gl_FragColor.a = 1.0;}

post-15513-0-32400400-1391002863_thumb.p

fxaa.zip

fxaa.zip

Edited by niektb
Link to comment
Share on other sites

  • 1 month later...
  On 13/03/2014 at 5:09 PM, stanislas69 said:

Did you make any improvement on your shader ?

No, my latest result was the first image you encounter when you scroll to the top. It discouraged me to go any further. The problem is that I have no idea what input I get from the engine and what I should send back.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

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.

 Share

×
×
  • Create New...