Gilmer Posted July 2, 2010 Share Posted July 2, 2010 Hello, I am currently working on a shader, to show reflection by cubemap. I commented some lines, and left only to show the diffuse. But the problem is that, is dont generating shadows, is fullbrigh. And if i put the command: "gl_FragData[0] = diffuse;", the leadwerks crash.. Here is the shader: cube.frag #extension GL_ARB_draw_buffers : enable // Color of the material uniform vec4 matColor = vec4(0.3,0.3,0.32,1.0); // Cube map uniform samplerCube texture6; // Reflection factor uniform float reflectionFactor = 1.0; uniform float apptime; uniform vec2 buffersize; uniform float meshlayerrange; uniform float meshlayerheight; uniform vec3 cameraposition; uniform float camerazoom; uniform float vegetationviewdistance; uniform float vegetationheight; //include "abstract::greyscale.txt" //include "abstract::DepthToZPosition.frag" varying vec3 T,B,N; varying vec2 texcoord0; varying vec2 texcoord1; varying vec3 cubecoord; varying vec3 vertexposition; varying vec4 modelvertex; varying vec4 projectionspace; varying vec4 refractionspace; varying vec4 fragcolor; float fOcclusionShadow = 1.0; //DIFFUSE #define LW_DIFFUSE texture0 #ifdef LW_DIFFUSE uniform sampler2D LW_DIFFUSE; #endif #ifdef LW_DIFFUSE2 uniform sampler2D LW_DIFFUSE2; #endif //////// void main(void) { // -------- DIFFUSE vec4 diffuse = fragcolor; vec3 normal; float shininess = 0.0; vec2 texcoord=texcoord0;// only use this because of parallax mapping float selfillumination = 0.0; #ifdef LW_DIFFUSE2 vec4 diffuse2 = texture2D(LW_DIFFUSE2,texcoord0); diffuse = vec4(1); #endif #ifdef LW_DIFFUSE diffuse *= texture2D(LW_DIFFUSE,texcoord); #endif #ifdef LW_DIFFUSE2 diffuse = fragcolor.r * diffuse + (1.0-fragcolor.r) * diffuse2; #endif gl_FragData[0] = diffuse; // ---------------- // -------- NORMAL normal=normalize(normal); // ---------------- //gl_FragColor = mix(matColor, textureCube(texture6, cubecoord)+diffuse, reflectionFactor); //diffuse = diffuse + (textureCube(texture6, cubecoord)/2); gl_FragColor = diffuse; } cube.vert Include "MeshMatrix.vert" uniform float apptime; uniform vec2 buffersize; uniform float meshlayerrange; uniform float meshlayerheight; uniform vec3 cameraposition; uniform float camerazoom; uniform float vegetationviewdistance; uniform float vegetationheight; varying vec3 T,B,N; varying vec2 texcoord0; varying vec2 texcoord1; varying vec3 cubecoord; varying vec3 vertexposition; varying vec4 modelvertex; varying vec4 projectionspace; varying vec4 refractionspace; varying vec4 fragcolor; void main() { vec4 vertexcameraposition; Include "GetMatrix.vert" fragcolor = gl_Color*color; modelvertex = gl_Vertex; mat3 nmat = mat3(mat[0].xyz,mat[1].xyz,mat[2].xyz); modelvertex = mat * modelvertex; vertexposition = modelvertex.xyz; vertexcameraposition = gl_ModelViewProjectionMatrix * modelvertex; texcoord0=gl_MultiTexCoord0.xy; texcoord1=gl_MultiTexCoord1.xy; cubecoord = modelvertex.xyz - cameraposition; cubecoord = reflect( cubecoord , normalize(nmat * gl_Normal) ); nmat = gl_NormalMatrix * nmat; N = normalize( nmat * gl_Normal ); gl_Position = vertexcameraposition; #ifdef __GLSL_CG_DATA_TYPES gl_ClipVertex = gl_ModelViewMatrix * modelvertex; #endif } Quote Link to comment Share on other sites More sharing options...
Josh Posted July 2, 2010 Share Posted July 2, 2010 Sync your SDK. Cubemap reflections have been added into the official shaders. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Gilmer Posted July 5, 2010 Author Share Posted July 5, 2010 Hello Josh, thanks for feedback. I sync my sdk, and tested the new shader. But have a problem, the shader show the reflect, but does not show the diffuse together, the shader "mesh_diffuse_cubemap" dont show the reflect. So i took the "mesh_cubemap" and im changing to merge the diffuse with reflect. The problem is that the cubemap use the channel "texture0" in the shader, and the diffuse "texture1". If i keep it, i can merge, but dont show shadows in model, but, if i change the cubemap to "texture1" and the diffuse to "texture0", the diffuse show, but dont show the reflect.. What i need change in cubemap, to render using the "texture1"? This is what I changed: .... #ifdef LW_CUBEMAP uniform samplerCube LW_CUBEMAP; varying vec3 cubemapdir; varying vec3 cubemapnormal; vec4 cube; vec4 diftex; #endif ... void main(void) { ... #ifdef LW_CUBEMAP vec3 cubecoord = reflect( normalize( modelvertex.xyz - cameraposition ), normal * gl_NormalMatrix ); cube = vec4( textureCube(LW_CUBEMAP,cubecoord).xyz, diffuse.w); diftex = texture2D(LW_DIFFUSE,texcoord); diffuse = diftex+cube; #endif ... } ... thanks Quote Link to comment Share on other sites More sharing options...
Gilmer Posted July 6, 2010 Author Share Posted July 6, 2010 anyone? I need it very much this. =/ Quote Link to comment Share on other sites More sharing options...
flachdrache Posted July 6, 2010 Share Posted July 6, 2010 From the shader the EMBM should blend with the diffuse.w (alphachannel) but it seams not to do much. just replace the #LW_CUBEMAP in the frag with this #ifdef LW_CUBEMAP vec3 cubecoord = reflect( normalize( modelvertex.xyz - cameraposition ), normal * gl_NormalMatrix ); // diffuse = vec4( textureCube(LW_CUBEMAP,cubecoord).xyz, diffuse.w); float lerpvalue = 0.5; diffuse = mix(vec4( textureCube(LW_CUBEMAP,cubecoord).xyz, diffuse.w), diffuse, lerpvalue); #endif thats a "temp" solution. I do have the same issue with my shaders but only on *_cubemap_skin.vert shaders which seam to be rejected in r5 in a whole (special care with the nmat maybe) ... ill take a look into it. PS: The diffuse texture should be there no matter what - no need to pass it along with a 2nd "vec4 diftex". hth Quote AMD 64 X2 Dual 5k - 4GB - XFX GForce9800GT - nv196.21 - WinXP Sp3 zBrush4R2 - Silo2Pro - Unwrap3DPro - Gile - MaPZone2.5 Xxploration FPS in progress ... Link to comment Share on other sites More sharing options...
Gilmer Posted July 7, 2010 Author Share Posted July 7, 2010 Thanks for answer JTimm... I did what you said, and i used the specular as a "mask" where it will reflect. But even so, i dont like of result, i want make some like this: But the result, is this: I searched some shader to car paint, or some explanation of how it works, but i dont found. And an another issues, how i can get the render of layer from objects around, instead of skybox? If i move the car, between a vegetation, is a little strange reflect only the sky, and not the tree arounds.. Thanks again for help Quote Link to comment Share on other sites More sharing options...
flachdrache Posted July 7, 2010 Share Posted July 7, 2010 He, i know that shader - a pretty expensive car effect paint. A good bunch of layers ... not just diffuse and cubemap. The cheap way is to use a "noise filter" on your specular map or to bake the effect onto the diffuse map (missing realtime specular reflections, though) maybe <<blender>> can do ?! http://matrep.parastudios.de/index.php?action=category&category=9-car-paint For the "realtime" reflections - and iam no glsl expert but that sounds expensive. Try to find the "Half-Life2_Shading.pdf" - there might be some info about this. I would say "fake it" or get an shader expert. Quote AMD 64 X2 Dual 5k - 4GB - XFX GForce9800GT - nv196.21 - WinXP Sp3 zBrush4R2 - Silo2Pro - Unwrap3DPro - Gile - MaPZone2.5 Xxploration FPS in progress ... Link to comment Share on other sites More sharing options...
Gilmer Posted July 8, 2010 Author Share Posted July 8, 2010 Thanks for helping again JTimm So, for now I'll leave it like this shader. What I'm in doubt, is how to render the models around? The shader is passing the images from skybox texture, and not get the main layer, which it objects around, I believe that doing so would give a significant improvement in the result. How could I change to do that? Thanks again Quote Link to comment Share on other sites More sharing options...
Jordan Posted July 8, 2010 Share Posted July 8, 2010 I'm also very interested in a realtime version of the cubemap shader Quote Link to comment Share on other sites More sharing options...
TylerH Posted July 10, 2010 Share Posted July 10, 2010 You need a camera parented to the center of the truck, hide the truck, render the camera in the 6 axial directions, and BindTexture each buffer image to get the realtime cubemap. Quote nVidia 530M Intel Core i7 - 2.3Ghz 8GB DDR3 RAM Windows 7 Ultimate (64x)----- Visual Studio 2010 Ultimate Google Chrome Creative Suite 5 FL Studio 10 Office 15 ----- Expert Professional Expert BMX Programmer ----- Link to comment Share on other sites More sharing options...
flachdrache Posted July 11, 2010 Share Posted July 11, 2010 I tried to look into my old x360 projects but the damn usb-stick keeps crashing. Found another one Here. However, in HL2 they use preRendered cubemaps with "samplepoints" along the track which is way cheaper on the hardware. Quote AMD 64 X2 Dual 5k - 4GB - XFX GForce9800GT - nv196.21 - WinXP Sp3 zBrush4R2 - Silo2Pro - Unwrap3DPro - Gile - MaPZone2.5 Xxploration FPS in progress ... Link to comment Share on other sites More sharing options...
Josh Posted July 11, 2010 Share Posted July 11, 2010 I think you could reasonably render to all six faces in real-time, with shadows disabled and quality settings turned down. I would only expect a top-of-the-line computer to handle this at good speed, though. Maybe only one cubemap face could be updated each frame? Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
TylerH Posted July 11, 2010 Share Posted July 11, 2010 Only the visible cube map faces? Would it be more too to determine which cube faces you can actually see? Quote nVidia 530M Intel Core i7 - 2.3Ghz 8GB DDR3 RAM Windows 7 Ultimate (64x)----- Visual Studio 2010 Ultimate Google Chrome Creative Suite 5 FL Studio 10 Office 15 ----- Expert Professional Expert BMX Programmer ----- Link to comment Share on other sites More sharing options...
Gilmer Posted July 12, 2010 Author Share Posted July 12, 2010 So, we create a script in lua, to render the six faces from cubemap, disabled the shadows, and turned down the quality. But the doubts, is why the shader, render only the skybox layer, if in no time i pass to it? And for sample, if i use this script to pass the images to shader, how i should pass, a image with resolution 1536x256, but that have six images inside, or six images 256x256, one for one? And how i can pass to the shader, the images from script? I Need pass the image to the "texture0" of shader.. Thanks all, for helping.. Quote Link to comment Share on other sites More sharing options...
TylerH Posted July 13, 2010 Share Posted July 13, 2010 You can use BindTexture. I believe it had an optional cubeface parameter, so you would say 1-6 to pass the cube faces. Quote nVidia 530M Intel Core i7 - 2.3Ghz 8GB DDR3 RAM Windows 7 Ultimate (64x)----- Visual Studio 2010 Ultimate Google Chrome Creative Suite 5 FL Studio 10 Office 15 ----- Expert Professional Expert BMX Programmer ----- Link to comment Share on other sites More sharing options...
Gilmer Posted July 13, 2010 Author Share Posted July 13, 2010 Thanks TylerH, but if i understand, the "BindTexture( TTexture texture, int texunit )" dont have parameter, to pass the cube faces. I can use it to pass the texture, but how i say what's the face? I found the SetColorBuffer(), and have a parameter to cubemap. I could use it?? thanks again for help, the leadwerks still some new for we.. Quote Link to comment Share on other sites More sharing options...
TylerH Posted July 18, 2010 Share Posted July 18, 2010 Ah yes, SetColorBuffer is what you would use. EDIT: You would create the texture you intend to use as the cubemap just as you would any other texture. Then for each cube face direction, call SetColorBuffer(texture, cubeface), render that direction. Then pass your texture to the shader. Quote nVidia 530M Intel Core i7 - 2.3Ghz 8GB DDR3 RAM Windows 7 Ultimate (64x)----- Visual Studio 2010 Ultimate Google Chrome Creative Suite 5 FL Studio 10 Office 15 ----- Expert Professional Expert BMX Programmer ----- Link to comment Share on other sites More sharing options...
TylerH Posted July 18, 2010 Share Posted July 18, 2010 I have attempted it in C# and Lua and neither have worked. Lua is the only language other than Blitzmax with CreateCubemap exposed, and I still can't get it to work. Attached is the code for both versions, as well as the cubemap.mat file. Can everyone please take a look at this? We could gain some great features and eye candy if this were to be working properly. cubemap.lua cubemap.mat.txt Program.cs.txt Quote nVidia 530M Intel Core i7 - 2.3Ghz 8GB DDR3 RAM Windows 7 Ultimate (64x)----- Visual Studio 2010 Ultimate Google Chrome Creative Suite 5 FL Studio 10 Office 15 ----- Expert Professional Expert BMX Programmer ----- Link to comment Share on other sites More sharing options...
TylerH Posted July 19, 2010 Share Posted July 19, 2010 After speaking with Josh, though he is busy, I think I am not doing it the proper way (yet it still isn't working) -- Create cubemap camera cubemapcamera = CreateCamera() -- Create cubemap cubemap = CreateCubemap(512,512) -- Create cubemap 'gbuffer' cubemapbuffer = CreateBuffer(512,512,1+2+4+8) -- Create six buffers to render each cube face to cubemapbufferpx = CreateBuffer(512,512,1+2+4+8) cubemapbuffernx = CreateBuffer(512,512,1+2+4+8) cubemapbufferpy = CreateBuffer(512,512,1+2+4+8) cubemapbufferny = CreateBuffer(512,512,1+2+4+8) cubemapbufferpz = CreateBuffer(512,512,1+2+4+8) cubemapbuffernz = CreateBuffer(512,512,1+2+4+8) -- Bind each buffer to a face of the cubemap SetColorBuffer(cubemapbufferpx, cubemap, 0, 0) -- positive x SetColorBuffer(cubemapbuffernx, cubemap, 0, 1) -- negative x SetColorBuffer(cubemapbufferpy, cubemap, 0, 2) -- positive y SetColorBuffer(cubemapbufferny, cubemap, 0, 3) -- negative y SetColorBuffer(cubemapbufferpz, cubemap, 0, 4) -- positive z SetColorBuffer(cubemapbuffernz, cubemap, 0, 5) -- negative z Then during rendering: -- Realtime cubemap CameraProjMode(camera, 0) -- Disable player cam PositionEntity(cubecamera,mesh.position) -- Position cubemap camera at the center of the mesh CameraProjMode(cubecamera, 1) -- Enable cubemap camera --Render Positive X SetBuffer(cubemapbuffer) RotateEntity(cubecamera, Vec3(0, 90, 0)) world:Render() SetBuffer(cubemapbufferpx) world:RenderLights(cubemapbuffer) -- Render Negative X SetBuffer(cubemapbuffer) RotateEntity(cubecamera, Vec3(0, -90, 0)) world:Render() SetBuffer(cubemapbuffernx) world:RenderLights(cubemapbuffer) --Render Positive Y SetBuffer(cubemapbuffer) RotateEntity(cubecamera, Vec3(-90, 0, 0)) world:Render() SetBuffer(cubemapbufferpy) world:RenderLights(cubemapbuffer) -- Render Negative Y SetBuffer(cubemapbuffer) RotateEntity(cubecamera, Vec3(90, 0, 0)) world:Render() SetBuffer(cubemapbufferny) world:RenderLights(cubemapbuffer) --Render Positive Z SetBuffer(cubemapbuffer) RotateEntity(cubecamera, Vec3(0, 0, 0)) world:Render() SetBuffer(cubemapbufferpz) world:RenderLights(cubemapbuffer) --Render Negative Z SetBuffer(cubemapbuffer) RotateEntity(cubecamera, Vec3(0, -180, 0)) world:Render() SetBuffer(cubemapbuffernz) world:RenderLights(cubemapbuffer) CameraProjMode(cubecamera, 0) -- Disable cubemap camera CameraProjMode(camera, 1) -- Enable player camera SetShader(GetMaterialShader(mesh.material)) BindTexture(cubemap,0) -- Bind cubemap to material SetShader(nil) -- render world to GBuffer and draw to BackBuffer as usual. This is the result (all 6 individual buffers are rendered to fine, but the cubemap doesn't seem to be getting rendered to): Full script is attached. cubemap.lua Quote nVidia 530M Intel Core i7 - 2.3Ghz 8GB DDR3 RAM Windows 7 Ultimate (64x)----- Visual Studio 2010 Ultimate Google Chrome Creative Suite 5 FL Studio 10 Office 15 ----- Expert Professional Expert BMX Programmer ----- Link to comment Share on other sites More sharing options...
Gilmer Posted July 20, 2010 Author Share Posted July 20, 2010 Tyler I tested the two examples, generating the black cube, not applying the texture [] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.