a.koryakin Posted December 3, 2014 Posted December 3, 2014 Hi. I'm writing GLSL shader and I want to make material with it.here is the code of shader:file fragment shader: glow_frag.shader uniform sampler2D Texture0; void main() { vec4 color = texture2D(Texture0,gl_TexCoord[0].st); gl_FragColor = color; } file vertex shader: glow_vert.shader void main() { gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0; gl_Position = ftransform(); } material library <?xml version="1.0" encoding="utf-8"?> <materials version="1.11"> <material name="glow"> <blend src="src_alpha" dest="one_minus_src_alpha"/> <shader pass="ambient" object="dynamic" vertex="data/Empty/glow_vert.shader" fragment="data/Empty/glow_frag.shader"/> <texture name="Texture0" filter="bilinear" anisotropy="1">../../../../../Desktop/Materials.png</texture> </material> </materials> But when i apply this material to geometry nothing is happening. what am i doing wrong?in Render Monkey this shader works fine.Empty.rar 1
helmut.bressler Posted December 5, 2014 Posted December 5, 2014 Hello Koryakin, I have only experience with the direct3d 11 renderer of unigine but since both hlsl and glsl shader source code are in the same files I have observed a few things which might be helpful for you: - Unigine is not using gl_TexCoord[0], gl_Normal, gl_Vertex and so on. Instead vertex shaders are using custom vertex attributes: in float4 s_attribute_0; in float4 s_attribute_1; in float4 s_attribute_2; in float4 s_attribute_3; for static meshes the following is expected: s_attribute_0.xyz is the position s_attribute_1.xy is the 1st texcoord set s_attribute_1.zw is the 2nd texcoord set for unigine >= 2.0 s_attribute_2 is the tangent space basis (a quaternion). The .w component encodes some sort of mirroring of the tangent space basis as far as I have understood. s_attribute_3 i don't know, probably the vertex color? for unigine < 2.0 s_attribute_2 is the normal vector s_attribute_3 the tangent. Since you are using a ObjectDynamic it is your choice what you are passing to the vertex shader, however if you want to use the vertex shader provided by Unigine you have to stick to the vertex layout mentioned above. It is also very likely that ftransform() does not work. Instead the modelview and the projection matrix are fed into the vertex shader via uniforms. They are defined in the file: \data\core\shaders\default\common\common_base.h The s_transform[3] array contains the modelview matrix in case hardware instancing is off and s_instances[] contains the modelview matrices in case instancing is on. The s_projection uniform is the projection matrix. As starting point I recommend to look at the static mesh general vertex shader: data\core\shaders\default\mesh\vertex_base.shader I'm also not sure about the material file, as far as I can remember there was a problem with object="dynamic". Instead you should say object="mesh_static" and you should derive a material which binds dynamic meshs to static meshs: <material name="glow_dynamic" parent="glow"> <bind object="dynamic" to="mesh_static"/> </material> But I'm not totally sure about whether this is really necessary, however it shouldn't cause any troubles. Good luck with shader hacking! cheers Helmut 2
a.koryakin Posted December 10, 2014 Author Posted December 10, 2014 Thank you Helmut. Your post was very helpful. I rewrite my shader accordingly to Unigine wrap , vertex_base.h and fragment_base.h.its working now.And I found shader I needed in shader examples.
helmut.bressler Posted December 15, 2014 Posted December 15, 2014 Thank you good to know that my assumptions are correct B) 1
Recommended Posts