@tytadas no specific tips, it's a tilemap and I am not sure I did it in the best possible way. I have 2 tilesets, 1 with "classic" textures and the other with normalmap textures. Inside Tiled I use 2 layers to hand-draw normalmaps upon my "classic map" (2 layers because I may have a bridge or coast overlapping water - or other map elements overlapping a generic "ground").
The "hard part" (where I suppose I waste a lot of resources) is rendering classic map and normal map aside in a big texture (power of 2 using hgy29 snippet http://giderosmobile.com/forum/discussion/comment/47547#Comment_47547, which then I send to the shader for the light effect). Since objects(buildings) in my game have a different size from the ground grid (and Tiled is not able to handle together grids with different sizes) I place them later (along with their normalmap) on an additional Sprite-layer when I render the "big texture".
Normal map textures are drawn with Sprite Illuminator, I choose normals directions based on the isometric tilemap (ie. "ground" normal is at "12 hours").
@keszegh, you need to define color attribute when creating your shader, then reference it in your vertex shader and pass it along down to the fragment shader through a 'varying'.
ookay, i understand this in principle. could you help how to do the varying, at least? with cpp i have almost no experience. (if it's easier for you, you can modify our terrain3d example and then i will understand what happens).
don't worry, i'm about to finish my questions. i realized that what i imagined as a polygonal 3d brush in my animation app, at the end it does not look as good as i wanted. still, i've learnt a lot about shaders and 3d in gideros in the last days, for which i'm glad, so thanks.
thanks, perfect. (the spec=0; was added by me and probably could be misleading if others want to use your code as a sample). i'm pretty sure that this lighting class would be necessary to add to the tools and/or examples, it's quite capable as it is now.
Hi @pie, below is how I would have wrote the ps shader (tested on my computer);
uniform lowp sampler2D g_Texture;
uniform lowp vec4 g_Color;#define NUM_LIGHTS 2
uniform mediump vec4 lightPos[NUM_LIGHTS];
varying highp vec2 texCoord;
varying mediump vec2 position;void main(){//Common data//Grab the main pixel color from the classic texture
lowp vec3 color0 = texture2D(g_Texture, texCoord).rgb;//Set the specular (i.e. "shine") color to 30% gray
lowp vec3 color1 = vec3(0.3,0.3,0.3);//Grab the normal vector from the right part of the texture://-Displace by 0.5 to the right in normalized coordinates (1=full texture width)//-Convert RGB (range 0->1) to XYZ (range -1 -> 1)
mediump vec3 normal = texture2D(g_Texture, texCoord + vec2(0.5,0.0)).rgb*2.0-1.0;
lowp vec3 lightContributions=vec3(0,0,0);int index;for(index =0; index <= NUM_LIGHTS; index++)// for all light sources {//Compute light direction, assuming light distance of 150 units
mediump vec3 lightDir = normalize(vec3(lightPos[index].xy,150)- vec3(position.xy,0));//Compute the light direction as if light was two times further (for specular)
mediump vec3 halfdir = normalize(normalize(lightDir)+ vec3(0,0,1));//Compute diffuse factor: normal and lightDir colinear -> 1, perpendicular -> 0
lowp float diff = max(0.0, dot(normal, lightDir));//Compute specular factor the same way, but with exponential scale
mediump float nh = max(0.0, dot(normal, halfdir));
mediump float spec = pow(nh,10.0);
lightContributions=lightContributions+(color0 * diff + color1 * spec);}
gl_FragColor = g_Color * vec4(lightContributions.rgb,1);}
I tried setShaderConstant () and i dont understand how it all works ..
It is used to pass values from LUA to shader. Its absolutly the same as Shader:setConstant(...). The only difference is that setShaderConstant operates on a shader that is assigned to a sprite, and setConstant applyies directly to the shader object.
For example, if you have this In your shader
uniform mediump vec2 fTexelSize;
mediump - accuracy of floating point value vec2 - 2d vector type
Hi @pie, below is how I would have wrote the ps shader (tested on my computer);
uniform lowp sampler2D g_Texture;
uniform lowp vec4 g_Color;#define NUM_LIGHTS 2
uniform mediump vec4 lightPos[NUM_LIGHTS];
varying highp vec2 texCoord;
varying mediump vec2 position;void main(){//Common data//Grab the main pixel color from the classic texture
lowp vec3 color0 = texture2D(g_Texture, texCoord).rgb;//Set the specular (i.e. "shine") color to 30% gray
lowp vec3 color1 = vec3(0.3,0.3,0.3);//Grab the normal vector from the right part of the texture://-Displace by 0.5 to the right in normalized coordinates (1=full texture width)//-Convert RGB (range 0->1) to XYZ (range -1 -> 1)
mediump vec3 normal = texture2D(g_Texture, texCoord + vec2(0.5,0.0)).rgb*2.0-1.0;
lowp vec3 lightContributions=vec3(0,0,0);int index;for(index =0; index <= NUM_LIGHTS; index++)// for all light sources {//Compute light direction, assuming light distance of 150 units
mediump vec3 lightDir = normalize(vec3(lightPos[index].xy,150)- vec3(position.xy,0));//Compute the light direction as if light was two times further (for specular)
mediump vec3 halfdir = normalize(normalize(lightDir)+ vec3(0,0,1));//Compute diffuse factor: normal and lightDir colinear -> 1, perpendicular -> 0
lowp float diff = max(0.0, dot(normal, lightDir));//Compute specular factor the same way, but with exponential scale
mediump float nh = max(0.0, dot(normal, halfdir));
mediump float spec = pow(nh,10.0);
lightContributions=lightContributions+(color0 * diff + color1 * spec);}
gl_FragColor = g_Color * vec4(lightContributions.rgb,1);}
I guess @hgy29 mean that your texture should be POWER OF 2 size. Like 512x512 (2^9) or 2048x2048 (2^11) etc But yours is 710x568
Yes that's what I meant. Actually your texture doesn't need to have the same width and height, it can be 512x256, as long as each dimension is a power of two, all is fine.
Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!). https://deluxepixel.com
Folks use visual shader editors nowadays. I didn't dive into it yet, but if I will, I'd check visual editors.
> Newcomers roadmap: from where to start learning Gideros "What one programmer can do in one month, two programmers can do in two months." - Fred Brooks “The more you do coding stuff, the better you get at it.” - Aristotle (322 BC)
Comments
Inside Tiled I use 2 layers to hand-draw normalmaps upon my "classic map" (2 layers because I may have a bridge or coast overlapping water - or other map elements overlapping a generic "ground").
The "hard part" (where I suppose I waste a lot of resources) is rendering classic map and normal map aside in a big texture (power of 2 using hgy29 snippet http://giderosmobile.com/forum/discussion/comment/47547#Comment_47547, which then I send to the shader for the light effect).
Since objects(buildings) in my game have a different size from the ground grid (and Tiled is not able to handle together grids with different sizes) I place them later (along with their normalmap) on an additional Sprite-layer when I render the "big texture".
Normal map textures are drawn with Sprite Illuminator, I choose normals directions based on the isometric tilemap (ie. "ground" normal is at "12 hours").
Fragmenter - animated loop machine and IKONOMIKON - the memory game
don't worry, i'm about to finish my questions. i realized that what i imagined as a polygonal 3d brush in my animation app, at the end it does not look as good as i wanted. still, i've learnt a lot about shaders and 3d in gideros in the last days, for which i'm glad, so thanks.
Fragmenter - animated loop machine and IKONOMIKON - the memory game
(the spec=0; was added by me and probably could be misleading if others want to use your code as a sample).
i'm pretty sure that this lighting class would be necessary to add to the tools and/or examples, it's quite capable as it is now.
Fragmenter - animated loop machine and IKONOMIKON - the memory game
I have listed only 2 sources:
https://play.google.com/store/apps/developer?id=razorback456
мій блог по гідерос https://simartinfo.blogspot.com
Слава Україні!
Likes: oleg
https://play.google.com/store/apps/developer?id=razorback456
мій блог по гідерос https://simartinfo.blogspot.com
Слава Україні!
I have another problem, I can't create 3 light sources, the program displays only 2
What am i doing wrong?
I figured it out myself
#define NUM_LIGHTS 3
Likes: MoKaLux
https://play.google.com/store/apps/developer?id=razorback456
мій блог по гідерос https://simartinfo.blogspot.com
Слава Україні!
#define NUM_LIGHTS 2
Can lua change the color and size of the light source?
https://play.google.com/store/apps/developer?id=razorback456
мій блог по гідерос https://simartinfo.blogspot.com
Слава Україні!
To change the light color and size (specular ?) you'll need to declare more uniforms and use setShaderConstant() from lua
Likes: oleg
https://play.google.com/store/apps/developer?id=razorback456
мій блог по гідерос https://simartinfo.blogspot.com
Слава Україні!
For example, if you have this In your shader
uniform mediump vec2 fTexelSize;
vec2 - 2d vector type
Then you use
You cant change non uniform values in sahder from LUA.
P.S. As a starting point read The Book of Shaders by Patricio Gonzalez Vivo & Jen Lowe
Likes: oleg, SinisterSoft
https://play.google.com/store/apps/developer?id=razorback456
мій блог по гідерос https://simartinfo.blogspot.com
Слава Україні!
But for some reason the normal.map coordinates are out of place
I have to shift the texture by 0.3467 instead of 0.5
Why is that so?
https://play.google.com/store/apps/developer?id=razorback456
мій блог по гідерос https://simartinfo.blogspot.com
Слава Україні!
Likes: oleg
https://play.google.com/store/apps/developer?id=razorback456
мій блог по гідерос https://simartinfo.blogspot.com
Слава Україні!
ps//Set the tile size 71 * 71
https://play.google.com/store/apps/developer?id=razorback456
мій блог по гідерос https://simartinfo.blogspot.com
Слава Україні!
But yours is 710x568
Likes: oleg, hgy29, MoKaLux
710/2048=0,3466796875 --Now i know the correct value of texture offset
Likes: antix, MoKaLux
https://play.google.com/store/apps/developer?id=razorback456
мій блог по гідерос https://simartinfo.blogspot.com
Слава Україні!
Likes: oleg, SinisterSoft, MoKaLux
Likes: MoKaLux
https://deluxepixel.com
I didn't dive into it yet, but if I will, I'd check visual editors.
"What one programmer can do in one month, two programmers can do in two months." - Fred Brooks
“The more you do coding stuff, the better you get at it.” - Aristotle (322 BC)
an error occurs when the game screen loses focus. On the tablet the same way.
Likes: MoKaLux
https://play.google.com/store/apps/developer?id=razorback456
мій блог по гідерос https://simartinfo.blogspot.com
Слава Україні!