gder

Member
  • Content count

    6
  • Joined

  • Last visited

Community Reputation

122 Neutral

About gder

  • Rank
    Newbie
  1. It seems mixed together in some vertex, see the attachement!   I modifiedsource code from  http://ogldev.atspace.co.uk/www/tutorial38/tutorial38.html Because they use glsl4.1,  can't run my computer!   Thanks!   code snippet in mesh.cpp  Mesh::InitFromScene:         glBindBuffer(GL_ARRAY_BUFFER, m_Buffers[POS_VB]);     glBufferData(GL_ARRAY_BUFFER, sizeof(Positions[0]) * Positions.size(), &Positions[0], GL_STATIC_DRAW); int VSInput_Position = glGetAttribLocationARB (g_shaderProg, "VSInput_Position"); glEnableVertexAttribArray(VSInput_Position);     glVertexAttribPointer(VSInput_Position, 3, GL_FLOAT, GL_FALSE, 0, 0);         glBindBuffer(GL_ARRAY_BUFFER, m_Buffers[TEXCOORD_VB]);     glBufferData(GL_ARRAY_BUFFER, sizeof(TexCoords[0]) * TexCoords.size(), &TexCoords[0], GL_STATIC_DRAW); int VSInput_TexCoord = glGetAttribLocationARB (g_shaderProg, "VSInput_TexCoord");     glEnableVertexAttribArray(VSInput_TexCoord);     glVertexAttribPointer(VSInput_TexCoord, 2, GL_FLOAT, GL_FALSE, 0, 0);        glBindBuffer(GL_ARRAY_BUFFER, m_Buffers[NORMAL_VB]);     glBufferData(GL_ARRAY_BUFFER, sizeof(Normals[0]) * Normals.size(), &Normals[0], GL_STATIC_DRAW); int VSInput_Normal = glGetAttribLocationARB (g_shaderProg, "VSInput_Normal");     glEnableVertexAttribArray(VSInput_Normal);     glVertexAttribPointer(VSInput_Normal, 3, GL_FLOAT, GL_FALSE, 0, 0);        glBindBuffer(GL_ARRAY_BUFFER, m_Buffers[BONE_VB]);     glBufferData(GL_ARRAY_BUFFER, sizeof(Bones[0]) * Bones.size(), &Bones[0], GL_STATIC_DRAW); int VSInput_BoneIDs = glGetAttribLocationARB (g_shaderProg, "VSInput_BoneIDs");     glEnableVertexAttribArray(VSInput_BoneIDs);     glVertexAttribPointer(VSInput_BoneIDs, 4, GL_INT, GL_FALSE,  sizeof(VertexBoneData), (const GLvoid*)0); int VSInput_Weights = glGetAttribLocationARB (g_shaderProg, "VSInput_Weights");     glEnableVertexAttribArray(VSInput_Weights);         glVertexAttribPointer(VSInput_Weights, 4, GL_FLOAT, GL_FALSE, sizeof(VertexBoneData), (const GLvoid*)16);          glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_Buffers[INDEX_BUFFER]);     glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(Indices[0]) * Indices.size(), &Indices[0], GL_STATIC_DRAW);     vertex shader:   #version 110 attribute  vec3  VSInput_Position;                                              attribute  vec2  VSInput_TexCoord;                                              attribute  vec3  VSInput_Normal;     attribute  vec4 VSInput_BoneIDs; attribute  vec4  VSInput_Weights; varying    vec2 VSOutput_TexCoord;      varying    vec3 VSOutput_Normal; varying    vec3 VSOutput_WorldPos;      const int MAX_BONES = 100; uniform mat4 gWVP; uniform mat4 gWorld; uniform mat4 gBones[MAX_BONES]; void main() {            mat4 BoneTransform = gBones[int(floor(VSInput_BoneIDs[0]))] * VSInput_Weights[0];     BoneTransform     += gBones[int(floor(VSInput_BoneIDs[1]))] * VSInput_Weights[1];     BoneTransform     += gBones[int(floor(VSInput_BoneIDs[2]))] * VSInput_Weights[2];     BoneTransform     += gBones[int(floor(VSInput_BoneIDs[3]))] * VSInput_Weights[3];     vec4 PosL      = BoneTransform * vec4(VSInput_Position, 1.0);     gl_Position    = gWVP * PosL;     VSOutput_TexCoord = VSInput_TexCoord;     vec4 NormalL   = BoneTransform * vec4(VSInput_Normal, 0.0);     VSOutput_Normal   = (gWorld * NormalL).xyz;     VSOutput_WorldPos = (gWorld * PosL).xyz;                                 }   fragment shader:   #version 120 struct VSOutput {                                                                                         vec2 TexCoord;                                                                      vec3 Normal;                                                                        vec3 WorldPos;                                                                  }; struct VSOutput1 {                                                                                         vec2 TexCoord;                                                                      vec3 Normal;                                                                        vec3 WorldPos;                                                                  }; const int MAX_POINT_LIGHTS = 2; const int MAX_SPOT_LIGHTS = 2; struct BaseLight {     vec3 Color;     float AmbientIntensity;     float DiffuseIntensity; }; struct DirectionalLight {     BaseLight Base;     vec3 Direction; };                                                                                      struct Attenuation                                                                   {                                                                                        float Constant;                                                                      float Linear;                                                                        float Exp;                                                                       };                                                                                                                                                                        struct PointLight                                                                            {                                                                                                BaseLight Base;                                                                       vec3 Position;                                                                               Attenuation Atten;                                                                       };                                                                                                                                                                                        struct SpotLight                                                                             {                                                                                                PointLight Base;                                                                      vec3 Direction;                                                                              float Cutoff;                                                                            };                                                                                                                                                                                        uniform int gNumPointLights;                                                                 uniform int gNumSpotLights;                                                                  uniform DirectionalLight gDirectionalLight;                                                  uniform PointLight gPointLights[MAX_POINT_LIGHTS];                                           uniform SpotLight gSpotLights[MAX_SPOT_LIGHTS];                                              uniform sampler2D gColorMap;                                                                 uniform vec3 gEyeWorldPos;                                                                   uniform float gMatSpecularIntensity;                                                         uniform float gSpecularPower; vec4 CalcLightInternal(BaseLight Light, vec3 LightDirection, VSOutput1 In)             {                                                                                                vec4 AmbientColor = vec4(Light.Color, 1.0f) * Light.AmbientIntensity;                        float DiffuseFactor = dot(In.Normal, -LightDirection);                                                                                                                                       vec4 DiffuseColor  = vec4(0, 0, 0, 0);                                                       vec4 SpecularColor = vec4(0, 0, 0, 0);                                                                                                                                                    if (DiffuseFactor > 0) {                                                                         DiffuseColor = vec4(Light.Color, 1.0f) * Light.DiffuseIntensity * DiffuseFactor;                                                                                                          vec3 VertexToEye = normalize(gEyeWorldPos - In.WorldPos);                                      vec3 LightReflect = normalize(reflect(LightDirection, In.Normal));                              float SpecularFactor = dot(VertexToEye, LightReflect);                                       SpecularFactor = pow(SpecularFactor, gSpecularPower);                                        if (SpecularFactor > 0) {                                                                        SpecularColor = vec4(Light.Color, 1.0f) *                                                                    gMatSpecularIntensity * SpecularFactor;                                  }                                                                                        }                                                                                                                                                                                         return (AmbientColor + DiffuseColor + SpecularColor);                                    }                                                                                                                                                                                         vec4 CalcDirectionalLight(VSOutput1 In)                                                       {                                                                                                return CalcLightInternal(gDirectionalLight.Base, gDirectionalLight.Direction, In);   }                                                                                                                                                                                         vec4 CalcPointLight(PointLight l, VSOutput1 In)                                        {                                                                                                vec3 LightDirection = In.WorldPos - l.Position;                                                float Distance = length(LightDirection);                                                     LightDirection = normalize(LightDirection);                                                                                                                                               vec4 Color = CalcLightInternal(l.Base, LightDirection, In);                              float Attenuation =  l.Atten.Constant +                                                                           l.Atten.Linear * Distance +                                                                  l.Atten.Exp * Distance * Distance;                                                                                                                                   return Color / Attenuation;                                                              }                                                                                                                                                                                         vec4 CalcSpotLight(SpotLight l, VSOutput1 In)                                          {                                                                                                vec3 LightToPixel = normalize(In.WorldPos - l.Base.Position);                                  float SpotFactor = dot(LightToPixel, l.Direction);                                                                                                                                        if (SpotFactor > l.Cutoff) {                                                                     vec4 Color = CalcPointLight(l.Base, In);                                                 return Color * (1.0 - (1.0 - SpotFactor) * 1.0/(1.0 - l.Cutoff));                        }                                                                                            else {                                                                                           return vec4(0,0,0,0);                                                                    }                                                                                        }                                                                                                                                                                                         void main(in VSOutput FSin, out vec4 FragColor) {                                         VSOutput1 In;     In.TexCoord = FSin.TexCoord;     In.Normal = normalize(FSin.Normal);     In.WorldPos = FSin.WorldPos;                                                                        vec4 TotalLight = CalcDirectionalLight(In);                                                                                                                                           for (int i = 0 ; i < gNumPointLights ; i++) {                                                    TotalLight += CalcPointLight(gPointLights[i], In);                                   }                                                                                                                                                                                         for (int i = 0 ; i < gNumSpotLights ; i++) {                                                     TotalLight += CalcSpotLight(gSpotLights[i], In);                                     }                                                                                                                                                                                         FragColor = texture(gColorMap, In.TexCoord.xy) * TotalLight;      }  
  2. Thank you for your hint, now i use D3DXCreateCubeTextureFromFile,it's OK!
  3. Hi,all I find that texCUBE always return zero using Pix debug tool, the inReflect coodinate isn't zero; Does anyone know the error? Thanks! This is my code: texture EnvironmentMap < string type = "CUBE"; string name = "Snow.dds"; >; samplerCUBE EnvMap = sampler_state { Texture = (EnvironmentMap); MipFilter = LINEAR; MinFilter = LINEAR; MagFilter = LINEAR; AddressU = Wrap; AddressV = Wrap; }; sampler2D Wood; float4 Main(float2 inTxr: TEXCOORD0,float3 inReflect: TEXCOORD1) : COLOR { float4 tmp=texCUBE(EnvMap,inReflect.xyz); return tmp; }
  4. OK, Thank You! I will try it.
  5. ah, I draw a ball, when i move it away from camera center, it is stretched on the side away from camera center. I use directX 9.0 and C++, when i modifed fov to be smaller as panic mentioned, it's ok. but i found that enen at the camera center, the ball is not complete spherical, but use DirectX Viewer tool, it looks complete spherical. // // Set camera. // D3DXVECTOR3 pos(0.0f, 0.0f, -10.0f); D3DXVECTOR3 target(0.0f, 0.0f, 0.0f); D3DXVECTOR3 up(0.0f, 1.0f, 0.0f); D3DXMATRIX V; D3DXMatrixLookAtLH( &V, &pos, &target, &up); Device->SetTransform(D3DTS_VIEW, &V); // // Set projection matrix. // D3DXMATRIX proj; D3DXMatrixPerspectiveFovLH( &proj, D3DX_PI * 0.1f, (float)Width/(float)Height, //Window size ratio 1.0f, 10000.0f); Device->SetTransform(D3DTS_PROJECTION, &proj);
  6. Hi, I move the model away from camera cental in the plane perpendicular to camera direction, it become deformed, anyone can tell me what's wrong? thank you!